Skip to content

fix(coding-agent): show the edit diff a failed call already applied - #340

Merged
liuedcson merged 1 commit into
mainfrom
fix/edit-diff-after-failed-call
Nov 2, 2026
Merged

liuedcson merged 1 commit into
mainfrom
fix/edit-diff-after-failed-call

Conversation

@liuedcson

Copy link
Copy Markdown
Collaborator

Problem

An edit whose file write landed can still be reported as a failed call:

  • a cancelled then_run raises ToolExecutionError carrying the change receipt;
  • a result-preparation failure keeps the result details while flagging the call.

The edit renderer read the diff only when the call succeeded, so an applied change disappeared from the card. On the Step presentation the args-based preview had already been recomputed against the changed file, so the card instead showed a stale "Could not find the exact text" error.

Refs #337.

Change

  • packages/coding-agent/src/core/tools/edit.ts: read details.diff regardless of context.isError. A failure before the write records no details at all, so it still shows only its error.
  • packages/coding-agent/test/step-then-run-command-parity.test.ts: cancel the embedded check for real, then assert the raised ToolExecutionError carries isError with the exact diff/patch, and that rendering the failed call shows both sides of the diff.
  • apps/cli/test/edit-tool-no-full-redraw.test.ts: pin the default Step presentation — the recorded diff replaces the stale preview error and the card still reads as failed; and a failed call with no change record shows no diff.

Validation

  • packages/coding-agent: pnpm exec vitest --run test/step-then-run-command-parity.test.ts test/tools.test.ts — 89 passed.
  • apps/cli: pnpm exec vitest --run test/edit-tool-no-full-redraw.test.ts — 5 passed.
  • Reverting the renderer change makes the new regressions fail (checked in both test files).
  • Root pnpm run check — passed.

Not covered

A call cancelled in the narrow window after the write but before the receipt is built (edit.ts write followed by throwIfAborted()) throws a plain error with no details, so there is nothing for the renderer to read. That needs the receipt to be constructed before the abort check, in the kernel, and is left out of this change.

An edit whose file write landed can still be reported as a failed call: a
cancelled `then_run` raises `ToolExecutionError` with the change receipt, and
a result-preparation failure keeps the details while flagging the call. The
edit renderer dropped the diff in both cases, so a change nothing could undo
from the card looked like it never happened.

Read the diff from the result details regardless of the call's own status. A
failure before the write records no detail at all, so it still shows only its
error. A Step card test pins the default presentation, where a stale
args-based preview error was shown instead of the recorded change.
@liuedcson
liuedcson merged commit fa10063 into main Nov 2, 2026
2 checks passed
@liuedcson
liuedcson deleted the fix/edit-diff-after-failed-call branch November 2, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant