Repository navigation
fix: keep output writers that the caller installs - #203
Merged
ferdingler merged 3 commits intoNov 9, 2026
Merged
Conversation
## 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
marked this pull request as ready for review
November 5, 2026 05:32
ferdingler
enabled auto-merge (squash)
November 8, 2026 21:16
ferdingler
disabled auto-merge
November 9, 2026 22:42
10 tasks done
3 tasks done
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.
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 likels /nope, or a pipeline likeecho a | cateach 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.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.