Skip to content

fix: apply group redirects to stderr when a writer is installed - #245

Merged
ferdingler merged 1 commit into
strands-agents:mainfrom
ferdingler:fix/group-redirect-channel-writer
Nov 12, 2026
Merged

ferdingler merged 1 commit into
strands-agents:mainfrom
ferdingler:fix/group-redirect-channel-writer

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

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>&1 still sent both errors to the writer, and a group writing 300 lines to stderr under 2>/dev/null delivered 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>&2 with 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.

  • 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.

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.
@ferdingler
ferdingler requested a review from a team as a code owner November 11, 2026 21:52
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.

2 participants