fix(apply-diff): report all failed diff blocks and diagnose mistyped start_line markers - #15
Open
simurg79 wants to merge 1 commit into
Open
fix(apply-diff): report all failed diff blocks and diagnose mistyped start_line markers#15simurg79 wants to merge 1 commit into
simurg79 wants to merge 1 commit into
Conversation
…start_line markers Previously only the last failure reached the model, so multi-block apply_diff errors were effectively invisible and the model retried blind. - Report every failed block with '--- Diff block N of M ---' labels and bounded per-block detail instead of surfacing only the final failure. - Emit a 'LIKELY CAUSE' hint when a failed block's first line looks like a mistyped start-line marker. - Partial success now reads 'Applied X of Y diff blocks' and instructs resending only the failed blocks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
apply_diffwas called with multiple diff blocks and more than one block failed to apply, only the last failure was surfaced back to the model. Every earlier failure was silently overwritten. The model therefore received an error message describing a single block, with no indication that other blocks had also failed, and would typically retry blindly — often resending the blocks that had already applied successfully, or "fixing" the one block it could see while the real breakage lay elsewhere.A closely related failure mode made this worse: a common way to break a diff block is to mistype the
:start_line:marker (wrong spelling, missing colons, stray indentation). That produces a generic "search content not found" error that gives the model no signal about the actual cause, so it retries with the same malformed marker.Defects fixed
1. Only the last failure reached the model.
All failed blocks are now reported together. Each is labeled with a
--- Diff block N of M ---header so the model can map a failure back to the specific block it sent, with bounded per-block detail (see caps below).2. Mistyped start-line markers produced an unhelpful generic error.
When a failed block's first line looks like a mistyped start-line marker, the error now includes a
LIKELY CAUSEhint naming that as the probable problem, instead of only reporting that the search content was not found.3. Partial-success messaging was ambiguous.
The partial-success path now reads
Applied X of Y diff blocksand explicitly instructs the model to resend only the failed blocks. Previously the wording invited resending the entire diff, which risked re-applying already-applied blocks.Bounded output
Reporting every failure risks flooding the context window, so the output is capped:
This keeps the worst case bounded regardless of how many blocks were sent or how large each one is.
Validation
src/core/tools/__tests__/applyDiffTool.failureReporting.spec.tssrc/core/diff/strategies/__tests__/multi-search-replace-marker-hint.spec.tscheck-typesclean across all packages.--max-warnings=0).Known limitation
searchBlocksis counted with a regex over occurrences of the literal<<<<<<< SEARCH. If that literal appears inside a block's content (for example, a diff that is itself editing diff-handling code or documentation about the diff format), the count will be too high. This value is advisory only — it is used for theN of Mlabels and theApplied X of Ysummary, and does not drive matching or application logic, so an overcount degrades only the wording of the message and cannot cause an incorrect edit.