fix(apply_diff): detect malformed ------- separator and surface helpful error (#12210)#12213
Open
SAY-5 wants to merge 2 commits intoRooCodeInc:mainfrom
Open
fix(apply_diff): detect malformed ------- separator and surface helpful error (#12210)#12213SAY-5 wants to merge 2 commits intoRooCodeInc:mainfrom
------- separator and surface helpful error (#12210)#12213SAY-5 wants to merge 2 commits intoRooCodeInc:mainfrom
Conversation
…pful error Closes RooCodeInc#12210. When a smaller model emits an apply_diff payload where the `-------` separator is missing the trailing newline, the outer regex's optional separator group quietly absorbs the run-on line into the search content. Match then fails with a confusing "63% similar (needs 100%)" error and the model loops. Add `detectMalformedSeparator` that runs against each replacement's search content right after marker unescaping. It flags first lines that start with seven or more dashes followed by non-dash, non-whitespace content on the same line. Markdown HRs and bare separators are NOT flagged. When detected, return an actionable error naming the exact problem and showing the correct shape so the model can self-correct instead of looping. Three regression tests under `malformed \`-------\` separator detection`: - exact reproduction from the issue → "Malformed separator" error surfaced; "63% similar" message no longer appears - well-formed separator still applies cleanly - search content with a long row of dashes inside the file is NOT misclassified
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.
Closes #12210.
Summary
Smaller models (Qwen 3.6 in the issue) sometimes emit an apply_diff payload where the
-------separator is missing its trailing newline:The outer regex makes the separator group optional, so the run-on line is silently absorbed into the search content. Roo then reports:
which sends the model into a loop, trying the same malformation again. The reporter notes the model can recover if told what's wrong — so a clearer error fixes the cause of the loop.
Change
Add
detectMalformedSeparator(searchContent)that runs against each replacement's search content right after marker unescaping. Flags first lines that start with seven-or-more dashes followed by non-dash, non-whitespace content on the same line. Returns the offending line so the error message can quote it; otherwise returnsnulland the existing flow continues unchanged.When malformed, emit:
False-positive guards: a search line that legitimately contains a long row of dashes inside the file content (markdown HR, comment header like
/* ---------- header ---------- */) is NOT flagged because the helper requires a non-dash, non-whitespace tail.Test plan
Three regression tests under
malformed \-------` separator detection`:-------\nseparator still applies cleanly.Results:
pnpm vitest run core/diff/strategies/__tests__/→ 66 passed; 0 failed (3 new + 63 existing).pnpm run check-types→ all 14 tasks pass.Notes
for (const replacement of replacements)loop), so other replacements in the same diff still apply normally if only one is malformed..changeset/fix-apply-diff-malformed-separator.md(patch).Interactively review PR in Roo Code Cloud