You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
v2 ACP: editing a filename containing a newline changes the file, then fails the session #54831
In OpenCode v2 over ACP, editing an existing file whose name contains a newline succeeds on disk and returns success to the model, but the client never receives completion. The session then fails with an internal error.
Tested on Linux at commit 4617210822bdbb31e5749751afbfb4584ccedac8, using diff 8.0.4. The relevant code remained unchanged on dev at e41e7e9064f1cb380f0905dd19c611756a577e79; that newer commit was not tested in a full session.
The simplified input above confirms the diff-parser failure. The full ACP failure was observed in an automated test using main.txt\nx and a longer replacement; the simplified ACP session was not rerun. Ordinary filenames do not trigger it.
Observed behavior and comparison
OpenCode changed the file and told the model Edited main.txt\nx (1 replacement). The client remained at in_progress, then received JSON-RPC error -32603: Internal error: Internal service failure. A subsequent shell call received no result.
In the same differential test, Claude Code, Codex, and DeepSeek Harness successfully edited the same filename and continued through both later calls. Gemini CLI rejected the filename with Invalid path: Path contains invalid characters (newlines or control characters), but continued normally. Only OpenCode failed the session.
Expected: a successful edit should report completion and allow further calls, even if its client diff cannot be displayed.
Thanks for the detailed report. I can confirm the underlying failure on the latest dev (e41e7e9), though only at the function level: I didn't run a full ACP session.
When an edit finishes, the ACP layer rebuilds a client diff from the patch the tool returns (withCompletedDiffs in packages/cli/src/acp/permission.ts). For a file named notes.txt\nx, the newline breaks the patch header, and diff's parsePatch throws Unknown line 5 "x". That throw isn't caught the way other preview failures are. So instead of sending the completion without a diff, the update fails. Judging from the code in turn.ts, that would also end the turn, which fits the missing completion and the -32603 you saw. The same input with an ordinary filename works.
The script below reproduces it with a small Bun test against that function. The relevant code is the same at the commit you tested (4617210).
// Copy into packages/cli/test/acp/ of an opencode checkout and run from packages/cli: bun test test/acp/acp-newline-filename.test.ts// Exercises the ACP completed-tool-call path (withCompletedDiffs) with the metadata core's edit tool// produces (fileDiff -> createTwoFilesPatch) for a file whose name contains a newline.import{test,expect}from"bun:test"import{Effect,Exit,Cause}from"effect"import{mkdtempSync,writeFileSync}from"node:fs"import{tmpdir}from"node:os"import{join}from"node:path"import{createTwoFilesPatch}from"diff"import*asACPPermissionfrom"../../src/acp/permission"construn=async(name: string)=>{constcwd=mkdtempSync(join(tmpdir(),"acp-nl-"))writeFileSync(join(cwd,name),"world\n")constupdate={sessionUpdate: "tool_call_update",toolCallId: "t1",status: "completed"}asanyconstsource={toolName: "edit",input: {path: name,oldString: "hello",newString: "world"},metadata: {files: [{file: name,patch: createTwoFilesPatch(name,name,"hello\n","world\n"),status: "modified",additions: 1,deletions: 1}]},}asanyreturnEffect.runPromiseExit(ACPPermission.withCompletedDiffs(update,source,cwd))}test("ordinary filename completes with a diff",async()=>{constexit=awaitrun("notes.txt")expect(Exit.isSuccess(exit)).toBe(true)})test("filename containing a newline should still complete",async()=>{constexit=awaitrun("notes.txt\nx")if(Exit.isFailure(exit))console.log(Cause.pretty(exit.cause))expect(Exit.isSuccess(exit)).toBe(true)})
The failure is in packages/cli/src/acp/permission.ts, in withCompletedDiffs: the per-file preview pipeline wraps applyPatch in Effect.try but calls parsePatch(file.patch) bare, so the Unknown line 5 "x" that a newline in the filename causes is raised as a defect rather than as a typed failure. Effect.orElseSucceed at the end of that same pipeline only catches typed failures, so the defect escapes, the tool_call_update fails, and the turn ends — which matches both the missing completion and the -32603.
Plan: make that call total the way its neighbour already is, so a patch whose header cannot be parsed yields no client diff and the tool call still completes. A preview is best effort (withCompletedDiffs already returns the update unchanged when it has no diffs), so I will also check the remaining unguarded step in that pipeline — structuredPatch after Patch.derive — rather than leave the next newline-shaped input to find it.
Verification: your repro shape as a regression test in packages/cli/test/acp/, asserting the effect succeeds for a filename containing a newline, with the ordinary filename kept as the control case; red against the current code, green with the fix.
Activity
opencode-agent commentedon Oct 12, 2026
Thanks for the detailed report. I can confirm the underlying failure on the latest
dev(e41e7e9), though only at the function level: I didn't run a full ACP session.When an
editfinishes, the ACP layer rebuilds a client diff from the patch the tool returns (withCompletedDiffsinpackages/cli/src/acp/permission.ts). For a file namednotes.txt\nx, the newline breaks the patch header, anddiff'sparsePatchthrowsUnknown line 5 "x". That throw isn't caught the way other preview failures are. So instead of sending the completion without a diff, the update fails. Judging from the code inturn.ts, that would also end the turn, which fits the missing completion and the-32603you saw. The same input with an ordinary filename works.The script below reproduces it with a small Bun test against that function. The relevant code is the same at the commit you tested (
4617210).Reproduction script (acp-newline-filename.test.ts)
Run it:
bun acp-newline-filename.test.tsargszero commentedon Oct 12, 2026
I'd like to work on this.
The failure is in
packages/cli/src/acp/permission.ts, inwithCompletedDiffs: the per-file preview pipeline wrapsapplyPatchinEffect.trybut callsparsePatch(file.patch)bare, so theUnknown line 5 "x"that a newline in the filename causes is raised as a defect rather than as a typed failure.Effect.orElseSucceedat the end of that same pipeline only catches typed failures, so the defect escapes, thetool_call_updatefails, and the turn ends — which matches both the missing completion and the-32603.Plan: make that call total the way its neighbour already is, so a patch whose header cannot be parsed yields no client diff and the tool call still completes. A preview is best effort (
withCompletedDiffsalready returns the update unchanged when it has no diffs), so I will also check the remaining unguarded step in that pipeline —structuredPatchafterPatch.derive— rather than leave the next newline-shaped input to find it.Verification: your repro shape as a regression test in
packages/cli/test/acp/, asserting the effect succeeds for a filename containing a newline, with the ordinary filename kept as the control case; red against the current code, green with the fix.