Skip to content

fix: run command, eval, and similar builtins as pipeline stages - #357

Merged
ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix/323-command-in-pipeline
Nov 24, 2026
Merged

ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix/323-command-in-pipeline

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

When command, eval, exec, source/., exit, return, break or continue ran in a pipeline with more than one stage, the shell didn't recognise them and reported "command not found". So echo hi | command grep -c hi failed, and so did command echo x | cat. That breaks Claude Code's grep and find wrappers when they fall back to command grep. In an embedder with a command fallback it was worse: the shell handed the fallback a program literally named command, so a policy that refused the real program was never asked about it.

Now those stages run the same way they do when they're alone on the line, in the stage's own subshell, and the kernel and the fallback are asked about the program that command actually runs. Nothing changes for single-command lines.

Related Issues

Part of #323

Documentation PR

None.

Type of Change

Bug fix

Testing

I added a differential case for these builtins in pipelines and two tests that check what the fallback is asked about. On main all three failed. With the change they pass, and so does the full test suite.

This doesn't cover exec -a or typeset from the same issue, which stay open there.

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

@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@github-actions github-actions Bot added the bug Something isn't working label Nov 21, 2026

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested. The pipeline fix works, but it also changes single-command lines: forms that failed with 127 on main now run in a discarded subshell and return 0.

  • 🔴 run() { "$@"; }; run source ./env.sh, command eval 'x=1' and command exit 3 silently do nothing. Applying the three new checks only when len > 1 restores main's behaviour and keeps the new tests green.
  • 🟡 A command NAME stage buffers its output: over 1 MiB it emits nothing, and non-UTF-8 bytes are replaced.
  • 🟡 With a function named like one of these builtins, the builtin runs with the wrong positional parameters (one-line fix).
  • 🟡 Two mutations of the new code pass every suite; two more case lines catch them.

The policy side holds: with a refusing kernel or fallback, no refused program ran through a command, eval, exec or . stage in about 175 scripts, and each program was checked once.

What I verified, appendix

Reviewed d15f3aa against dbb6189, on aarch64 Linux, debug builds. bash is 5.2.15.

Verified

  • cargo test --workspace --all-targets on d15f3aa: exit 0, 2735 passed, 0 failed, 0 ignored. cargo fmt --check: exit 0. cargo clippy --workspace --all-targets: exit 0, no warnings on added lines.
  • The three new tests fail on main. With the PR's test files copied onto dbb6189, command_check is 31 passed, 2 failed, and differential fails only on executor_builtins_in_pipeline.
  • executor_builtins_in_pipeline.expected equals bash's output for the .sh.
  • Env prefixes, redirects and heredocs on such a stage match bash, and so does the Claude Code wrapper shape from #323 (grep() { command grep "$@"; }; echo hi | grep -c hi).
  • Nothing leaks to the parent shell from exit, eval 'x=1', cd, export, ., break 2 in a stage. Already-expanded words are not expanded again.
  • Recursion through eval and . stages stops at "maximum recursion depth exceeded" without aborting.
  • 12 literal single-command forms and the 124 differential cases on main give identical output on both revisions.

Not tested: Python, Node and WASM bindings; platforms other than Linux.

Reading order: src/exec.rs 3834, 3877, 4208-4224, then 4289-4315.

Appendix, non-blocking (4)

  • echo | break and echo | continue leave $? at the previous status; bash gives 0. false; for i in 1; do echo | break; echo "st=$?"; done prints st=1 (Err(_) => state_proc.last_exit, src/exec.rs:4311).
  • set -x; echo hi | eval cat prints + eval cat twice; bash prints it once. run_pipeline traces the stage and the eval arm traces it again.
  • Pre-existing, not filed: a function stage on main also drops all of its output over 1 MiB (f() { cat; }; cat a a a | f | wc -c prints 0). It is the mechanism behind the second finding. I can open an issue if you want one.
  • Pre-existing: echo hi | builtin eval cat fails with "not a shell builtin" on both revisions.

Comment thread src/exec.rs Resolved
Comment thread src/exec.rs Resolved
Comment thread src/exec.rs Resolved
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@strandly-the-agent strandly-the-agent left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at d10dd81. All four findings from my last review are fixed; I re-ran each repro against this commit.

Finding Status
🔴 Single-command lines ran in a discarded subshell Fixed. The five scripts print what main prints.
🟡 command NAME stage buffered its output Fixed. 1.2 MB and 5 MB pass through intact, bytes are kept, and a refusal stops the pipeline before any stage runs.
🟡 Function named like one of these builtins Fixed. The function runs, as on main and in bash.
🟡 Unpinned behaviours Fixed, with one follow-on from the unwrap (inline).

Two things remain, neither blocking:

  • 🟡 Two parts of the new code are not pinned by a test; two case lines cover them (inline).
  • Nested forms still hand the fallback the wrapper word, as on main. With tool refused, echo | exec command tool a asks the fallback about command and calls it, and so do the single lines command command tool a and x=command; $x tool a. Having the command and exec arms re-enter execute_pipeline_checked would close these; a follow-up is fine.

I filed #382 for the function-stage buffering, as you asked.

What I verified, appendix

Reviewed d10dd81 against d15f3aa (previous review) and dbb6189 (main), on aarch64 Linux, debug builds. bash is 5.2.15.

Verified

  • cargo test --workspace --all-targets on d10dd81: exit 0, 2738 passed, 0 failed, 0 ignored. cargo fmt --check: exit 0. cargo clippy --workspace --all-targets: exit 0.
  • The new tests fail on d15f3aa. With this commit's tests/ on d15f3aa's src/: a_refused_command_stage_stops_the_pipeline_before_any_stage_runs fails, differential fails on command_stage_streams and executor_builtins_in_pipeline, and both ..._does_not_silently_discard_its_effect tests fail.
  • Both case files' .expected equal bash's output.
  • Probes on the unwrap, 14 groups. 11 match bash, apart from the shell's name in error messages: command command cat, command eval/exit/. in a stage, command read/cd/export, a name from an expansion, empty and missing names, a function NAME after command, env prefixes and redirects, statuses with pipefail and !, three-stage pipelines with $(...) and background, skipping the function only in the stage that says command, and command sh -c.
  • The other 3 differ from bash. command -v cat prints cat where bash prints a path, and command -V eval is worded differently. set -x; echo hi | command cat prints the two stages' trace lines in the other order. Both are the same on d15f3aa apart from its extra + cat trace line. The third is the function named command, in the appendix.
  • Policy: I re-ran the 176 embedder scripts from the first review. In none did a refused program run or finish under its own name. 93 scripts differ from d15f3aa:
    • 42 are refusals that now stop the pipeline up front: the other stages get command_dropped or are never checked.
    • 31 single-command forms give main's result again.
    • 14 change only the order of the check events.
    • 2 cancelled command sleep stages now get command_dropped; on d15f3aa they got neither notification.
    • 1 failed redirect now checks the command stage before failing.
    • 3 are the nested forms above (echo | exec command tool a, echo | exec exec tool a, echo | eval exec command tool a), which d15f3aa refused. On main the fallback was asked about exec or eval for these.

Not tested: Python, Node and WASM bindings; platforms other than Linux.

Appendix, non-blocking (1)

  • With a function named command, command() { echo fn "$@"; }; echo hi | command cat prints hi; main and bash print fn cat. The word is dropped before the function lookup. A single-command line already runs the builtin on main.

@ferdingler
ferdingler merged commit a8cb898 into strands-agents:main Nov 24, 2026
38 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants