Repository navigation
shell: a reader that stops early no longer fails a piped command - #2189
Merged
Merged
Conversation
Every bash door now runs under shell.PipefailArgs: pipefail stays on, and an EXIT trap reads PIPESTATUS of the last pipeline. A non-final stage that died of SIGPIPE (141) counts as success when the last stage succeeded, so `git log | head` exits 0 while `false | tail` still exits 1. An ERR-trap mark limits the easing to a pipeline whose status ended a list, so `yes | head -1 && false` keeps today's 141. errexit, explicit exits, subshells, functions, and a command's own EXIT or ERR trap keep today's status. sh and commands without a pipe run as written. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
santoshkumarradha
marked this pull request as ready for review
November 2, 2026 13:35
santoshkumarradha
added a commit
that referenced
this pull request
Nov 2, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
santoshkumarradha
added a commit
that referenced
this pull request
Nov 2, 2026
* shell: a reader that stops early no longer fails a piped command Every bash door now runs under shell.PipefailArgs: pipefail stays on, and an EXIT trap reads PIPESTATUS of the last pipeline. A non-final stage that died of SIGPIPE (141) counts as success when the last stage succeeded, so `git log | head` exits 0 while `false | tail` still exits 1. An ERR-trap mark limits the easing to a pipeline whose status ended a list, so `yes | head -1 && false` keeps today's 141. errexit, explicit exits, subshells, functions, and a command's own EXIT or ERR trap keep today's status. sh and commands without a pipe run as written. Co-Authored-By: Claude Opus 5.5 <[email protected]> * shell: plain-case comments for the early-reader exception Co-Authored-By: Claude Opus 5.5 <[email protected]> * changes: entry for the early-reader fix (#2189) Co-Authored-By: Claude Opus 5.5 <[email protected]> * session: watch ticks and automation commands run under pipefail jobShell now takes the command and returns the full argument list from shell.PipefailArgs, so a failing stage of a pipe fails a watch tick or an automation command, as it does at every other bash door. A reader that stops early (head) still succeeds, and sh gets the command unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * changes: entry for the job-shell pipefail fix (#2191) Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Behaviour
Since every bash door started running with
-o pipefail, a piped command whose reader stops early reported failure. For example, ingit log | headthe writer dies of SIGPIPE and the command reported status 141. Now such a command succeeds when its last stage succeeded and every earlier failing stage ended with 141. Any other failing stage still fails the command.shell.PipefailArgs, builds the arguments for every bash door: the foreground shell (internal/exec/tools.go), background jobs and services (detachedCommandininternal/exec/services.go, used byjobs.go), and the bare tool and streaming shell (internal/exec/bare).PIPESTATUSof the last pipeline and recalculates the pipefail result, counting a non-final 141 as success.yes | head -1 && falsethe 141 skipped thefalseand the command still exits 141. If the pipeline had counted as a success, thefalsewould have run, so 0 would be a false answer.set -e; after an explicitexit; for a subshell or a function; and when the command sets its own EXIT or ERR trap. In those cases the command's own trap runs as before. Every return in the check names its status, so a command's own ERR trap does not fire a second time.|runs exactly as written. Theshprogram gets no pipefail and no prefix, as before.Evidence
Red on base
app/v3(the new tests copied onto the base tree):TestBashBeltTruncationWritesHeadTailAndPath,TestBashBeltTruncationCapFollowsTheWindow(internal/session): FAILTestForegroundShellForgivesOnlyAnEarlyReader,TestBackgroundJobForgivesOnlyAnEarlyReader,TestDetachedCommandForgivesOnlyAnEarlyReader(internal/exec): FAILTestAnEarlyReaderIsNotAFailureButEveryOtherStageIs(internal/exec/bare): FAILGreen on this branch:
go vet ./internal/shell/ ./internal/exec/... ./internal/session/: EXIT=0gofmt -l internal cmd: empty, EXIT=0go test ./internal/shell/: EXIT=0.TestPipefailForgivesOnlyAReaderThatStoppedEarlycovers these cases:yes x | head -1gives 0,false | tail -20gives 1,false | yes | head -1gives 1,yes x | head -1 | falsegives 1,yes x | head -1 && falsegives 141, a usertrap ... EXITstill runs, a user ERR trap fires once, andset -e/set -u/set -xbehave as before.TestPipefailLeavesShAndPipeFreeCommandsAsWrittencoversshand commands with no pipe.go test ./internal/exec/...: EXIT=0go test ./internal/session/ -run 'Belt|Bash': both bash belt tests now PASS. The run still exits 1 because ofTestUserBashChangesReachTheTurnEndSnapshot, which also fails on base (that build has no seal engine).go test ./internal/session/: EXIT=1. Every failure also fails on base: two prefix budgets, the stage verbs budget, ProgramHold, two NoRoad tests, and the three sealed-tree tests that need a seal engine.make test-laws BASE=origin/app/v3: EXIT=2. Every failure also fails on base:TestSourceComments(it flags files this PR does not touch),TestOnlyTheTaxonomyTurnsAStatusIntoAMove, and two NoRoad tests.make changelog-check BASE=origin/app/v3: EXIT=0Limits
&&or||list, and an earlier pipeline in the same command failed with exactly the same statuses at the end of a list. Then the stale mark matches and the result is eased to 0 (for exampleyes | head -1; yes | head -1 && false). This needs the same statuses twice and is rare.$?after the pipeline still reads 141. Only the command's final exit status changes.__codeaf_prefix.🤖 Generated with Claude Code