Repository navigation
Description
Description
When a parent session starts a background shell (shell tool, background: true) and the shell finishes after session/prompt has already returned end_turn, core wakes the parent correctly: the <shell … state="completed"> message lands in the parent session and a full assistant turn runs and is persisted. But the ACP client receives zero session/update notifications for that resumed turn, so it never sees the agent's reaction.
This is the shell counterpart of #55760, which fixed the same problem for background subagents (#55834, #63395). Subagent wake-ups now stream correctly over ACP; background shells do not.
Likely cause. In packages/cli/src/acp/turn.ts, handoff keeps following the session after the turn only while subagent children are open:
opencode/packages/cli/src/acp/turn.ts
Lines 323 to 348 in aa2960f
| const handoff = Effect.fnUntraced(function* ( | |
| attached: Attached, | |
| turn: Turn, | |
| exit: Exit.Exit<ACPTranslate.Terminal, ACPError.Failure>, | |
| ) { | |
| const close = Scope.close(turn.subscription.scope, Exit.void) | |
| if (Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)) return yield* close | |
| const state = yield* Ref.get(turn.state) | |
| if (state.openChildren.size === 0) { | |
| if (state.children.size > 0) backgrounds.set(attached, { state: turn.state }) | |
| return yield* close | |
| } | |
| const responded = yield* ACPConnection.Responded | |
| const nextState = yield* Ref.make({ ...state, started: false }) | |
| const cancelled = yield* Deferred.make<void>() | |
| // Children outlive a cancelled turn, so their asks and report-triggered turns still reach the client. | |
| const background = Effect.withFiber((fiber) => { | |
| backgrounds.set(attached, { state: nextState, fiber }) | |
| return Effect.exit(responded).pipe( | |
| Effect.andThen( | |
| followChildren({ ...turn, ctx: { ...turn.ctx, start: undefined }, state: nextState, cancelled }), | |
| ), | |
| Effect.interruptible, | |
| ) | |
| }).pipe(Effect.ignore, Effect.ensuring(close), Effect.withSpan("cli.acp.turn.background")) | |
| yield* input.sessions.fork(attached, background).pipe(Effect.catchTag("ACPSessionNotFoundError", () => close)) |
With no open children it closes the subscription (L331–335), so the turn started by the shell's completion has no listener. Running background shells are not considered.
Expected. The resumed parent turn streams as ordinary session/update notifications, the same as for a completed background subagent. That is: keep following while the session has running background shells, as handoff already does for openChildren.
Plugins
Not checked. The repro uses only the built-in shell tool.
OpenCode version
2.3.0 (opencode acp, agentInfo.version: "2.3.0")
Steps to reproduce
- Start
opencode acpand sendinitialize, thensession/new. session/promptwith:Use the shell tool with background: true to run `sleep 15 && echo BG_REPRO_DONE`. Do not wait for it. Reply with exactly STARTED and end your turn. When the shell completes, reply with exactly RESUMED.- Keep reading stdout for 75 s after the prompt returns.
What the ACP client receives:
4.1s tool_call_update shell in_progress {"command":"sleep 15 && echo BG_REPRO_DONE","background":true}
4.3s tool_call_update shell completed
7.4s agent_message_chunk "STARTED"
7.4s session/prompt → {"stopReason":"end_turn"}
82.7s (nothing else received)
What the session contains (read back through opencode serve, GET /api/session/{id}/message):
assistant "STARTED"
idle outcome: succeeded
user (synthetic) <shell id="sh_…" state="completed" command="sleep 15 && echo BG_REPRO_DONE"> BG_REPRO_DONE </shell> (+12 s)
assistant "RESUMED" (+15 s)
idle outcome: succeeded
So the wake-up and the RESUMED turn happen server-side about 15 s after the prompt returned, but none of it reaches the ACP client.
Screenshot
N/A
Operating System
macOS 27.0.1
Terminal
N/A (stdio ACP client)
Activity
opencodejr commentedon Nov 15, 2026
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the detailed report. I reproduced this on 2.3.0 using a local mock model server in place of a real provider.
What I did:
opencode acpand sentinitialize,session/newandsession/prompt.sleep 15 && echo BG_REPRO_DONEwith theshelltool andbackground: true, then repliedSTARTED.session/promptreturnedend_turn.About 15 s later the server sent the model the
<shell … state="completed">BG_REPRO_DONE</shell>wake-up and theRESUMEDturn ran. The ACP client got 0session/updatenotifications in the 45 s afterend_turn.It still happens on the latest
dev(aa2960fa2). The script below reproduces it, withopencodefrom PATH or a checkout viaOC_DEV.Related: #55760 (the same symptom for background subagents, fixed by #63395).
Reproduction script (repro.ts)
Run it:
bun repro.tsr266-tech commentedon Nov 16, 2026
Candidate: r266-tech@2754a41
I reproduced this with a real
opencode acpsubprocess and a background shell released by a file signal afterend_turn. The patch retains the existing subscription for background shell work, checking job → inbox → active in the same order as the noninteractive client. It preserves following across another prompt and retires the subscription when work clears. Ordinary prompts make no background queries.Full CLI: 405 pass / 9 skip / 0 fail; unmodified
devfails the five new background cases, including the subprocess reproduction. Concurrent randomized repeats: 120 pass. Rootbun run check(35 tasks) and CLItypecheck:tscpass.Local macOS/Bun 1.4.4 with a scripted SSE provider; no real provider tested. The repository’s three-open-PR limit prevents submission, so the branch is available for review/reuse.