Skip to content

Show the ACP agent's full stderr when it exits - #8504

Open
lanjak wants to merge 2 commits into
get-bb:mainfrom
lanjak:fix-acp-startup-exit-stderr
Open

lanjak wants to merge 2 commits into
get-bb:mainfrom
lanjak:fix-acp-startup-exit-stderr

Conversation

@lanjak

@lanjak lanjak commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

Two defects removed the agent's stderr from the error that bb shows when an ACP agent exits. Both are in packages/provider-bridge-acp/src/bridge/agent-connection.ts.

  1. EPIPE path (ACP agent that exits at start shows only "stdin closed (EPIPE)", not its stderr #8503). When the agent exits before bb writes its first request, the write to its stdin fails with EPIPE. The stdin error handler (closeForAgentStdin) set exited = true and rejected pending requests with only stdin closed (EPIPE): write EPIPE. The child exit handler, which adds the stderr tail, then saw exited and returned. The error lost the line that named the cause, for example /bin/sh: --dangerously-skip-permissions: invalid option.
  2. Unfinished last line (ACP agent stderr tail drops a last line without a newline while a descendant holds stderr #8508). The tail came from readline line events. readline gives an unfinished last line only when stderr ends. When a descendant of the agent held stderr open, the error was built before that, so the last line, often the fatal error, was lost.

What changed

  • closeForAgentStdin rejects pending requests after the agent stops (stopAgent(0), which already ran there) and adds the stderr tail in the same : <tail> form as the exit path. New requests in that window still fail at once, because exited is set first.
  • stderr is read with a StringDecoder and an own split on \r\n, \r and \n, the same separators as readline. A \r at the end of a chunk stays in the buffer, so a \r\n split across chunks gives one line. The unfinished line is added to the tail on both exit paths. It keeps only its last 4,096 characters, so each chunk costs time in proportion to its own size (50 MB with no line ending: 11 ms; an uncapped buffer took about 10 s in review). The 40-line cap is unchanged.
  • The note "descendant cleanup could not be confirmed" goes only to the onExit tail, after the agent's lines, not into stderrChunks. Without this, it would appear in the user's error on Windows, where an already exited child gives treeTermination: "unverified".
  • No wire change. The error text is the only visible change.

Docs: no doc quotes this error or describes the stderr tail (rg -n "stdin closed" docs packages/templates plugins/*/skills).

How you verified

Base: e0c49e2.

Test or check main this branch
reports the agent's stderr when it exits before reading stdin (stderr with no newline) fails: got 'ACP agent "/usr/bin/node" stdin close…' passes
keeps a last stderr line without a newline while a descendant holds stderr open fails: tail ends at warn: one passes
keeps only the end of a very long stderr line that has no newline (100,000 characters) fails: full line in the tail passes
keeps the stderr tail bounded when the agent redraws a line with carriage returns (500 \r redraws) passes passes
Real /bin/sh --dangerously-skip-permissions -c 'exec agy acp "$@"' agy through createAcpAgentConnection + requestAcpInitialize ACP agent "/bin/sh" stdin closed (EPIPE): write EPIPE ACP agent "/bin/sh" stdin closed (EPIPE): write EPIPE: /bin/sh: --dangerously-skip-permissions: invalid option
  • pnpm exec turbo run test typecheck lint --filter=@bb/provider-bridge-acp: 648 passed, 4 skipped; typecheck and lint clean. Full package suite 5 of 5 runs green.
  • node packages/plugin-sdk/scripts/check-npm-version-guard.mjs: PASS (0.6.215 is not on npm yet), so no SDK version bump.
  • After the tests, no descendant process is left (pgrep).
  • Not covered: Node can emit exit before it has read stderr that the agent already wrote. That race is older and separate.

This PR replaces #8509, which had the second fix on its own branch.

Fixes #8503
Fixes #8508

AGENT GENERATED

When an ACP agent exited before its first request, the stdin EPIPE handler
rejected pending requests with only "stdin closed (EPIPE): write EPIPE"
and marked the connection exited, so the exit handler that adds the stderr
tail did nothing. The stdin handler now rejects after the agent stops and
adds the stderr tail.
readline gives a line without a newline only when stderr ends. When a
descendant of the agent still held stderr open at exit, the last line,
often the fatal error, was missing from the exit error and the onExit tail.
Read stderr with an own line buffer and add the unfinished line to the
tail.
@lanjak lanjak changed the title Show the ACP agent's stderr when it exits before bb writes to it Show the ACP agent's full stderr when it exits Dec 2, 2026

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

1 participant