fix: scope fuzzy-edit normalization to matched region only (#89994)#96814
fix: scope fuzzy-edit normalization to matched region only (#89994)#96814jiahjian wants to merge 1 commit into
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close: this PR targets the real fuzzy-edit corruption bug, but it is superseded by #96636, which is the safer open landing candidate with sufficient proof, a merge ref, and green current checks; this branch still has a normalized-offset mapper bug. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Continue the fix on #96636 or an equivalent canonical branch with segment-aware normalized-offset mapping, and close this duplicate branch. So I’m closing this here and keeping the remaining discussion on #96636. Review detailsBest possible solution: Continue the fix on #96636 or an equivalent canonical branch with segment-aware normalized-offset mapping, and close this duplicate branch. Do we have a high-confidence way to reproduce the issue? Yes. The linked issue has a high-confidence source reproduction on current main, and a no-write probe of this PR's mapper shows a concrete zero-length splice for a fuzzy match inside Is this the best way to solve the issue? No. Keeping the original write/diff base is the right direction, but this branch's prefix binary-search mapper is not the best fix; the canonical branch should use segment-aware normalized-offset mapping. Security review: Security review cleared: The diff changes TypeScript edit-helper logic, colocated Vitest coverage, and a local proof script only; it adds no dependencies, workflows, package metadata, secrets handling, or downloaded code. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 31a0f97dd944. |
164c331 to
caa0d5f
Compare
…89994) When any edit falls back to fuzzy matching, normalizeForFuzzyMatch was applied to the entire file, silently mutating unrelated lines (trailing whitespace stripped, smart quotes/dashes/spaces converted to ASCII, NFKC recomposed). The model-facing diff was computed against the already-normalized base, making the corruption invisible. Fix: use normalizeForFuzzyMatch only to locate match positions. Add findOriginalPosition (prefix-based binary search) and findOriginalSpan to map fuzzy match positions back to original content. Keep baseContent as the original LF-normalized content so untouched lines are preserved byte-for-byte. Closes openclaw#89994. Co-Authored-By: Claude <[email protected]>
caa0d5f to
aa43d9b
Compare
|
ClawSweeper applied the proposed close for this PR.
|
What Problem This Solves
Fixes P0 issue #89994: when any edit in the
edittool falls back to fuzzy matching,normalizeForFuzzyMatchwas applied to the entire file instead of just the matched region. This silently mutates unrelated lines — trailing whitespace stripped, smart quotes/dashes/spaces converted to ASCII, NFKC recomposed — and the diff shown to the model is computed against the already-normalized base, making the corruption invisible to both the model and the user.Root cause (in
applyEditsToNormalizedContent):Then
newContentis spliced from this already-normalized base, writing the corrupted content to disk.Fix: Use
normalizeForFuzzyMatchonly to locate match positions. AddfindOriginalPosition(prefix-based binary search with>=boundary) andfindOriginalSpanto map fuzzy match positions back to the original content.baseContentis now always the original LF-normalized content, so untouched lines are preserved byte-for-byte.Evidence
Real terminal output — proof script (
npx tsx scripts/proof-issue-89994.ts)Key observations
—) preserved — not converted to ASCII hyphenlet x = 1;keeps its 3 trailing spaces“/”) preserved — not converted to straight quotesffi) preserved — not decomposed toffireturn 2;→return 3;) appears as+/-, unrelated lines appear only as contextUnit test results — 7/7 passing
🤖 Generated with Claude Code