-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: improve error messages for diff marker escaping in apply_diff tool #7751
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
Conversation
- Enhanced error messages to clearly explain when and how to escape special markers - Differentiated between structural errors and content escaping issues - Added helpful examples showing correct escaping syntax - Added comprehensive tests for marker escaping scenarios - Fixes issue where Grok Coder models get confused by unescaped markers in content Resolves #7750
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like grading my own homework - I already know where I cheated.
expect(escapeResult.success).toBe(false) | ||
expect(escapeResult.error).toContain("appears to be part of the content") | ||
expect(escapeResult.error).toContain("MUST escape it") | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add test coverage for these edge cases?
- Escaped
:start_line:
and:end_line:
markers (the code handles them inunescapeMarkers
but no tests) - Multiple consecutive escaped markers (e.g.,
\=======\=======
) - Mixed escaped and unescaped markers in the same diff
These scenarios might trip up AI models in practice.
|
||
it("should provide helpful error message for unescaped markers", () => { | ||
// This is actually a valid diff structure, not an error case | ||
const diff = "<<<<<<< SEARCH\n" + "code with\n" + "=======\n" + "replacement\n" + ">>>>>>> REPLACE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says "This is actually a valid diff structure, not an error case" but then correctly tests for success. Could we rename this test to something like "should accept valid diff structure without escaped markers" to better reflect what it's validating?
":start_line: (required) The line number of original content where the search block starts.\n" + | ||
"-------\n" + | ||
"[exact content to find including whitespace]\n" + | ||
":start_line:NUMBER (optional but recommended)\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the :start_line:
parameter actually required or optional? The tool description at line 109 says "(required)" but the error message here says "(optional but recommended)". This inconsistency might confuse users (and AI models) about whether they must provide this parameter.
":start_line: (required) The line number of original content where the search block starts.\n" + | ||
"-------\n" + | ||
"[exact content to find including whitespace]\n" + | ||
":start_line:NUMBER (optional but recommended)\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same inconsistency here - the parameter is described as "(optional but recommended)" but the tool description marks it as required. Should we standardize this across both files?
Closing, see #7750 (comment) |
Summary
This PR addresses Issue #7750 where Grok Coder models were experiencing parsing errors with the apply_diff tool when diff markers (like
=======
) appeared in the actual file content.Problem
When AI models (particularly Grok Coder) try to edit files containing merge conflict markers or similar patterns, the diff parser would get confused and fail with unclear error messages like:
Solution
This PR improves the error handling and messaging to:
Changes
multi-search-replace.ts
andmulti-file-search-replace.ts
escaping-markers.spec.ts
Testing
Impact
This fix will help AI models (especially Grok Coder) successfully edit files that contain diff-like markers, reducing frustration and failed edit attempts.
Fixes #7750
Important
Improves error messages for diff marker escaping in
apply_diff
tool, adds examples, and enhances test coverage.multi-search-replace.ts
andmulti-file-search-replace.ts
for diff marker escaping.escaping-markers.spec.ts
for marker escaping scenarios.multi-search-replace.spec.ts
to match new error message format.validateMarkerSequencing()
to handle new error cases and provide clearer guidance.This description was created by
for f2a6e42. You can customize this summary. It will automatically update as commits are pushed.