Repository navigation
fix: apply group redirects to stderr when a writer is installed - #245
Merged
ferdingler merged 1 commit intoNov 12, 2026
Merged
Conversation
A redirect on a `{ ...; }` group captured the group's stderr only when no
writer was installed on fd 2. With a writer, every stage inside the group
inherited it, so `{ ls /nope; } 2>/dev/null` and `>/dev/null 2>&1` still
sent the diagnostics to the writer.
While a redirected group runs, the descriptors it redirects leave the
caller's writer aside, so the group's output is captured and delivered
by its redirects. The writer comes back before delivery. An unredirected
stream keeps the writer as before.
priyasingh2111
approved these changes
Nov 12, 2026
This was referenced Nov 21, 2026
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
When an embedder installs its own stderr writer to stream live output (the setup from #203), a redirect on a
{ …; }group didn't apply to stderr.{ echo out; ls /nope; unalias missing; } >/dev/null 2>&1still sent both errors to the writer, and a group writing 300 lines to stderr under2>/dev/nulldelivered all 300. Bash prints nothing in both cases. #206 fixed group redirects for captured output, but nothing tested it with a writer installed, so this case slipped through.Now, while a redirected group runs, the streams it redirects stop going to the installed writer and follow the redirect instead. The writer is put back once the group finishes, and a group without redirects streams to it exactly as before. Small change in the executor, no API changes.
Evidence of how this is fixed in Box
Strands Box carries a vendored copy of Shell that already handles this: it diverts a redirected group's stderr away from the installed writer while the group runs (UPSTREAM.md note). Box also diverts the shell's own diagnostic channel during the group. I tried that here and couldn't find a case where it changed anything, so I left it out.
Related Issues
None.
Documentation PR
None.
Type of Change
Bug fix
Testing
I added tests with writers installed for both cases above, for stderr to a file, for
2>&1 >file, and for a group with no redirect. On main, the four redirect tests fail. The no-redirect one passes on main too, and it's there to check that nothing changes when there's no redirect. I also compared a range of group shapes with and without writers, and after the fix they now agree. The #206 tests still pass, as does the full Rust suite, and fmt and clippy show no new warnings. I didn't run the Python or Node suites since neither binding changed.One thing I noticed and left alone:
{ …; } 1>&2with a writer installed sends the group's output to captured stderr instead of the stderr writer. That's a separate delivery problem, and it was already there before this change.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.