-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: prevent start_line/end_line in apply_diff REPLACE #4015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: prevent start_line/end_line in apply_diff REPLACE #4015
Conversation
Adds validation to ensure that `:start_line:` and `:end_line:` markers do not appear in the REPLACE section of an apply_diff operation. These markers are only valid within the SEARCH section. This change prevents potential errors and confusion when users might inadvertently include these markers in the replacement content. New tests have been added to verify this validation. Fixes: #4013 Signed-off-by: Eric Wheeler <[email protected]>
|
Hey @KJ7LNW, is there a reason to prevent the tool from executing instead of just removing the incorrect We already handle some errors by the models this way, for example, when the closing tag of a tool call is omitted, does it make sense to do the same here? Maybe in the future we can call a tool but also provide feedback to the model at the same time. |
This pull requests fixes an unlikely event. It happens so rarely that I do not think it justifies intentionally breaking data integrity. This is why: When designing these tools we should always support creation of any arbitrary string: what if it really needs to create |
I agree, this looks good to me then, since I've had this happen a couple of times with Gemini. |
Context
This pull request addresses an issue where
:start_line:and:end_line:markers could be erroneously included in theREPLACEsection of anapply_diffoperation. These markers are intended only for theSEARCHsection to specify the target lines for modification. Including them in theREPLACEsection could lead to unexpected behavior or errors.This change ensures that
apply_diffoperations are more robust by validating the placement of these markers.Fixes: #4013
Implementation
The
MultiSearchReplaceDiffStrategyinsrc/core/diff/strategies/multi-search-replace.tshas been updated to include a validation step within thevalidateMarkerSequencingmethod. This new validation specifically checks if:start_line:or:end_line:markers (when not escaped) are present in the content between=======and>>>>>>> REPLACE.If such markers are found, the diff operation will fail with an informative error message guiding the user on the correct format and the allowed placement of these markers.
Corresponding unit tests have been added to
src/core/diff/strategies/__tests__/multi-search-replace.test.tsto verify this new validation logic, ensuring that invalid placements are rejected and valid placements (including escaped markers in the REPLACE section) are correctly processed.How to Test
The core functionality can be tested by attempting
apply_diffoperations::start_line:or:end_line:incorrectly placed in theREPLACEsection (should fail with an error).SEARCHsection (should succeed).\:start_line:) in theREPLACEsection (should succeed, treating them as literal text).Get in Touch
Discord: KJ7LNW
Important
Adds validation to prevent
:start_line:and:end_line:markers inREPLACEsection ofapply_diff, with tests to verify behavior.:start_line:and:end_line:markers inREPLACEsection ofapply_diff.validateMarkerSequencing()inmulti-search-replace.ts.multi-search-replace.test.tsto verify validation logic.This description was created by
for 3f86541. You can customize this summary. It will automatically update as commits are pushed.