Skip to content

fix(acp): preserve stderr when an agent exits during initialization - #540

Merged
benbrandt merged 1 commit into
mainfrom
fix/acp-agent-exit-stderr-531
Dec 1, 2026
Merged

benbrandt merged 1 commit into
mainfrom
fix/acp-agent-exit-stderr-531

Conversation

@benbrandt

Copy link
Copy Markdown
Member

Fixes #531

When an agent exits before replying to initialize, its pipes can close before the SDK collects its exit status and stderr. The client then gets only Broken pipe or Incoming transport closed, even when the agent printed an explanation.

AcpAgent now keeps draining stderr and gives the child the existing one-second exit window after a failed write or a request that ends the connection at stdout EOF. A nonzero exit during that window supplies the status and stderr. A clean exit or an expired wait preserves the original transport error. Client cancellation bypasses the wait.

Subprocess tests cover both connection entry points, cancellation during that wait, and custom transport driver cleanup.

Verification

  • just test passed twice on macOS, with 1,662 passing and 67 ignored per run.
  • All 100 consecutive CLI launches of a failing agent reported exit status 2 and its stderr. A healthy agent completed prompts, and an agent that stayed alive after closing stdout returned the original EOF error in about one second.
  • Workspace Clippy passed with warnings denied. The core library also passed compile checks for aarch64-pc-windows-msvc and wasm32-unknown-unknown.

@benbrandt
benbrandt enabled auto-merge (squash) December 1, 2026 13:30
@benbrandt
benbrandt merged commit 991545a into main Dec 1, 2026
13 checks passed
@benbrandt
benbrandt deleted the fix/acp-agent-exit-stderr-531 branch December 1, 2026 13:32
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.

AcpAgent: agent stderr is lost when the agent exits before the first write (bare "Broken pipe" error)

1 participant