Skip to content

Keep the last ACP agent stderr line when it has no newline - #8509

Closed
lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:fix-acp-stderr-partial-line
Closed

lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:fix-acp-stderr-partial-line

Conversation

@lanjak

@lanjak lanjak commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

The ACP agent stderr 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 exit handler built the error before that, so the last line was lost. That line is often the fatal error.

What changed

  • packages/provider-bridge-acp/src/bridge/agent-connection.ts: read stderr 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 in the exit path and in the stdin-closed path. The 40-line cap is unchanged, and a big chunk pushes only its last 40 lines. The unfinished line 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), and a huge line does not go into the error message.
  • The note "descendant cleanup could not be confirmed" still goes into stderrChunks, so in onExit it can come before the unfinished line. Show the ACP agent's full stderr when it exits #8504 moves that note out of stderrChunks; with both merged, the order is right.
  • No wire change, no new wait or timeout.

Docs: no doc describes the stderr tail.

How you verified

Base: e0c49e2.

Test main this branch
keeps a last stderr line without a newline while a descendant holds stderr open fails: tail ends at warn: one passes, 20 of 20 runs
keeps the stderr tail bounded when the agent redraws a line with carriage returns (500 \r redraws) passes 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
  • pnpm exec turbo run test typecheck lint --filter=@bb/provider-bridge-acp: 647 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.
  • Not covered: Node can emit exit before it has read stderr that the agent already wrote. That race is separate and older.
  • After the test, no descendant process is left (pgrep).

Fixes #8508

AGENT GENERATED

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 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing: this fix is now in #8504, together with the #8503 fix. Both change the same function in agent-connection.ts, so one PR avoids a rebase conflict. #8504 fixes #8508.

@lanjak lanjak closed this Dec 2, 2026
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 agent stderr tail drops a last line without a newline while a descendant holds stderr

1 participant