Skip to content

Conversation

@lhish
Copy link
Contributor

@lhish lhish commented Jul 4, 2025

Related GitHub Issue

Closes: #5390

Description

This PR addresses an issue where the apply_diff tool (specifically within the multiApplyDiffTool) would intermittently hang when encountering an error during file modification. The root cause was improper error handling; exceptions thrown during XML parsing or diff application were not being caught and propagated correctly. This caused the tool's execution to stall indefinitely without providing any feedback to the user interface, which in turn could confuse the LLM and lead to repetitive, incorrect outputs.

I have changed the original silent error into an explicit editing error that is now displayed in the UI and reported back to the LLM.

Test Procedure

I tested this fix using several real-world cases where I previously encountered this issue, and it resolved the problem successfully in all of them. I attempted to write a new test, but I was unable to determine the specific type of malformed XML that would cause the parser to fail in this exact way, which made it impossible to create a reproducible test case.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

This is a bug fix that improves the stability and error-reporting behavior of an existing tool. It does not change the tool's functionality from a user's perspective, so no documentation updates are needed.


Important

Fixes intermittent hanging in applyDiffTool by improving error handling and feedback in multiApplyDiffTool.ts.

  • Behavior:
    • Fixes intermittent hanging issue in applyDiffTool in multiApplyDiffTool.ts by improving error handling.
    • Converts silent errors during XML parsing and diff application into explicit errors reported to the UI and LLM.
  • Error Handling:
    • In applyDiffTool, catches exceptions during XML parsing and diff application, increments cline.consecutiveMistakeCount, records tool error, and reports detailed error message.
    • Uses cline.say to communicate errors and pushToolResult to log them.
  • Misc:

This description was created by Ellipsis for 55be84c. You can customize this summary. It will automatically update as commits are pushed.

@lhish lhish requested review from cte, jr and mrubens as code owners July 4, 2025 08:53
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Jul 4, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 4, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 4, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 4, 2025
- Keep detailed XML structure instructions only for LLM via pushToolResult
- Show simple error message to user via cline.say
- Aligns with established error handling pattern in codebase
@lhish lhish changed the title fix(tools): 解决 apply_diff 工具间歇性挂起且缺少明确错误反馈的问题 (#5390) fix(tools): Resolve intermittent hangs and lack of clear error feedback in apply_diff tool Jul 4, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @lhish!

I made a small change to properly show the error to the user, but everything looks good!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 4, 2025
- Track XML parsing errors using captureDiffApplicationError
- Include consecutive mistake count for better error analysis
- Helps monitor and debug XML parsing issues in production
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jul 4, 2025
@mrubens mrubens merged commit 8e7d9e0 into RooCodeInc:main Jul 4, 2025
14 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 4, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Bug: apply_diff tool intermittently hangs and lacks clear error feedback

4 participants