Skip to content

improve: show edit mismatch candidate lines#97512

Closed
aditya-vithaldas wants to merge 7 commits into
openclaw:mainfrom
aditya-vithaldas:codex/edit-mismatch-candidates
Closed

improve: show edit mismatch candidate lines#97512
aditya-vithaldas wants to merge 7 commits into
openclaw:mainfrom
aditya-vithaldas:codex/edit-mismatch-candidates

Conversation

@aditya-vithaldas

@aditya-vithaldas aditya-vithaldas commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Closes #97032

AI-assisted by Codex.

What Problem This Solves

Resolves a problem where edit-tool exact-match failures only reported that oldText was not found and then dumped a capped file snippet. Users had no nearby line comparison to tell whether the miss was caused by indentation, escaping, whitespace, or similar text drift.

Why This Change Was Made

The edit mismatch hint now adds up to three bounded closest candidate lines before the existing capped Current file contents section. Each candidate includes a line number, expected text, found text, a simple difference marker, and a short hint such as indentation mismatch or backslash escaping mismatch.

The same hint is now applied to indexed multi-edit edits[n] not-found failures when the index is in the real-edit apply path. Mixed no-op validation errors are guarded so they do not attach candidates from the wrong edit list.

The matching algorithm is unchanged. This is diagnostic-only output on the existing exact-match failure path.

User Impact

Users and agents can recover from failed edits faster because the error points at likely nearby text and explains common mismatch classes instead of forcing blind retries.

Evidence

  • Pushed follow-up commit 77c059e7 after review feedback.
  • node scripts/run-vitest.mjs src/agents/sessions/tools/edit.test.ts src/agents/agent-tools.create-openclaw-coding-tools.test.ts
  • node node_modules/oxfmt/bin/oxfmt --check --threads=1 src/agents/sessions/tools/edit.ts src/agents/sessions/tools/edit.test.ts
  • git diff --check
  • .agents/skills/autoreview/scripts/autoreview --mode local --codex-bin /tmp/codex-fast-wrapper reported clean after the indexed multi-edit and mixed no-op guard changes.
  • Local terminal proof using production createEditTool against a temp file, with the temp path redacted:
Could not find edits[1] in <tmp>/demo.txt. The oldText must match exactly including all whitespace and newlines.
Closest candidate lines for oldText:
- line 2:
  expected: "  const beta = 2;"
  found:    "const beta = 2;"
  diff:     ^^^^^^^^^^^^ ^^^^
  hint:     indentation differs (expected 2 leading whitespace chars, found 0)

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Jun 28, 2026
@clawsweeper

clawsweeper Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 28, 2026, 4:29 PM ET / 20:29 UTC.

Summary
The branch adds bounded closest-candidate line diagnostics to edit-tool oldText mismatch errors, plus regression tests for indentation, escaping, indexed multi-edit, no-op guard behavior, and scan limits.

PR surface: Source +200, Tests +182. Total +382 across 2 files.

Reproducibility: yes. Source inspection of current main and v2026.6.10 shows only the generic exact-match failure plus bounded current-file contents, while the requested candidate-line comparison path is absent.

Review metrics: 2 noteworthy metrics.

  • Same-request PRs: 5 open PRs. Multiple active branches target the same edit mismatch diagnostics issue, so maintainers need one canonical output contract before landing.
  • Candidate diagnostic bounds: 3 candidates, 2,000 lines, 141 stored chars, 282,000 scanned chars. The review-relevant safety question is whether failed-edit diagnostics remain bounded on large or minified files.

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

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #97032
Summary: The linked issue is the canonical diagnostics request; this PR and four sibling PRs are competing candidate implementations for that same request.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • none.

Risk before merge

  • [P1] Five open PRs target the same linked diagnostics request; landing more than one could create conflicting user-facing edit mismatch output contracts.
  • [P1] The diagnostic intentionally exposes up to three nearby source lines beyond the existing capped file snippet, so maintainers should accept the final wording and exposure shape before merge.

Maintainer options:

  1. Choose This Output Contract
    Maintainers can select this branch as the canonical implementation, then merge it after routine checks finish and close or rebase the sibling PRs.
  2. Ask For One Final Combined Branch
    If maintainers prefer pieces from multiple sibling PRs, request one narrow final branch with the chosen wording and bounded scan behavior before merge.
  3. Pause In Favor Of A Sibling
    If another open PR has the desired output shape, pause or close this PR after preserving any useful tests or scan-bound fixes there.

Next step before merge

  • [P2] No narrow automated repair remains after a5aec32; maintainer review should choose the canonical diagnostics branch/output contract and let routine checks finish.

Security
Cleared: No dependency, workflow, permission, secret, package, or supply-chain changes were found; the added diagnostics stay inside the existing edit-tool read/error path.

Review details

Best possible solution:

Land one canonical bounded diagnostic implementation for #97032, then close or supersede the overlapping sibling PRs.

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

Yes. Source inspection of current main and v2026.6.10 shows only the generic exact-match failure plus bounded current-file contents, while the requested candidate-line comparison path is absent.

Is this the best way to solve the issue?

Yes for the owner boundary, with a maintainer decision still needed. The edit-tool mismatch error path is the narrow place to add this diagnostic, and PR head now bounds scan work; maintainers still need to choose this output contract over the sibling PRs.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P3: This is a low-risk edit-tool diagnostics and ergonomics improvement, not an urgent runtime or channel regression.
  • merge-risk: 🚨 other: The PR competes with sibling implementations and changes the user-facing diagnostic/source-exposure shape, which green CI cannot choose for maintainers.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes redacted terminal output from production createEditTool showing the new indexed mismatch candidate output, with follow-up comments adding focused validation for bounded behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes redacted terminal output from production createEditTool showing the new indexed mismatch candidate output, with follow-up comments adding focused validation for bounded behavior.
Evidence reviewed

PR surface:

Source +200, Tests +182. Total +382 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 206 6 +200
Tests 1 182 0 +182
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 388 6 +382

What I checked:

Likely related people:

  • mbelinky: PR fix(agents): harden edit tool recovery #52516 added the edit recovery hardening path that first appended bounded current-file contents on mismatch. (role: introduced current mismatch-content behavior; confidence: high; commits: 922f4e66ea1a; files: src/agents/pi-tools.host-edit.ts, src/agents/pi-tools.read.ts, src/agents/pi-tools.read.host-edit-recovery.test.ts)
  • steipete: The agent runtime internalization folded edit recovery into the current session edit-tool surface, and a later commit added edits[] payload support relevant to indexed mismatch output. (role: major refactor and adjacent edit-tool contributor; confidence: medium; commits: bb46b79d3c14, 693d17c4a2ae; files: src/agents/sessions/tools/edit.ts, src/agents/sessions/tools/edit-diff.ts, src/agents/pi-tools.host-edit.ts)
  • vincentkoc: Recent session-tool internals work touched edit-diff, and Vincent merged the no-op edit behavior PR that this PR carefully guards around. (role: recent adjacent contributor; confidence: medium; commits: 0455028a3cd2, ab966c214be0; files: src/agents/sessions/tools/edit-diff.ts, src/agents/sessions/tools/edit.ts, src/agents/sessions/tools/edit.test.ts)
  • zw-xysk: PR fix(tools): treat no-op writes and edits as terminal tool-loop failures (fixes #96983) #97044 recently changed no-op write/edit behavior in the same files and test area that this PR extends. (role: recent adjacent contributor; confidence: medium; commits: ab966c214be0; files: src/agents/sessions/tools/edit.ts, src/agents/sessions/tools/edit-diff.ts, src/agents/sessions/tools/edit.test.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.

@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. 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 28, 2026
@aditya-vithaldas

Copy link
Copy Markdown
Contributor Author

Updated in 77c059e7: indexed multi-edit not-found errors now receive candidate-line hints during the real-edit apply path, and mixed no-op validation errors are guarded so they do not show candidates from the wrong edit list. PR body evidence now includes focused tests, formatting, auto-review, and redacted terminal proof from production createEditTool output.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 28, 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 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. and removed 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. labels Jun 28, 2026
@aditya-vithaldas
aditya-vithaldas marked this pull request as ready for review June 28, 2026 17:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 77c059e70b

ℹ️ 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".

Comment thread src/agents/sessions/tools/edit.ts Outdated
@aditya-vithaldas

Copy link
Copy Markdown
Contributor Author

Follow-up for the CI lint failure on the ready-for-review run.

Root cause: check-lint failed on unicorn(no-array-sort) for the new closest-candidate ordering in src/agents/sessions/tools/edit.ts.

Fix pushed in 765689f4: switched the two candidate sorts to toSorted() with the same comparators.

Evidence:

  • pnpm lint --threads=8
  • node scripts/run-vitest.mjs src/agents/sessions/tools/edit.test.ts
  • git diff --check

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jun 28, 2026
@aditya-vithaldas

Copy link
Copy Markdown
Contributor Author

Addressed the ClawSweeper P2 about bounding the candidate scan before splitting in commit 71d79df.

What changed:

  • Replaced the whole-file normalizeToLF(currentContent).split("\n").slice(...) path with a bounded line collector that stops after EDIT_MISMATCH_SCAN_LINE_LIMIT normalized lines.
  • Preserved LF, CRLF, and bare-CR line delimiter behavior for candidate line numbering and text.
  • Added a regression where the best candidate is just beyond line 2000 and is not reported.

Verification:

  • /Users/AdityaWork/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node scripts/run-vitest.mjs src/agents/sessions/tools/edit.test.ts src/agents/agent-tools.create-openclaw-coding-tools.test.ts
  • /Users/AdityaWork/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node node_modules/oxfmt/bin/oxfmt --check --threads=1 src/agents/sessions/tools/edit.ts src/agents/sessions/tools/edit.test.ts
  • git diff --check
  • .agents/skills/autoreview/scripts/autoreview --mode local --codex-bin /tmp/codex-fast-wrapper - clean, no actionable findings.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 28, 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.

@aditya-vithaldas

Copy link
Copy Markdown
Contributor Author

Pushed 96d29789 as a no-op CI retrigger only. No code changed after 71d79df6; the previous security-fast failure was a Python/pre-commit dependency setup failure (No matching distribution found for pre-commit==4.2.0), before branch checks. I do not have upstream rerun rights, and #97505's fresh security-fast run is now passing, so this retriggers the recovered lane without altering the fix.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 28, 2026
@aditya-vithaldas

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

No code changed after the bounded-scan fix in 71d79df6; head 96d29789 is only the no-op CI retrigger documented above. Please re-review the current head so the post-fix author-waiting state can update against the active SHA.

@clawsweeper

clawsweeper Bot commented Jun 28, 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 the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jun 28, 2026
@aditya-vithaldas

Copy link
Copy Markdown
Contributor Author

Current-head babysit note (2026-06-28T19:48Z): head 96d297890a36d76826dd067c3a5ce642fb0c5a24 is MERGEABLE/CLEAN, has no unresolved review threads, and the current check set is green (65 pass, 32 skipping, no failing or pending checks).

The visible status: ⏳ waiting on author label appears stale relative to the bounded-scan fix in 71d79df6 and the no-op CI retrigger in 96d29789. There is no current author action showing in live review threads/checks.

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 28, 2026
@aditya-vithaldas

Copy link
Copy Markdown
Contributor Author

Addressed the refreshed ClawSweeper P2 in d19707ff.

What changed:

  • Candidate collection now caps each normalized mismatch line before storing, scoring, trimming, or formatting it.
  • The cap stores one extra character beyond the display limit so diagnostics can still show truncation with ... without carrying a full minified/no-newline line through the scoring path.
  • Added a no-newline large-line regression that would keep reporting nearest text differs without the pre-score cap, and now proves the bounded candidate still produces the expected indentation hint without exposing the tail marker.

Verification:

  • node scripts/run-vitest.mjs src/agents/sessions/tools/edit.test.ts src/agents/agent-tools.create-openclaw-coding-tools.test.ts -> 2 files, 90 tests passed
  • node node_modules/oxfmt/bin/oxfmt --check --threads=1 src/agents/sessions/tools/edit.ts src/agents/sessions/tools/edit.test.ts -> passed
  • git diff --check -> passed
  • .agents/skills/autoreview/scripts/autoreview --mode local --codex-bin .artifacts/codex-flex --prompt 'Review the #97512 follow-up patch only. Context: ClawSweeper asked to bound edit mismatch candidate lines before storing/scoring and add a no-newline large-line regression. Focus on correctness, bounded diagnostic behavior, and test adequacy.' -> clean, no accepted/actionable findings

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 28, 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.

@aditya-vithaldas

Copy link
Copy Markdown
Contributor Author

Follow-up for the refreshed ClawSweeper P2 in a5aec328.

What changed after d19707ff:

  • Added a total byte scan cap for mismatch candidate collection: EDIT_MISMATCH_SCAN_LINE_LIMIT * EDIT_MISMATCH_LINE_STORAGE_LIMIT.
  • collectNormalizedLines now stops scanning at the byte cap, then stores only the capped candidate prefix, so no-newline/minified files cannot force a full-file diagnostic scan before scoring.
  • Added a regression with a 300k-character unterminated first line followed by a better-looking candidate on line 2. The diagnostic must not scan far enough to report line 2, proving the byte cap is active rather than only the display/storage cap.

Verification:

  • node scripts/run-vitest.mjs src/agents/sessions/tools/edit.test.ts src/agents/agent-tools.create-openclaw-coding-tools.test.ts -> 2 files, 91 tests passed
  • node node_modules/oxfmt/bin/oxfmt --check --threads=1 src/agents/sessions/tools/edit.ts src/agents/sessions/tools/edit.test.ts -> passed
  • git diff --check -> passed
  • .agents/skills/autoreview/scripts/autoreview --mode local --codex-bin .artifacts/codex-flex --prompt 'Review the #97512 follow-up patch only. Context: ClawSweeper asked to bound edit mismatch candidate lines before storing/scoring, then asked to bound no-newline scan work. Focus on correctness, bounded diagnostic behavior, and test adequacy.' -> clean, no accepted/actionable findings

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 28, 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. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 28, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Thanks @aditya-vithaldas. 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.

@vincentkoc vincentkoc closed this Jul 6, 2026
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

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