Skip to content

fix: send both streams through a group redirect and capture $(eval …) - #206

Merged
ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix/group-redirect-and-eval-capture
Nov 9, 2026
Merged

ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix/group-redirect-and-eval-capture

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A redirect on a { …; } group only ever handled stdout going to a file. Anything else lost output: { echo hi; } 2>&1 printed nothing, { echo hi; } 2>/dev/null swallowed the hi too, x=$({ cd /nope; } 2>&1) came back empty, and { ls /nope; } > f dropped the error on the terminal. Separately, $(eval …), $(. file) and $(command …) expanded to nothing, because command substitution skipped the path that runs those builtins. Claude Code's per-command wrapper leans on both of these.

Now a group's stdout and stderr each end up where the redirects say, applied in order like bash, so 2>&1 >f sends stderr to the terminal and stdout to the file. Command substitution runs a pipeline the same way a direct command does, so those builtins produce output, and exit inside $(eval …) stops the substitution. Same limit as before for groups: the output is collected and written when the group finishes, so stdout and stderr don't interleave.

Evidence of how this is fixed in Box

Strands Box carries a vendored copy of Shell that already does both: it routes a group's two streams by its redirects and runs a captured pipeline through the builtin dispatch (UPSTREAM.md note). I left out its extra buffer that also diverts the shell's own diagnostics during a redirected group: I couldn't find a case here where it changes anything, so I can add it later if it turns out to matter.

Related Issues

None.

Documentation PR

None.

Type of Change

Bug fix

Testing

I checked each case against bash on Linux and added tests for them, including one through the CLI, since the terminal path behaves differently from the captured one. On main, all but one of the new tests fail; the remaining one passes on main through the library and only fails on the terminal, which the CLI test covers. The full Rust suite passes, and fmt and clippy are clean with no new warnings. I didn't run the Python or Node suites locally since neither binding changed. This doesn't depend on #199, but both touch stderr handling in the executor, so whichever lands second may need a small rebase.

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

…val …)

A redirect on { …; } kept only a file target for stdout. 2>&1, 2>file and
>&2 dropped the group's output, and a group's stderr was lost on the
terminal. Each of fd 1 and fd 2 now ends at one target, decided by the
redirects in order, as bash does.

Command substitution ran a pipeline without the special-builtin dispatch,
so $(eval …), $(. file) and $(command …) expanded to nothing. A captured
pipeline now takes the same dispatch as a direct one.
@ferdingler
ferdingler enabled auto-merge (squash) November 8, 2026 21:16
@ferdingler
ferdingler disabled auto-merge November 9, 2026 22:43
@ferdingler
ferdingler merged commit dcd9618 into strands-agents:main Nov 9, 2026
30 checks passed
@ferdingler
ferdingler deleted the fix/group-redirect-and-eval-capture branch November 9, 2026 23:48
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