Repository navigation
Conversation
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.
This was referenced Dec 1, 2026
Open
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.errorhandler (closeForAgentStdin) setexited = trueand rejected pending requests with onlystdin closed (EPIPE): write EPIPE. The childexithandler, which adds the stderr tail, then sawexitedand returned. The error lost the line that named the cause, for example/bin/sh: --dangerously-skip-permissions: invalid option.readlinelineevents. 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
closeForAgentStdinrejects 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, becauseexitedis set first.StringDecoderand an own split on\r\n,\rand\n, the same separators as readline. A\rat the end of a chunk stays in the buffer, so a\r\nsplit 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.onExittail, after the agent's lines, not intostderrChunks. Without this, it would appear in the user's error on Windows, where an already exited child givestreeTermination: "unverified".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.
reports the agent's stderr when it exits before reading stdin(stderr with no newline)got 'ACP agent "/usr/bin/node" stdin close…'keeps a last stderr line without a newline while a descendant holds stderr openwarn: onekeeps only the end of a very long stderr line that has no newline(100,000 characters)keeps the stderr tail bounded when the agent redraws a line with carriage returns(500\rredraws)/bin/sh --dangerously-skip-permissions -c 'exec agy acp "$@"' agythroughcreateAcpAgentConnection+requestAcpInitializeACP agent "/bin/sh" stdin closed (EPIPE): write EPIPEACP agent "/bin/sh" stdin closed (EPIPE): write EPIPE: /bin/sh: --dangerously-skip-permissions: invalid optionpnpm 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.pgrep).exitbefore 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