Skip to content

Conversation

@KJ7LNW
Copy link
Contributor

@KJ7LNW KJ7LNW commented Jul 16, 2025

Context

When apply_diff fails to find a match, it previously returned an excessively verbose error message that included redundant information the model already had, wasting valuable context window space.

Implementation

This PR streamlines the error output by:

  • Removing the redundant search content that was just sent by the model
  • Removing the large original file content section that was noisy and context-consuming
  • Keeping only the 'Best Match Found' section, which provides the most actionable information for debugging

The best match section shows exactly what was found in the file that was closest to the search pattern, enabling targeted corrections without re-reading the entire file.

How to Test

  1. Use apply_diff with content that doesn't exactly match the file
  2. Observe that the error message is now more concise but still provides the critical information needed for debugging

Get in Touch

Discord: KJ7LNW

Fixes #5795


Important

Streamlines apply_diff error messages by removing redundant content and updating version to 3.23.12.

  • Behavior:
    • Streamlines error messages in apply_diff by removing redundant search content and large original file content sections in multi-file-search-replace.ts and multi-search-replace.ts.
    • Retains 'Best Match Found' section for actionable debugging information.
  • Versioning:
    • Updates version to 3.23.12 in package.json to reflect changes.
  • Misc:
    • Removes .changeset/v3.23.12.md file as part of cleanup.

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

@KJ7LNW KJ7LNW requested review from cte, jr and mrubens as code owners July 16, 2025 21:31
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jul 16, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 16, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 17, 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 17, 2025
When apply_diff fails to find a match, the error message previously included:
- The search content that was just sent (redundant since model already has it)
- A large snippet of the original file (noisy and context-consuming)

This change streamlines the error output to only show the "Best Match Found"
section, which provides the most actionable information for debugging while
conserving valuable context window space.

The best match section shows exactly what was found in the file that was
closest to the search pattern, enabling targeted corrections without
re-reading the entire file.

Fixes: #5795
Signed-off-by: Eric Wheeler <[email protected]>
@KJ7LNW
Copy link
Contributor Author

KJ7LNW commented Jul 18, 2025

rebased on v3.23.14

@daniel-lxs
Copy link
Member

@roomote-agent Show me a before and after with this change, do not create a new PR or make any changes

@roomote
Copy link
Contributor

roomote bot commented Jul 18, 2025

I'll show you the before and after comparison of the apply_diff error message changes. Let me examine the code changes first.

@roomote
Copy link
Contributor

roomote bot commented Jul 18, 2025

Before and After Comparison: apply_diff Error Messages

This PR significantly reduces the verbosity of apply_diff error messages by removing redundant content while keeping the most actionable debugging information.

BEFORE (Previous Error Message):

When apply_diff failed to find a match, it would return a very verbose error like this:

No sufficiently similar match found (75% similar, needs 80%)

Debug Info:
- Similarity Score: 75%
- Required Threshold: 80%
- Search Range: starting at line 42
- Tried both standard and aggressive line number stripping
- Tip: Use the read_file tool to get the latest content of the file before attempting to use the apply_diff tool again, as the file content may have changed

Search Content:
function calculateTotal(items) {
    let sum = 0;
    for (const item of items) {
        sum += item.price;
    }
    return sum;
}

Best Match Found:
42 | function calculateTotal(items) {
43 |     let total = 0;
44 |     for (const item of items) {
45 |         total += item.price;
46 |     }
47 |     return total;
48 | }

Original Content:
35 | // Helper functions
36 | function validateInput(data) {
37 |     return data && typeof data === 'object';
38 | }
39 | 
40 | // Main calculation function
41 | function calculateTotal(items) {
42 |     let total = 0;
43 |     for (const item of items) {
44 |         total += item.price;
45 |     }
46 |     return total;
47 | }
48 | 
49 | function formatCurrency(amount) {
50 |     return `$${amount.toFixed(2)}`;
51 | }

AFTER (New Streamlined Error Message):

Now the same error is much more concise:

No sufficiently similar match found (75% similar, needs 80%)

Debug Info:
- Similarity Score: 75%
- Required Threshold: 80%
- Search Range: starting at line 42
- Tried both standard and aggressive line number stripping
- Tip: Use the read_file tool to get the latest content of the file before attempting to use the apply_diff tool again, as the file content may have changed

Best Match Found:
42 | function calculateTotal(items) {
43 |     let total = 0;
44 |     for (const item of items) {
45 |         total += item.price;
46 |     }
47 |     return total;
48 | }

Key Changes:

  1. Removed Search Content section - This was redundant since the model just sent this content
  2. Removed Original Content section - This large section was noisy and consumed valuable context window space
  3. Kept Best Match Found section - This is the most actionable information for debugging, showing exactly what was found in the file

Benefits:

  • Reduced context window usage - Saves valuable tokens for more important information
  • Less noise - Focuses on what's actually helpful for debugging
  • Still actionable - The 'Best Match Found' section shows exactly what needs to be corrected
  • Maintains debugging capability - All essential information for fixing the issue is preserved

The error message is now much more focused and efficient while still providing the critical information needed to understand why the match failed and how to fix it.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jul 18, 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.

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 18, 2025
@mrubens
Copy link
Collaborator

mrubens commented Jul 19, 2025

It's not clear to me that the original content isn't valuable here. Is there a way we can demonstrate that it does more harm than good? I don't think that the best match on a failed diff is always the intended match. Until we have a little more evidence that this is positive I'm hesitant to make this change.

@mrubens mrubens added Issue - Needs Info Missing details or unclear. Waiting on author to provide more context. and removed PR - Needs Review lgtm This PR has been approved by a maintainer labels Jul 19, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue - Needs Info Missing details or unclear. Waiting on author to provide more context. labels Jul 19, 2025
@KJ7LNW
Copy link
Contributor Author

KJ7LNW commented Jul 19, 2025

Run an eval?

@daniel-lxs daniel-lxs moved this from PR [Needs Review] to PR [Changes Requested] in Roo Code Roadmap Jul 19, 2025
@KJ7LNW KJ7LNW closed this by deleting the head repository Sep 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 PR - Changes Requested size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: PR [Changes Requested]

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] apply_diff errors: reduce redundant context; keep best-match details only

4 participants