Skip to content

fix(acp): complete edits whose patch header cannot be parsed - #62186

Open
neriousy wants to merge 2 commits into
devfrom
acp-newline-filename
Open

neriousy wants to merge 2 commits into
devfrom
acp-newline-filename

Conversation

@neriousy

@neriousy neriousy commented Nov 5, 2026

Copy link
Copy Markdown
Member

What was wrong

Over ACP, editing a file whose name contains a newline (for example notes.txt\nx) changed the file, but the tool call never completed. The prompt then failed with -32603 Internal error, which ended the turn.

Root cause

When a tool call completes, withCompletedDiffs in packages/cli/src/acp/permission.ts rebuilds a client diff from the patch the tool recorded. A newline in the file name breaks the patch header, so parsePatch throws Unknown line 5 "x". That was the only call in the per-file pipeline not wrapped in Effect.try. The throw became a defect, which the per-file Effect.orElseSucceed does not catch, so the error escaped and failed the whole update and the turn.

Fix

Wrap parsePatch in Effect.try, like the applyPatch and Patch.derive calls next to it. If the patch can't be parsed, the existing fallback now handles it: the tool call completes without a diff for that file, and the turn continues.

How verified

  • New wire-level test in packages/cli/test/acp/prompt.test.ts sends a completed edit for notes.txt\nx through the real ACP agent. Before the fix it fails with the same -32603 Internal error the issue reports. With the fix the turn ends with end_turn and the tool call completes. The test is skipped on Windows, because Windows file names cannot contain a newline.
  • bun test test/acp/ in packages/cli: 101 pass. The new test also passed --rerun-each 10.
  • bun typecheck in packages/cli: clean.

No feature flag: this is a bug fix.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round">
  <style>
    .pulse{animation:p 2.4s ease-in-out infinite}
    .check{stroke-dasharray:18;stroke-dashoffset:0;animation:c 2.4s ease-out infinite}
    @keyframes p{0%,100%{opacity:.35}50%{opacity:.8}}
    @keyframes c{0%,20%{stroke-dashoffset:18}45%,100%{stroke-dashoffset:0}}
    @media (prefers-reduced-motion:reduce){.pulse,.check{animation:none}}
  </style>
  <rect x="8" y="12" width="224" height="48" rx="10" stroke-opacity=".3"/>
  <rect x="20" y="24" width="24" height="24" rx="5" stroke-opacity=".5"/>
  <path d="M26 31h12M26 36h8M26 41h10" stroke-opacity=".5"/>
  <text x="56" y="34" font-family="ui-monospace,monospace" font-size="11" fill="currentColor" stroke="none" fill-opacity=".85">edit notes.txt\nx</text>
  <rect class="pulse" x="56" y="41" width="96" height="4" rx="2" fill="currentColor" stroke="none"/>
  <circle cx="206" cy="36" r="12" stroke-opacity=".6"/>
  <path class="check" d="M200 36l4.5 4.5L212 31" stroke-width="2"/>
</svg>

Closes #54831

@opencodejr opencodejr 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.

The fix is sound. On the base, the new ACP wire test fails with the -32603 Internal error from the issue. With this change it passes, and all of test/acp/ passes (101 tests). typecheck:tsc is clean.

Wrapping parsePatch in Effect.try lets a bad patch header take the existing per-file orElseSucceed fallback, the same way the applyPatch and Patch.derive calls next to it already do. The file gets no diff and the turn continues.

Public API: unchanged.

One small point: this is a one-line fix, so the new test in prompt.test.ts can be dropped to keep the change minimal.

@opencodejr opencodejr 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.

The new commit only adds a test. It runs a real ACP subprocess and edits notes.txt\nx. I ran it: on the base it fails with the -32603 internal error, and with this change it passes. All of test/acp/ passes (102 tests), and typecheck:tsc is clean. Public API: unchanged.

The fix is still sound. Like the wire test in prompt.test.ts, this second test isn't needed for a one-line fix and can be dropped to keep the change minimal.

This branch has not been deployed

No deployments
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.

v2 ACP: editing a filename containing a newline changes the file, then fails the session

1 participant