Skip to content

fix(middleware): surface stderr when CLI exits with error (#374)#379

Merged
alexey-pelykh merged 1 commit intomainfrom
fix/374-surface-cli-stderr
Mar 7, 2026
Merged

fix(middleware): surface stderr when CLI exits with error (#374)#379
alexey-pelykh merged 1 commit intomainfrom
fix/374-surface-cli-stderr

Conversation

@alexey-pelykh
Copy link
Copy Markdown

Summary

  • When a CLI agent runtime exits with a non-zero exit code (or zero with no NDJSON output) and stderr has content, the runtime now emits a CLI_STDERR error event with the stderr message
  • Adds stderr optional field to AgentRunResult so captured stderr is available for logging/diagnostics downstream
  • Previously, stderr was captured into stderrChunks but never used — messages sent via channels would silently "disappear" with no error

Closes #374

Test plan

  • Existing test updated: stderr on success exit with output still produces no error event
  • New test: stderr included in done result when present
  • New test: non-zero exit + stderr → emits CLI_STDERR error event
  • New test: zero exit + no NDJSON output + stderr → emits CLI_STDERR error event
  • New test: non-zero exit without stderr → no CLI_STDERR event
  • Full test suite passes (868 tests across 93 files)
  • Type-check, lint, format all clean

🤖 Generated with Claude Code

When a CLI agent runtime exits with a non-zero exit code (or exits with
zero but produces no NDJSON output) and stderr contains content, the
runtime now emits a CLI_STDERR error event with the stderr content.
The captured stderr is also included in the done event result via a new
`stderr` field on AgentRunResult, making it available for logging and
diagnostics downstream.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alexey-pelykh alexey-pelykh enabled auto-merge (squash) March 7, 2026 22:37
@alexey-pelykh alexey-pelykh merged commit 1de6519 into main Mar 7, 2026
5 checks passed
@alexey-pelykh alexey-pelykh deleted the fix/374-surface-cli-stderr branch March 7, 2026 22:44
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.

fix(middleware): CLIRuntimeBase silently discards stderr when CLI exits with error

1 participant