Skip to content

fix(acp): stream running shell output on in_progress tool updates - #62191

Open
neriousy wants to merge 2 commits into
devfrom
acp-shell-stream
Open

neriousy wants to merge 2 commits into
devfrom
acp-shell-stream

Conversation

@neriousy

@neriousy neriousy commented Nov 5, 2026

Copy link
Copy Markdown
Member

What was wrong

Since v2.0, ACP clients don't see a shell command's output while it runs. The tool_call_update with status: "in_progress" has no content, and all the output only shows up on the completed update. Up to v1.18 the in-progress updates included the output so far, which let clients show a live terminal.

Root cause

In v2, live shell output moved into the core Shell service. The service writes output to a file and serves it by cursor through GET /api/shell/:id/output. While a command runs, the shell tool only reports { shellID } as progress, and the TUI polls that route to show live output. The ACP bridge was never hooked up to it: runningToolUpdate had no content, and session.tool.progress sent a bare running update.

Fix

The ACP bridge now follows a running shell the same way the TUI does:

  • translate.ts: when a shell tool reports progress with a shellID, it emits ShellFollow. When that tool succeeds, fails, or is abandoned on cancel, it emits ShellStop before the terminal update.
  • turn.ts: each followed shell gets a fiber in a per-turn FiberMap, scoped to the turn's subscription. The fiber reads client.shell.output by cursor in the session's location. It catches up right away, then waits ShellOutputInterval (1s, same as the TUI) between reads. Each new chunk sends an in_progress tool_call_update with the output so far as content.
    • The update goes through the usual routing, so child sessions and opencode/session/child_update work too.
    • The text is capped to the last 30,000 characters with a ... prefix, like v1.18's preview. A noisy command skips ahead instead of re-reading everything.
    • Sends can't be interrupted, and ShellStop waits for the fiber to end. So a running update never arrives after the tool's completed or failed update.
    • If a read fails, the live view stops (logged as a warning). The terminal update still carries the full output.
  • tool.ts: runningToolUpdate accepts an optional output, which becomes content.

The core shell tool and the server are unchanged. No feature flag, since this restores behavior that regressed.

How verified

  • New wire test in packages/cli/test/acp/prompt.test.ts ("streams a running shell command's output until the tool completes"). A fake server serves growing shell output. The test checks that in-progress updates carry line 1\n, then line 1\nline 2\n, that the read uses the session location, and that the last update is the single completed one. It fails on dev and passes here, including with --rerun-each 20.
  • New end-to-end test packages/cli/test/acp/shell-output.subprocess.test.ts. It runs the real opencode acp over stdio JSON-RPC with createAcpFixture, in an isolated env with a mock LLM. The mock model calls shell with echo line 1; sleep 2; echo line 2; sleep 2; echo line 3. The test checks that an in_progress update carries line 1\n… before line 3 is printed, that every running text is a prefix of the final output, and that the turn ends with completed. On origin/dev source it fails (no running update has content). With the fix it passes (3/3 reruns). The subprocess harness now records the requests and notifications the agent sends (received()).
  • Also ran the issue's repro.sh, with the mock model and an isolated HOME/XDG, against this branch's CLI. Before: pending, in_progress (no content) ×2, then completed 5s later. After: in_progress with line 1, then line 1\nline 2, and so on, once per second, then completed.
  • bun typecheck in packages/cli. These ACP suites pass: prompt, translate, turn, permission, replay, session, compaction, elicitation, plus the subprocess tests.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none">
  <style>
    .l { fill: currentColor; opacity: .55 }
    @media (prefers-reduced-motion: no-preference) {
      .a { animation: show 4s infinite }
      .b { animation: show2 4s infinite }
      .c { animation: show3 4s infinite }
      .d { animation: done 4s infinite }
      .s { animation: spin 1s linear infinite; transform-origin: 26px 14px }
    }
    @keyframes show { 0%, 8% { opacity: 0 } 14%, 100% { opacity: .55 } }
    @keyframes show2 { 0%, 33% { opacity: 0 } 39%, 100% { opacity: .55 } }
    @keyframes show3 { 0%, 58% { opacity: 0 } 64%, 100% { opacity: .55 } }
    @keyframes done { 0%, 78% { opacity: 0 } 84%, 96% { opacity: 1 } 100% { opacity: 0 } }
    @keyframes spin { to { transform: rotate(360deg) } }
  </style>
  <rect x="8" y="4" width="224" height="64" rx="8" stroke="currentColor" stroke-opacity=".3"/>
  <circle class="s" cx="26" cy="14" r="5" stroke="currentColor" stroke-opacity=".7" stroke-width="2" stroke-dasharray="20 12"/>
  <rect x="38" y="11" width="92" height="6" rx="3" fill="currentColor" opacity=".8"/>
  <path class="d" d="M196 14l4 4 8-8" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  <rect class="l a" x="20" y="28" width="64" height="5" rx="2.5"/>
  <rect class="l b" x="20" y="40" width="96" height="5" rx="2.5"/>
  <rect class="l c" x="20" y="52" width="80" height="5" rx="2.5"/>
</svg>

Closes #62173

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

I reproduced the bug on the base and confirmed this fixes it. I ran the script from #62173 against each checkout from source, with a mock model:

  • Base: two in_progress updates with no content, then completed with all five lines about 5s later.
  • This PR: an in_progress update every second with the output so far, then a single completed update at the end.

The packages/cli ACP tests pass (102), and so does typecheck:tsc.

The ordering holds up. ShellStop goes through FiberMap.remove, which waits for the polling fiber to end, and sends can't be interrupted, so no running update can arrive after the final one. The cursor and catch-up logic matches the TUI's polling.

Public API: unchanged. ACP in_progress updates for shell tools carry content again, as they did in v1.18.

No blocking concerns.

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.

ACP: running shell output is no longer streamed on in_progress tool_call_update (regression from v1.18)

1 participant