Skip to content

Commit a6c1d8c

Browse files
author
Eric Wheeler
committed
fix: reduce redundant context in apply_diff error messages
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]>
1 parent 2f4d833 commit a6c1d8c

File tree

2 files changed

+2
-29
lines changed

2 files changed

+2
-29
lines changed

src/core/diff/strategies/multi-file-search-replace.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -614,20 +614,6 @@ Each file requires its own path, start_line, and diff elements.
614614
searchLines = aggressiveSearchLines
615615
replaceLines = replaceContent ? replaceContent.split(/\r?\n/) : []
616616
} else {
617-
// No match found with either method
618-
const originalContentSection =
619-
startLine !== undefined && endLine !== undefined
620-
? `\n\nOriginal Content:\n${addLineNumbers(
621-
resultLines
622-
.slice(
623-
Math.max(0, startLine - 1 - this.bufferLines),
624-
Math.min(resultLines.length, endLine + this.bufferLines),
625-
)
626-
.join("\n"),
627-
Math.max(1, startLine - this.bufferLines),
628-
)}`
629-
: `\n\nOriginal Content:\n${addLineNumbers(resultLines.join("\n"))}`
630-
631617
const bestMatchSection = bestMatchContent
632618
? `\n\nBest Match Found:\n${addLineNumbers(bestMatchContent, matchIndex + 1)}`
633619
: `\n\nBest Match Found:\n(no match)`
@@ -644,7 +630,7 @@ Each file requires its own path, start_line, and diff elements.
644630
bestMatchScore * 100,
645631
)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${
646632
startLine ? `starting at line ${startLine}` : "start to end"
647-
}\n- Tried both standard and aggressive line number stripping\n- 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\n\nSearch Content:\n${searchChunk}${bestMatchSection}${originalContentSection}`,
633+
}\n- Tried both standard and aggressive line number stripping\n- 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\n\nSearch Content:\n${bestMatchSection}`,
648634
})
649635
continue
650636
}

src/core/diff/strategies/multi-search-replace.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -521,19 +521,6 @@ Only use a single line of '=======' between search and replacement content, beca
521521
replaceLines = replaceContent ? replaceContent.split(/\r?\n/) : []
522522
} else {
523523
// No match found with either method
524-
const originalContentSection =
525-
startLine !== undefined && endLine !== undefined
526-
? `\n\nOriginal Content:\n${addLineNumbers(
527-
resultLines
528-
.slice(
529-
Math.max(0, startLine - 1 - this.bufferLines),
530-
Math.min(resultLines.length, endLine + this.bufferLines),
531-
)
532-
.join("\n"),
533-
Math.max(1, startLine - this.bufferLines),
534-
)}`
535-
: `\n\nOriginal Content:\n${addLineNumbers(resultLines.join("\n"))}`
536-
537524
const bestMatchSection = bestMatchContent
538525
? `\n\nBest Match Found:\n${addLineNumbers(bestMatchContent, matchIndex + 1)}`
539526
: `\n\nBest Match Found:\n(no match)`
@@ -542,7 +529,7 @@ Only use a single line of '=======' between search and replacement content, beca
542529

543530
diffResults.push({
544531
success: false,
545-
error: `No sufficiently similar match found${lineRange} (${Math.floor(bestMatchScore * 100)}% similar, needs ${Math.floor(this.fuzzyThreshold * 100)}%)\n\nDebug Info:\n- Similarity Score: ${Math.floor(bestMatchScore * 100)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${startLine ? `starting at line ${startLine}` : "start to end"}\n- Tried both standard and aggressive line number stripping\n- 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\n\nSearch Content:\n${searchChunk}${bestMatchSection}${originalContentSection}`,
532+
error: `No sufficiently similar match found${lineRange} (${Math.floor(bestMatchScore * 100)}% similar, needs ${Math.floor(this.fuzzyThreshold * 100)}%)\n\nDebug Info:\n- Similarity Score: ${Math.floor(bestMatchScore * 100)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${startLine ? `starting at line ${startLine}` : "start to end"}\n- Tried both standard and aggressive line number stripping\n- 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\n\nSearch Content:\n${bestMatchSection}`,
546533
})
547534
continue
548535
}

0 commit comments

Comments
 (0)