Repository navigation
execute_command and shell_exec report a failing pipeline stage; shell results are structured - #56
Merged
Merged
Conversation
A pipeline's status was its last stage's: commands ran in /bin/sh without pipefail, so `cargo build 2>&1 | grep -E '^error' | head -60` failed to build while the tool said "Return code: 0" and "Command completed successfully". - POSIX string commands (sandboxed and unsandboxed) run in `bash --posix -o pipefail -c`, resolved and probed once per process; without bash, /bin/sh gets -o pipefail only when it honours it. --posix keeps macOS /bin/sh semantics and never sources $BASH_ENV. argv lists and Windows are unchanged. - The result carries `pipefail: true|false`; a shell without it is said in the render. - A non-zero exit reads "Command failed (exit code N)" (also with capture off), success false, full stdout/stderr kept; 141/SIGPIPE says a later stage such as head cut an earlier command off. Exit code only, the output is never scanned. - Tool description, when_to_use, docstring and the grep example teach pipefail, `|| true`, and that output is already previewed (no `| head`).
Review of 09376f7 found the taught idioms re-broke or inverted results: - `cmd | grep -q pat` inverts with a large producer (grep exits early, the producer gets SIGPIPE, pipefail fails the pipe): teach `grep pat >/dev/null`. - `cmd | grep pat || true` hides cmd's failure again: teach `cmd | { grep pat || true; }` (cmd's exit code survives, no match is 0). - A failing command's long output kept only its first 20,000 chars, losing the error printed at the end: failures keep head and tail. `tail` is no longer warned against (it never cuts a command off); `head` still is. - A shell probe that raised was cached as "no pipefail" until restart: only a probe that answered is cached. - shell_exec sessions had no pipefail: each session turns it on at start (in a subshell first, so a shell without it never errors) and measures it; the result carries `pipefail`, and the render says when it is off. - A failure with no output says "(no output)"; the signal-name path is tested.
… parity The re-gate of 5965f7c found more ways the taught idioms hid failures: - `cmd | grep pat >/dev/null && echo yes || echo no` answered "no" with rc 0 when cmd failed, and `{ grep pat || true; }` swallowed grep's own errors. Both tools now teach grouped tests: `cmd | { grep pat || [ $? -eq 1 ]; }` and `cmd | { grep pat >/dev/null && echo yes || echo no; }`. - The shell is /bin/sh -o pipefail when it supports it (each platform keeps its own sh), bash --posix only when it does not; still no $BASH_ENV. - execute_command resolves the shell once per call (argv and field agree, sandboxed path included via wrap(shell=...)); a probe killed by a signal is not cached. - The 141 sentence no longer blames a pipeline stage for a plain `exit 141`; the omitted marker gives only the count (the stdout field may be offloaded). - shell_exec: the shared verdict (command_verdict.py) adds the same failure line and head-and-tail preview (the reader now keeps a rolling tail); pipefail is re-asserted after every command and reported as unknown when the start measurement did not finish; when_to_use carries the idioms.
…hat ends The final re-gate: hosts counted every shell_exec call as a success (its text never starts with Error:/❌), and a command that ended the session shell (`exit 3`, `set -e` then `false`, a sourced script that exits) showed no failure at all. - shell_exec returns execute_command's shape: success, return_code/exit_code, pipefail, timed_out, session_ended, output_truncated, error, and the old text in `rendered`. Refusals and session errors are failure dicts too. - When the PTY closes during a command the shell is reaped and its exit status reported: "The shell session ended during this command (exit code N)". - A timeout keeps the latest output (the reader's rolling tail), like a failure. - The pipefail re-assert runs before the sentinel and reports on the sentinel line, so `exec dash` stops claiming pipefail, nothing leaks into the next output, and set -x traces cannot desync the exit code. - Omitted counts are exact (the sentinel's newline no longer counted); tests pin the counts. Unused posix_shell_argv removed; docstring wording on 141.
…ed pid Review of 497757c: - A command line left open (trailing &&, ||, | or \) skipped or swallowed the status capture, so the previous call's exit code was reported. The status line now uses no shell variable: an empty line ends a `\` continuation and `(exit $?) && :` keeps the status while absorbing a dangling operator (and a failing && list under set -e never ends the shell). `readonly`/`set -u` can no longer break it. A status line without a readable code is a failure. - _reap kills the group while the exited shell still holds the pid, waits, then forgets the pid; close() skips a forgotten pid; is_alive() that reaps keeps the status (a concurrent run() reports it) and forgets the pid too. - Pipefail is re-asserted in the resync line after a timeout (the Ctrl-C discarded the pending re-assert). - A session ended by a signal names it; `exit 0` ending the session stays a failure and says its state is lost. - Line endings are normalised once in the PTY reader, so omitted counts are on the normalised text. - shell_write_stdin returns the same kind of dict; input that ends the shell is a failure. - Docs and changelog list the actual fields of every result and refusal.
…ts fail Review of 4ec2d72: the blank line before the status line answered one-line prompts (`read -p` got "yes"), `exit() { :; }` or `alias exit=true` shadowed the `(exit $?)` absorber, and a trailing `|` swallowed the output into a success. - Adopt the reviewer's tested shape: `{ :\n<cmd>\n\n}` then a plain `printf ... "$?"`. A line left open (&&, ||, |, f(), an unclosed construct) is a syntax error at `}` and fails at once; a trailing `\` keeps its status; nothing the command defines can shadow the status line; a prompt reads only after the whole group, so it times out instead of being answered. Aliases defined in a call apply from the next call (documented). - bash runs with +H: `!` is literal ("Hello, World!", "#!/bin/sh"). - Completion is off, so a literal TAB (a heredoc Makefile) reaches the command. - ECHO/ONLCR are cleared in the child before exec, so a slow parent can no longer leave the session echoing commands and status lines. - The pipefail re-assert runs with its trace and DEBUG-trap output discarded. - is_alive() kills the group before reaping when the terminal already closed. - Docs: timeout coercion (max 600, min 1, 0/negative/non-numeric = 120) and the shell_write_stdin refusal fields.
…ecute_command and shell_exec Six commits from 2026-11-17 (09376f7..2f3a78e), merged on top of 2.40.0. Not a release: no version bump; the changelog entry stays a fragment (changelog.d/execute-command-pipefail.md). Conflicts resolved so both sides keep their behaviour: - sandbox.py, Sandbox.wrap: a sandbox that brings its own shell keeps it (Windows: the launcher's --shell, and -- before an argv list; a caller's POSIX shell is never put in front of the command there); every other sandbox runs a string command in the caller's shell, by default posix_shell() (pipefail when the host's shells have it). The _shell field is now None unless the sandbox has its own, instead of a /bin/sh default. - shell_session.py, terminal setup: ECHO/ONLCR are cleared in the child before exec through the branch's _quiet_terminal helper; the parent no longer touches the terminal after the fork (as on main since 2.40.0). - shell_session.py, _resync: main's repeated interrupts, each with a fresh marker, and a session closed when none arrives; each attempt also turns pipefail back on (the branch). Adjusted beside the conflicts: - tests/tools/test_shell_session.py: the fd-leak test waits on the shell's pid only while the session still holds one (run() now reaps a shell that ended during its command); a new test covers shell_exec after a failed resync (a failure dict, then a fresh session). - tests/tools/test_sandbox_spec.py: the Windows sandbox ignores a caller's POSIX shell. - docs/tool-calling.md and the fragment: pipefail is macOS and Linux only; a session closed after a failed resync is a refusal. llms-full.txt regenerated (scripts/update_llms.py).
…ry platform; a prompt's real behaviour documented; an interrupt that ends the shell is reported as ended
…ompt; shell_exec reports not_run; the Windows job checks the Windows text
…ractVision itself (it hardcoded 0.40.3, which AbstractVision 0.3.39 refuses first)
… session when that command has ended on its own or waits at a prompt (a no-op line precedes the sync line, which an interrupted reader no longer drops)
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.
What changes for a user
execute_commandandshell_execon macOS and Linux (cargo build 2>&1 | grep error | headused to report "Return code: 0" when the build failed). On Windows, wherecmd.exehas no such option, the tool says so.shell_execandshell_write_stdinreturn a structured result (success,error,return_code,timed_out,session_ended,not_run,rendered) instead of text.shell_write_stdinis for a REPL or a later prompt, an interrupt that ends the shell is reported as ended and the next command as not run.mainwas red against the registry since 2026-11-29).This brings in the six commits of the local branch
fix/execute-command-failures(2026-11-17), merged onto 2.40.0, plus three follow-up commits from two adversarial review rounds. The changelog entry ischangelog.d/execute-command-pipefail.md. No version bump; this is not a release.Checks
scripts/ci_local.sh abstractcore --jobs 2 --allow-skipped: every runnable job passes on this head (changelog, test 3.9-3.13, local-model tests) or on the head before the last test-only commit (build, docs, console-tui crate and MSRV). Skipped here and proven only by this pull request: the Linux command sandbox job (bubblewrap + Landlock) and the Windows command sandbox job.tests/tools/: 1917 passed. Sandbox argv compared for every sandbox kind against both parents; mutants on the merge resolution and the new code are caught.Open before a release
| headexits 141 and counts as a failed command. That is a product decision pending with the owner.