Skip to content

fix(edit): show candidate lines with similarity scores on oldText match failure#97038

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
ZOOWH:fix/97032-edit-notfound-candidates
Jul 6, 2026
Merged

fix(edit): show candidate lines with similarity scores on oldText match failure#97038
vincentkoc merged 3 commits into
openclaw:mainfrom
ZOOWH:fix/97032-edit-notfound-candidates

Conversation

@ZOOWH

@ZOOWH ZOOWH commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

When the edit tool cannot find oldText exactly, its failure only reports the expected and observed text. Agents cannot see the closest candidate lines, so small typos, indentation drift, or escaping differences lead to repeated blind retries.

Why This Change Was Made

The failure path now performs a bounded similarity scan and reports the three strongest candidate lines with scores. The scan is capped at 128 Ki UTF-16 code units and 1,000 lines, candidate display is capped at 120 characters, and unrelated matches below 45% are omitted. The successful edit path is unchanged.

User Impact

Edit failures become actionable without dumping large files or adding work to successful edits. Diagnostics identify likely typo, indentation, and escaping mismatches while keeping output and computation bounded.

Evidence

  • node scripts/run-vitest.mjs src/agents/sessions/tools/edit-diff.test.ts src/agents/sessions/tools/edit.test.ts — 9 diagnostic tests and 23 existing edit-tool tests passed.
  • Fresh GPT-5.5 branch autoreview found no actionable issues on exact head 59b8f921f6d57ed186ed46a2b33b2e95d0601b3d.
  • Native review artifacts validate as READY with zero findings.
  • Pre-rebase Testbox changed gate passed in tbx_01kwwh3bersv6jy68szp13b21a (Actions run 28820306743); exact-head CI is tracked in Actions run 28824931017.

Closes #97032

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 26, 2026
@clawsweeper

clawsweeper Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 6, 2026, 6:00 PM ET / 22:00 UTC.

Summary
The branch adds bounded Levenshtein-based candidate-line hints and focused tests to edit-diff oldText not-found errors.

PR surface: Source +144, Tests +100. Total +244 across 2 files.

Reproducibility: yes. source-level: current main's getNotFoundError emits only the generic mismatch text, and edit execution routes through applyEditsToNormalizedContent. I did not run a live edit command in this read-only review.

Review metrics: 1 noteworthy metric.

  • Similarity scoring budget: 3 hints; 1,000 lines; 128 KiB scan; 120 chars/line; 45% threshold. These bounds are the main safety property for adding Levenshtein work to the edit mismatch error path.

Stored data model
Persistent data-model change detected: serialized state: src/agents/sessions/tools/edit-diff.test.ts, serialized state: src/agents/sessions/tools/edit-diff.ts, unknown-data-model-change: src/agents/sessions/tools/edit-diff.test.ts, unknown-data-model-change: src/agents/sessions/tools/edit-diff.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #97032
Summary: The open issue is the canonical request for edit oldText mismatch diagnostics; this PR is one candidate fix among several overlapping implementations.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted terminal output, copied live output, or logs from a real edit-tool mismatch that shows the candidate-line diagnostics.
  • Have a maintainer choose the canonical output shape among the overlapping edit mismatch PRs.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only tests, CI, and review-artifact statements are visible; add a redacted real edit-tool terminal run or log showing the new mismatch output, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.

Risk before merge

  • [P1] Multiple open PRs implement the same edit mismatch diagnostic, so merging one without an explicit canonical choice can leave competing output contracts and stale candidate branches.
  • [P1] The current PR body shows test and CI evidence, but I did not find an after-fix real edit-tool invocation transcript or terminal output; contributor proof should be added before merge unless a maintainer overrides the gate.

Maintainer options:

  1. Add Proof And Select This Branch (recommended)
    Ask for or provide a redacted terminal/live output proof of a failed edit showing candidate lines, then land this branch as the canonical implementation if the output shape is accepted.
  2. Pause For The Richer Diagnostic
    If the richer expected/found/escaped-diff output is preferred, pause or close this PR after choosing the sibling branch that should own the issue.
  3. Consolidate The Output Contract
    Move the selected hint wording, bounds, and regression tests into one branch before merge to avoid competing diagnostics.

Next step before merge

  • [P1] Manual review is the right lane because the remaining blocker is canonical output selection and visible proof, not a narrow code defect for automation to repair.

Maintainer decision needed

  • Question: Which edit oldText mismatch diagnostic output should become the canonical implementation for edit tool: show candidate lines with diff on oldText match failure #97032?
  • Rationale: Several viable PRs implement the same user-facing diagnostic with different wording and richness, and tests cannot choose the permanent output contract.
  • Likely owner: vincentkoc — vincentkoc is assigned, authored the latest branch-compatible commit, and has recent history in the edit-diff helper.
  • Options:
    • Use This Concise Branch (recommended): After adding visible real edit-tool proof and clearing exact-head gates, land this mergeable implementation as the canonical bounded candidate-line diagnostic.
    • Choose A Richer Sibling: If maintainers want escaped diff and indentation presentation to be more explicit now, pause this PR and select a richer overlapping branch instead.
    • Consolidate Before Merge: Port the preferred wording, bounds, and tests into one branch so only one edit mismatch diagnostic contract ships.

Security
Cleared: The diff changes edit-tool diagnostics and focused tests only, with no dependency, workflow, secret, permission, package, or network surface change.

Review details

Best possible solution:

Land one maintainer-selected bounded edit-diff diagnostic with redacted real terminal proof, then close or rebase the sibling candidate PRs against that canonical output.

Do we have a high-confidence way to reproduce the issue?

Yes, source-level: current main's getNotFoundError emits only the generic mismatch text, and edit execution routes through applyEditsToNormalizedContent. I did not run a live edit command in this read-only review.

Is this the best way to solve the issue?

Mostly yes: the shared edit-diff helper is the right layer because execution and preview share it, and the patch keeps matching semantics unchanged. The remaining questions are the canonical output shape and visible real behavior proof.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e80e8a2b6730.

Label changes

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only tests, CI, and review-artifact statements are visible; add a redacted real edit-tool terminal run or log showing the new mismatch output, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.
  • remove proof: sufficient: Current real behavior proof status is mock_only, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P3: This is a focused edit-tool diagnostics and ergonomics enhancement with limited blast radius.
  • merge-risk: 🚨 other: Several open PRs implement the same linked edit mismatch diagnostic, so green CI does not choose the canonical user-facing output.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only tests, CI, and review-artifact statements are visible; add a redacted real edit-tool terminal run or log showing the new mismatch output, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +144, Tests +100. Total +244 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 151 7 +144
Tests 1 100 0 +100
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 251 7 +244

What I checked:

Likely related people:

  • vincentkoc: Assigned to this PR, authored the latest branch-compatible PR commit, and previously refactored the session edit-diff helper. (role: recent area contributor and likely follow-up owner; confidence: high; commits: 59b8f921f6d5, 0455028a3cd2; files: src/agents/sessions/tools/edit-diff.ts, src/agents/sessions/tools/edit-diff.test.ts)
  • mbelinky: The current bounded file-content mismatch hint path traces back to edit tool recovery hardening in the earlier Pi edit surface. (role: introduced current recovery behavior; confidence: medium; commits: 922f4e66ea1a; files: src/agents/pi-tools.host-edit.ts, src/agents/pi-tools.read.ts)
  • zw-xysk: Recently changed adjacent no-op edit/write handling in the same current edit.ts and edit-diff.ts paths. (role: recent behavior contributor; confidence: medium; commits: ab966c214be0; files: src/agents/sessions/tools/edit.ts, src/agents/sessions/tools/edit-diff.ts)
  • mikasa0818: Recently fixed unicode-safe truncation for the existing edit mismatch hint surface that this PR extends. (role: adjacent diagnostic contributor; confidence: medium; commits: f27d494d00e7; files: src/agents/sessions/tools/edit.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-06-26T14:22:42.865Z sha 9c9b1e5 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-06T21:16:11.120Z sha 651751a :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jun 26, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 26, 2026
@ZOOWH

ZOOWH commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Fixed P2: replaced .sort() with .toSorted() for candidate ranking.

@clawsweeper

clawsweeper Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 26, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 26, 2026
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 26, 2026
@ZOOWH

ZOOWH commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

1 similar comment
@ZOOWH

ZOOWH commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 26, 2026
ZOOWH and others added 3 commits July 6, 2026 13:27
When edit tool cannot find oldText, include up to 3 near-match candidate
lines with similarity scores and line numbers. Caps input size (MAX_LINES
3000, MAX_LINE_LEN 200) to avoid unbounded CPU on large files. Reuses
existing levenshteinDistance helper.

Closes openclaw#97032
Fixes lint violation: unicorn(no-array-sort)
@vincentkoc
vincentkoc force-pushed the fix/97032-edit-notfound-candidates branch from 651751a to 59b8f92 Compare July 6, 2026 21:36
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@openclaw-barnacle openclaw-barnacle Bot added triage: blank-template Candidate: PR template appears mostly untouched. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 6, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 6, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Land-ready maintainer proof for exact head 59b8f921f6d57ed186ed46a2b33b2e95d0601b3d:

  • Focused regression proof: node scripts/run-vitest.mjs src/agents/sessions/tools/edit-diff.test.ts src/agents/sessions/tools/edit.test.ts — 9 diagnostic tests and 23 existing edit-tool tests passed.
  • Fresh GPT-5.5 branch autoreview: no actionable findings.
  • Native review artifacts: validated, READY, zero findings.
  • Supplemental pre-rebase Testbox changed gate: tbx_01kwwh3bersv6jy68szp13b21a, Actions run 28820306743.
  • Exact-SHA capacity fallback: CI release gate 28825597082 completed successfully across the full graph, including QA Smoke CI and native-i18n.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 97038 accepted the hosted exact-head evidence and verified the remote PR tree matches the prepared tree.
  • Patch remains +251/-7 across 2 files. GitHub reports it mergeable. No remaining proof gaps.

@vincentkoc
vincentkoc merged commit 4204a94 into openclaw:main Jul 6, 2026
255 of 267 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

@ZOOWH
ZOOWH deleted the fix/97032-edit-notfound-candidates branch July 7, 2026 00:41
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 7, 2026
…ch failure (openclaw#97038)

* fix(edit): show candidate lines on oldText match failure

When edit tool cannot find oldText, include up to 3 near-match candidate
lines with similarity scores and line numbers. Caps input size (MAX_LINES
3000, MAX_LINE_LEN 200) to avoid unbounded CPU on large files. Reuses
existing levenshteinDistance helper.

Closes openclaw#97032

* fix(edit): use toSorted instead of sort for candidate ranking

Fixes lint violation: unicorn(no-array-sort)

* fix(edit): keep candidate truncation branch-compatible

---------

Co-authored-by: Vincent Koc <[email protected]>
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
…ch failure (openclaw#97038)

* fix(edit): show candidate lines on oldText match failure

When edit tool cannot find oldText, include up to 3 near-match candidate
lines with similarity scores and line numbers. Caps input size (MAX_LINES
3000, MAX_LINE_LEN 200) to avoid unbounded CPU on large files. Reuses
existing levenshteinDistance helper.

Closes openclaw#97032

* fix(edit): use toSorted instead of sort for candidate ranking

Fixes lint violation: unicorn(no-array-sort)

* fix(edit): keep candidate truncation branch-compatible

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: blank-template Candidate: PR template appears mostly untouched.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

edit tool: show candidate lines with diff on oldText match failure

2 participants