fix(edit): show candidate lines with similarity score on oldText match failure #97035
fix(edit): show candidate lines with similarity score on oldText match failure #97035maweibin wants to merge 1 commit into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 6, 2026, 12:39 AM ET / 04:39 UTC. Summary PR surface: Source +58, Tests +106. Total +164 across 2 files. Reproducibility: yes. Current main and v2026.6.11 are source-reproducible as generic edit mismatch errors with capped current-file context but no candidate-line diagnostics. Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Land one bounded edit-mismatch diagnostic contract that preserves exact matching and current-file context, then close or rebase sibling candidate PRs against that chosen contract. Do we have a high-confidence way to reproduce the issue? Yes. Current main and v2026.6.11 are source-reproducible as generic edit mismatch errors with capped current-file context but no candidate-line diagnostics. Is this the best way to solve the issue? Unclear. The shared edit-diff path is the right layer, but this PR's similarity-only output is narrower than the linked issue and richer sibling PRs, so the final format needs maintainer selection. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f296dc4e68e4. Label changesLabel justifications:
Evidence reviewedPR surface: Source +58, Tests +106. Total +164 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (3 earlier review cycles)
|
70fc97a to
42829d2
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
42829d2 to
cc916d2
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
d9bf83b to
69191be
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
Merge ReadinessEdit tool UX improvement: when
@steipete @vincentkoc — UX polish on edit tool, ready for review. |
…dError (openclaw#97035 P2) Use content.split('\n', CANDIDATE_MAX_LINES) instead of split on the entire content then slice. For large or minified files the old code still traversed and allocated the whole file's line array before the 200-line cap applied.
5d84b40 to
874f3d4
Compare
…dError (openclaw#97035 P2) Use content.split('\n', CANDIDATE_MAX_LINES) instead of split on the entire content then slice. For large or minified files the old code still traversed and allocated the whole file's line array before the 200-line cap applied.
…h failure (openclaw#97035) When oldText matching fails, the error message now shows up to 3 candidate lines from the file content ranked by similarity score (Levenshtein distance), helping users identify whitespace or indentation mismatches. Bounds applied throughout: - Content split capped at 200 lines - Line scoring limited to first 200 chars per line - oldText lines capped before trim/slicing - similarityScore threshold at 0.3 Fixes: openclaw#97032
874f3d4 to
c851eed
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Thanks @maweibin. The canonical fix for #97032 landed through #97038 as 4204a948457cafc601c1f27a1965fcfb011c2131. We selected #97038 because it keeps the diagnostic in the shared edit-diff owner path, bounds both scan cost and output, and covers typo, indentation, escaping, cap, and surrogate-safe truncation behavior with focused tests. This PR targets the same behavior, so I’m closing it as superseded. Your parallel implementation helped validate the need and solution space. |
Fixes #97032.
What Problem This Solves
When the edit tool's
oldTextmatch fails, it only returns "Could not find the exact text" with no diagnostic information. Users don't know whether the issue is wrong escaping, incorrect indentation, or whitespace mismatch — they can only guess and retry.Why This Change Was Made
Extended
getNotFoundError()to compute Levenshtein-based similarity scores between the oldText and file content lines. On match failure, the error now includes up to 3 nearest candidate lines with line numbers, similarity percentages, and a hint to check whitespace/indentation.Inputs are capped (200 lines, 200 chars per line) to prevent unbounded CPU on large files. The matching algorithm itself is unchanged.
User Impact
Edit tool users now see actionable diagnostics on match failure:
Evidence
Behavior addressed: Edit tool oldText match failure lacks candidate diagnostics.
Real environment tested: Node 24.13.1, direct
applyEditsToNormalizedContentcall.Exact steps or command run after this patch:
Evidence after fix:
Observed result after fix: On oldText match failure, up to 3 nearest candidate lines are displayed with similarity scores. Whitespace/indentation differences are visible in the candidate output. Large files are bounded at 200 lines / 200 chars per line.
Regression Test Plan
node scripts/run-vitest.mjs src/agents/sessions/tools/edit.test.ts src/agents/agent-tools.create-openclaw-coding-tools.test.ts --runnode scripts/run-oxlint.mjs src/agents/sessions/tools/edit-diff.ts— cleanAI Assistance