Skip to content

fix: keep output writers that the caller installs - #203

Merged
ferdingler merged 3 commits into
strands-agents:mainfrom
ferdingler:fix/keep-caller-output-writers
Nov 9, 2026
Merged

ferdingler merged 3 commits into
strands-agents:mainfrom
ferdingler:fix/keep-caller-output-writers

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Description

If you install your own channel writers on the shell's stdout and stderr to get output as it's produced, they never see a byte. A builtin like echo, a command like ls /nope, or a pipeline like echo a | cat each swap in their own pipes, so everything lands in the captured result instead. For an embedder that streams output through those writers, that means losing all output, not just the streaming.

Now the caller's writers are kept. A single builtin writes to them directly, a pipeline's last stage writes its stdout there, and every stage writes its stderr there. If a builtin's redirect fails, the reason goes to the caller's stderr writer too, so it isn't silently dropped. A redirect still wins over the writer, and when no writer is installed, output is captured exactly like before.

Evidence of how this is fixed in Box

Strands Box carries a vendored copy of Shell and installs these writers to stream a command's output back to the agent. Its copy keeps them for a single builtin and for pipeline stages (UPSTREAM.md note). I left out Box's per-writer output budget and its wait for pending writes, because those are separate changes.

Related Issues

None.

Documentation PR

None.

Type of Change

Bug fix

Testing

I added tests that install writers and check that builtin output, command output, pipeline output, diagnostics and non-UTF-8 bytes reach them, that a redirect still takes output away from them, and that capture is unchanged with no writer. The writer tests fail on main and pass with the change. I also removed the routing for a failed redirect, and its test caught it. The Rust suite, fmt and clippy are clean, with no new warnings. I didn't run the Python or Node suites because the bindings didn't change. This doesn't depend on #194 or #199.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

A caller can install a channel writer on the stdout or the stderr of
the shell process to receive output as it is produced. A builtin, a
command, or a pipeline replaced these writers with its own pipes, so
the writers received no bytes. The output went to the captured result
instead.

## Solution

A forked builtin keeps the caller's writers. A pipeline gives the
caller's stdout writer to its last stage and the caller's stderr writer
to every stage. When the caller installs no writer, the shell captures
output as before. When a redirect of a builtin fails, the reason goes
to the caller's stderr writer.

## Tests

Added tests in tests/shell_integration.rs. Each writer_receives_* test
installs writers and checks that the writer gets the bytes and the
captured result stays empty. redirect_takes_output_away_from_writer
checks that a redirect still wins. output_is_captured_when_no_writer_is_installed
checks that capture does not change. The new writer tests failed on
main and pass with the change. I removed the redirect-failure routing
and writer_receives_failed_redirect_reason failed. cargo test
--workspace --all-targets passes, cargo fmt --check passes, and the
clippy warning count is the same as on main. I did not run the Python
or Node suites, because the bindings did not change.
@ferdingler
ferdingler marked this pull request as ready for review November 5, 2026 05:32
@ferdingler
ferdingler requested a review from a team as a code owner November 5, 2026 05:32
@ferdingler
ferdingler enabled auto-merge (squash) November 8, 2026 21:16
@ferdingler
ferdingler disabled auto-merge November 9, 2026 22:42
@ferdingler
ferdingler merged commit eb48b96 into strands-agents:main Nov 9, 2026
30 checks passed
@ferdingler
ferdingler deleted the fix/keep-caller-output-writers branch November 9, 2026 22:42
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.

1 participant