fix: tolerant parsing of :start_line directive in apply_diff#12201
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: tolerant parsing of :start_line directive in apply_diff#12201roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
The apply_diff regex now accepts both `:start_line:` and `:start_line=` formats for the delimiter between the directive name and the line number. This fixes cases where models produce `:start_line=18` instead of `:start_line:18`, which previously caused the directive to leak into the search content, resulting in confusing "insufficient match" errors. Additionally, a fallback detector strips leaked `:start_line=` directives from the search content if they somehow get past the regex, recovering gracefully rather than failing with a misleading similarity score. Closes #12199
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.
Related GitHub Issue
Closes: #12199
Description
This PR attempts to address Issue #12199 where
apply_difffails with a confusing "insufficient match" error when the model produces a slightly malformed:start_linedirective.Root cause: When models write
:start_line=18(using=instead of:as delimiter), the regex fails to parse it, causing the directive text and separator to leak into the search content. The search then fails because the file does not contain:start_line=18.Approach (different from PR #12200): Rather than making
:start_line:strictly mandatory (which would break backward compatibility and require test changes), this PR takes a tolerant parsing approach:Regex update: The main diff-parsing regex now accepts both
:start_line:and:start_line=formats (and same for:end_line:), so[:=]is accepted as the delimiter character.Fallback stripping: A new
stripLeakedStartLineDirective()method detects and strips botched:start_line=directives that somehow leaked into search content, recovering the start line number and cleaning the search content rather than failing with a misleading similarity score.This keeps backward compatibility --
:start_line:remains optional, existing tests pass without changes, and botched directives are handled gracefully.Test Procedure
multi-search-replace.spec.tsandmulti-search-replace-trailing-newline.spec.tspass:start_line=with equals delimiter via regex (single and multiple blocks)Pre-Submission Checklist
Feedback and guidance are welcome.
Interactively review PR in Roo Code Cloud