Repository navigation
fix(shell): run piped commands as a pipeline on macOS and Linux - #4019
kovtcharov wants to merge 1 commit into
Conversation
Approve with suggestionsThis fixes a genuinely bad bug: on macOS and Linux every piped command was being run as one concatenated command, so the model got wrong output labelled Three small things worth folding in before merge, none blocking:
Worth calling out that the test that should have caught the original bug only checked a flag, not the behaviour — this PR fixes that too, which is the more valuable half of the change. Real-world evidenceNo That confirms the core claims of the PR — chaining, pipefail, SIGPIPE, and timeout cleanup all behave as described. It does not cover the tool wrapper end to end, the Windows 🔍 Technical details🟢 Minor1. Partial stdout is dropped on timeout (
2. A missing binary in stage 2+ raises 3. No universal-newline translation in the pipeline path (
Same command, different output depending on whether it was piped. Verified, not flagged
Strengths
|
On macOS and Linux every piped shell command returned wrong output with status "success". The validator drops the `|` tokens and the executor then ran the segments as one argv, so `cat notes.txt | sort` ran as `cat notes.txt sort` and `grep a x.txt | wc -l` returned "x.txt" instead of a count. Windows was unaffected because it goes through cmd.exe. Validated segments are now chained as separate processes, still without a shell. The exit code is the rightmost failing stage, so `pytest | tail` cannot turn a failing suite into a verified pass; an upstream stage killed by SIGPIPE (`| head`) is not a failure. Every stage's stderr is kept, and a timeout kills the whole pipeline. test_a_pipeline_is_not_run_as_argv only pinned the shell flag, so it passed while the bug was live; it now checks that the stages are chained.
b9d4d92 to
b6780b9
Compare
|
Rebased onto current main. First in the shell stack, nothing to merge before it; #4020 builds on this. |
|
Everything in this PR is already on It landed as part of #4049, which squash-merged the tip of the stack this branch sits in and carried every commit below it along. GitHub does not auto-close the lower PRs in a stack when the tip is squashed, which is why this stayed open — and why it has been showing a conflict against a Closing as superseded. No work is lost; reopen if you disagree. 🔍 Technical detailsVerified rather than assumed — merged Residual: empty. The merge produces a tree identical to |
On macOS and Linux every piped shell command returned wrong output with status "success".
grep a x.txt | wc -lreturnedx.txt, andcat x.txt | sortcame back unsorted. Pipes now run as real pipelines, still without a shell, so the model gets the output it asked for. A failing stage is never hidden behind a later one, sopytest | tailcan't turn a failing suite into a verified pass.Fixes #4018.
Test plan
python -m pytest tests/unit/test_shell_pipelines.py tests/unit/test_skill_binary_grants.pypasses. On main, 4 of the 7 new pipeline tests fail.cat notes.txt | grep apple | wc -lin the shell tool returns a count on macOS/Linux.🔍 Technical details
Popen. Each stage's stderr goes to a temp file, so a chatty upstream can't deadlock the pipeline.| headends a pipeline.test_a_pipeline_is_not_run_as_argvonly asserted theshellflag, which is why it passed while the bug was live. It now asserts the stages are chained.