fix(agents): show fuzzy match suggestions when edit oldText not found#42265
fix(agents): show fuzzy match suggestions when edit oldText not found#42265imwyvern wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52f018b3bd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Greptile SummaryThis PR adds a Issues identified:
Confidence Score: 2/5
Last reviewed commit: 52f018b |
52f018b to
b45f11d
Compare
|
Addressed all 4 review items in b45f11d:
24/24 tests pass, lint clean. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b45f11d1c6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
When the edit tool fails to find oldText in a file, the error message is a dead-end — the model has no information about what's actually in the file and often retries blindly or re-reads the entire file. This adds a new wrapper `wrapEditToolWithFuzzyMatchSuggestions` that enriches not-found errors with the closest matching regions from the file, including line numbers and similarity scores. The model can then self-correct in one shot. Algorithm: - Sliding window across file lines with LCS ratio scoring - Pre-filter eliminates 90%+ of windows cheaply - Returns top 3 matches above 40% similarity threshold Performance: - Zero overhead on success (wrapper only activates on failure) - File size cap at 100KB, binary file detection - Output capped at 2000 chars - Early termination on near-perfect (>95%) match Applied to both createHostWorkspaceEditTool and createSandboxedEditTool.
b45f11d to
73d0392
Compare
|
Fixed P1 prefilter issue in 73d0392:
26/26 tests pass, lint clean. |
|
Fixed P1 prefilter issue in 73d0392: Extracted |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 645faa2961
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
645faa2 to
e5766d1
Compare
|
Fixed P2 short-line prefilter in e5766d1: Short lines (<8 chars) now always pass the prefilter — they're cheap to LCS-score anyway, and the old |
e5766d1 to
7decafb
Compare
7decafb to
e5766d1
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5766d1ac3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e5766d1 to
a8212f3
Compare
Add explicit tests verifying the three review concerns: - fs.stat() is called before fs.readFile() (no full read before size check) - Pre-filter trims leading whitespace (indentation mismatches not rejected) - FS errors in fallback rethrow original error (not raw ENOENT) All three fixes were already present in the implementation; these tests document the expected behavior for each review point.
a8212f3 to
4b8d1d6
Compare
|
Closing to reduce active PR count (10-PR limit). Will reopen if queue clears. The branch and code are preserved. |
…head When edit oldText doesn't match exactly, the error hint now locates and displays the most similar region in the file (with line numbers) instead of dumping the first 800 characters. This helps the model quickly spot which lines diverged from its expectation. Falls back to the current full-file-head behavior when no region scores above zero shared lines. Combines the intent of openclaw#56857 and openclaw#42265.
Problem
When the edit tool fails to find
oldTextin a file, it returns:This is a dead-end — the model has no information about what's actually in the file. It often retries with the same wrong text, re-reads the entire file (wasting tokens), or gives up after multiple failed attempts.
Solution
Added a new wrapper
wrapEditToolWithFuzzyMatchSuggestionsthat enriches "not found" errors with the closest matching regions from the file. Applied to bothcreateHostWorkspaceEditToolandcreateSandboxedEditTool.Algorithm: Sliding window across file lines scored with normalized LCS ratio. A pre-filter (8-char substring check) eliminates 90%+ of windows cheaply before full LCS computation.
Performance: Zero overhead on success — the wrapper only activates on failure. File size cap (100KB), binary detection, output cap (2000 chars), and early termination on near-perfect matches (>95%).
Example: Improved Error Output
Test Coverage (24 tests)
lcsLength,lcsRatio,scoreWindows— identity, empty, partial, no-match casesold_stringparam alias, no-similar-regions fallback, multiple ranked regions, path resolution