Repository navigation
fix(scripts): a failing command in a pipeline must not read as success - #3736
Merged
Merged
Conversation
Without `pipefail` a pipeline's exit status is its LAST command's, so
`cargo build … | tail -12` reports tail's success while cargo failed. That
cost an evening: a rebuild was reported green by its own harness, the binary
was never produced, and the node ran a stale core hosting zero citizens for
hours while I read the "[exited with code 0]" and believed it.
`set -e` does NOT cover this. Every one of these scripts could carry `set -e`
at the top and still swallow the exit code of the command that mattered, which
is exactly what makes it survive review: the script LOOKS defended.
THE CONCRETE DEFECT, in the gate nobody is allowed to bypass —
git-prepush.sh counted ESLint errors by grepping the linter's merged output:
CURRENT=$(… npx eslint … 2>&1 | grep -cE "error\s+" || true)
if [ "$CURRENT" -le "$BASELINE" ]; then → "✅ ESLint: $CURRENT errors"
A linter that CRASHED (missing module, bad config, wrong cwd) writes
diagnostics the regex does not match — "Error: Cannot find module" has a
capital E and no trailing whitespace class — so the count is 0, `0 -le
BASELINE` holds, and a push sails through under a green checkmark. Measured:
printf 'Error: Cannot find module\n' | grep -cE "error\s+" → 0
`|| true` guaranteed the pipeline could not fail on its own, independently of
pipefail. So the fix here is not the flag: it checks eslint's EXIT STATUS
(0 = clean, 1 = found errors, ≥2 = the linter itself failed) and refuses
loudly on ≥2 rather than reporting a silent zero.
`|| LINT_RC=$?` on that call is load-bearing, not defensive noise: `set -e`
aborts on a failing command substitution and eslint exits 1 for the ORDINARY
"found lint errors" case, so without it the script would die on the exact path
it exists to report. The old `|| true` was doing that job too — it just
discarded the code we now need.
PROVEN BY EXECUTION, not by reading (three cases against a stubbed eslint):
clean (exit 0) → PASS, 0 errors
lint (exit 1) → PASS, 2 errors counted, script survives set -e
crash (exit 2) → REFUSED, FAILED=1
and the OLD code on that same crash → CURRENT=0 → green checkmark.
SCOPE, deliberately NOT `-euo`. `-u` (nounset) makes a bare reference to an
unset variable fatal, and start-server.sh alone carries 193 bare references
against 11 guarded ones by design — optional per-host env vars are how it
adapts to each machine. Turning nounset on there is a behaviour change to the
deploy path, testable on no box I have, whose failure mode is an install that
dies instantly on hardware nobody can reproduce. That is a worse outcome than
the hole being closed, and it would land hardest on the tier least able to
recover. `-u` is a per-file audit with its own ratchet, not a bundled flag.
21 scripts gained `set -o pipefail`; all 40 verified to still parse.
The ratchet counts scripts that pipe into tail/head/grep/tee/awk/sed without
pipefail, and is baselined at ZERO. Its CI job also runs a MUTATION step:
strip pipefail from start-server.sh and assert the gate goes red, then
restore. A ratchet that cannot be shown to fail is decoration — and this one
was written by someone who, while testing it, read `exit=0` from
`check-pipefail.sh | tail -6` and briefly believed a red gate was green. The
bug caught its own author mid-fix; the mutation step exists because of that.
Both workflow triggers carry the same paths filter, per the comment on
ts-persona-forbidden-strings-ratchet.yml where a missing filter on `push`
produced 100/100 red and taught everyone to ignore the X.
Card aad30dee.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
… editing it The first revision of this PR patched `tools/scripts/generated/manifest.linux.sh`, a file stamped "GENERATED FILE - DO NOT EDIT" and rendered from `install-manifest.toml` by `tools/manifest-gen`. CI's install-manifest projection drift detector failed it, correctly. That is the whole lesson of this PR pointed back at its author: I mechanically swept every *.sh for a missing flag and swept a mechanical projection along with the sources, producing a green hygiene gate and a red drift gate on the same commit. A generated script must inherit pipefail from its GENERATOR, not from someone editing its output — making it pass the lint by hand would be defeating the source of truth to satisfy the lint. Generated output is now excluded from the ratchet, with the reason recorded at the exclusion so the next person does not "fix" it. Emitting `set -o pipefail` from manifest-gen is the follow-up on card aad30dee. Re-verified after the change: ratchet green at baseline 0, mutation still turns it red (exit 1), and the generated file is byte-identical to canary. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
Contributor
Author
|
M5-core review: NO OBJECTION. Checked the one script where pipefail could change behaviour under The ratchet catching its own author ( |
joelteply
added a commit
that referenced
this pull request
Sep 5, 2026
…in a comment My own mutation step caught this, which is the first time tonight a gate I wrote failed me before a human did. The detector asked `grep -qE 'set -o +pipefail'` with no anchor, so ANY occurrence of that text counted as compliance — including a comment discussing the flag. The fix for #3736 (this PR's sibling commit) adds explanatory comments containing the words `set -o pipefail`, and with those present the mutation step stripped the REAL `set -o pipefail` line from start-server.sh and the ratchet still reported 0 offenders: ##[error]pipefail ratchet did NOT fail on a script with pipefail removed — the gate is dead. ✅ pipefail: 0 offender(s), at baseline (0). A checker that cannot distinguish "the flag is set" from "the word appears" is the exact defect this gate exists to stop, reproduced inside the gate. It is the same shape as counting a crashed linter's stderr and calling it zero errors: presence of a string standing in for the state it describes. Anchored to line start (after optional indentation) so it matches a `set` statement and never a comment. Verified by running the mutation with the comments in place: real flag stripped, one comment mention remaining, ratchet correctly exits 1 and names start-server.sh; restored, exits 0. Card aad30dee. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply
added a commit
that referenced
this pull request
Sep 5, 2026
…sets -e My sweep in #3736 was wrong, in exactly the way I argued a mechanical `-euo` sweep would be wrong two hours earlier. I won that argument about `-u` and then did the same thing with `pipefail`. In a script already running `set -e`, pipefail turns an EXPECTED-EMPTY pipeline into a fatal error. Confirmed sites, each measured rather than reasoned: start-server.sh:411 airc socket derivation — `ls` finds nothing and `grep -v` filters everything out on any machine with no airc daemon. A FRESH INSTALL. Silent exit 1. start-server.sh:255 lane-adopt port probe — `ps` fails when a pid dies mid-race, the ordinary condition the loop tolerates. git-precommit.sh:658 SCREENSHOT_SESSION=$(find …/screenshots/*.png | head -1) — aborts EVERY COMMIT on a checkout with no screenshots directory (M5's find, proven in a dry shell). Every one is followed by a guard written for the empty case. pipefail killed the script before it reached the handling that already existed. A static pass found ~28 more command substitutions containing pipes across the `set -e` scripts (git-precommit 16, download-avatar-models 8, install-livekit 6, start-server 9; 11 already guarded). Patching two of them, which is what this branch originally did, would have left the rest. So: pipefail is REVERTED from all nine scripts that already set `-e`. It stays on the ten that do not, where the flag cannot turn an empty result fatal. The two `|| true` guards in start-server.sh stay — they are correct on their own merits and cost nothing. WHAT SURVIVES, because it was never about the flag: - the git-prepush ESLint fix. A crashed linter used to yield CURRENT=0 and a green checkmark; it now checks eslint's exit status and refuses on >=2. That is the real defect from the original report and it is untouched. - the ratchet, rebaselined at the honest count of 9 rather than a swept 0. Those nine are the debt. The flag returns one script at a time, with each pipe's empty case actually EXERCISED, and the baseline drops by one. - the CI mutation step, now pointed at system-stop.sh (which still carries the flag). It has already earned itself twice: it caught the unanchored regex that let a comment mentioning "set -o pipefail" pass as compliance, and it is what keeps a rebaselined gate from quietly becoming decoration. The lesson I paid for twice tonight: a mechanical sweep of a behaviour-changing flag is not hygiene, it is a behaviour change to every file it touches — and `bash -n` cannot see it, because parsing is syntax and this is runtime. I reported "40/40 parse" and called it verified. Card aad30dee. Unblocks the fleet: canary tip is deployable again. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply
added a commit
that referenced
this pull request
Sep 5, 2026
… is normal (#3738) * fix(scripts): pipefail must not kill the deploy where an empty result is normal I merged pipefail into start-server.sh in #3736 and broke it. Two command substitutions whose pipelines FAIL on a healthy machine now abort the script, because `set -e` (line 26) plus `set -o pipefail` turns an expected-empty result into a fatal error. MEASURED, both exit 1 before this commit: 1. tools/scripts/start-server.sh:411 — the airc socket derivation X="$( ls -1t "$HOME"/.airc/runtime/airc-machine-*-v5.sock 2>/dev/null | grep -v '\.lock$' | head -1 )" `ls` fails when no socket matches; `grep -v` exits 1 when nothing survives the filter. Fires on any machine where the airc daemon is not running — A FRESH INSTALL. The deploy path exits silently, with no FATAL line, because it dies at a substitution rather than at a guarded check. 2. tools/scripts/start-server.sh:255 — the lane-adopt port probe port="$( ps -o command= -p "$pid" 2>/dev/null | sed -n '…' )" `ps` fails when the pid died between listing and probing, which is the ordinary race the adoption loop exists to tolerate. One dead lane took the whole deploy with it. In BOTH cases the very next line is `if [ -n "$X" ]` — the code was already written for the empty result. pipefail killed the script before it could reach the handling that existed. `|| true` inside each substitution keeps the failure local. This does NOT weaken the flag: it marks the two places where a failing pipeline is the expected, already-handled outcome, and every other pipe in the script keeps the new behaviour. Verified by running, not by reading — no-socket and dead-pid both survive with the guards doing their job, and a genuine `false | cat` under the same settings still exits 1. WHY I DID NOT CATCH THIS IN #3736: I ran `bash -n` on all 40 scripts and reported "all parse". Parsing is syntax; this is runtime behaviour, and `bash -n` cannot see it. I let "40/40 parse" stand in for "the deploy path still works" — the same substitution error as reading tail's exit status for cargo's, one level up. My own node was mid-build on the PRE-MERGE copy of this script, so nothing here exercised the change I had just merged. The irony is exact and worth recording: I spent the evening arguing that a mechanical `-euo` sweep would break the deploy path on hardware nobody could test, won that argument, and then broke the deploy path with the one flag I had called safe — on the fresh-install case for the low-end tier I am supposed to be defending. Card aad30dee. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE * fix(ratchet): the pipefail test must match a STATEMENT, not the word in a comment My own mutation step caught this, which is the first time tonight a gate I wrote failed me before a human did. The detector asked `grep -qE 'set -o +pipefail'` with no anchor, so ANY occurrence of that text counted as compliance — including a comment discussing the flag. The fix for #3736 (this PR's sibling commit) adds explanatory comments containing the words `set -o pipefail`, and with those present the mutation step stripped the REAL `set -o pipefail` line from start-server.sh and the ratchet still reported 0 offenders: ##[error]pipefail ratchet did NOT fail on a script with pipefail removed — the gate is dead. ✅ pipefail: 0 offender(s), at baseline (0). A checker that cannot distinguish "the flag is set" from "the word appears" is the exact defect this gate exists to stop, reproduced inside the gate. It is the same shape as counting a crashed linter's stderr and calling it zero errors: presence of a string standing in for the state it describes. Anchored to line start (after optional indentation) so it matches a `set` statement and never a comment. Verified by running the mutation with the comments in place: real flag stripped, one comment mention remaining, ratchet correctly exits 1 and names start-server.sh; restored, exits 0. Card aad30dee. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE * revert(scripts): pull pipefail back out of every script that already sets -e My sweep in #3736 was wrong, in exactly the way I argued a mechanical `-euo` sweep would be wrong two hours earlier. I won that argument about `-u` and then did the same thing with `pipefail`. In a script already running `set -e`, pipefail turns an EXPECTED-EMPTY pipeline into a fatal error. Confirmed sites, each measured rather than reasoned: start-server.sh:411 airc socket derivation — `ls` finds nothing and `grep -v` filters everything out on any machine with no airc daemon. A FRESH INSTALL. Silent exit 1. start-server.sh:255 lane-adopt port probe — `ps` fails when a pid dies mid-race, the ordinary condition the loop tolerates. git-precommit.sh:658 SCREENSHOT_SESSION=$(find …/screenshots/*.png | head -1) — aborts EVERY COMMIT on a checkout with no screenshots directory (M5's find, proven in a dry shell). Every one is followed by a guard written for the empty case. pipefail killed the script before it reached the handling that already existed. A static pass found ~28 more command substitutions containing pipes across the `set -e` scripts (git-precommit 16, download-avatar-models 8, install-livekit 6, start-server 9; 11 already guarded). Patching two of them, which is what this branch originally did, would have left the rest. So: pipefail is REVERTED from all nine scripts that already set `-e`. It stays on the ten that do not, where the flag cannot turn an empty result fatal. The two `|| true` guards in start-server.sh stay — they are correct on their own merits and cost nothing. WHAT SURVIVES, because it was never about the flag: - the git-prepush ESLint fix. A crashed linter used to yield CURRENT=0 and a green checkmark; it now checks eslint's exit status and refuses on >=2. That is the real defect from the original report and it is untouched. - the ratchet, rebaselined at the honest count of 9 rather than a swept 0. Those nine are the debt. The flag returns one script at a time, with each pipe's empty case actually EXERCISED, and the baseline drops by one. - the CI mutation step, now pointed at system-stop.sh (which still carries the flag). It has already earned itself twice: it caught the unanchored regex that let a comment mentioning "set -o pipefail" pass as compliance, and it is what keeps a rebaselined gate from quietly becoming decoration. The lesson I paid for twice tonight: a mechanical sweep of a behaviour-changing flag is not hygiene, it is a behaviour change to every file it touches — and `bash -n` cannot see it, because parsing is syntax and this is runtime. I reported "40/40 parse" and called it verified. Card aad30dee. Unblocks the fleet: canary tip is deployable again. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
joelteply
added a commit
that referenced
this pull request
Sep 5, 2026
Three defects on the FRESH-INSTALL path (install.sh -> lib/install-common.sh). None is a #3736 regression: install.sh has run `set -eo pipefail` on line 26 since d9cd959 (2026-07-05) and sources this library into that shell, so the first two have been live for two months and reverting pipefail from the -e scripts does not reach them. 1+2. TWO PIPELINES ABORT THE INSTALL, both the same shape — a pipeline whose EMPTY result the very next line was already written to handle: mod_cold_storage grep exits 1 when config.env has no CONTINUUM_STORAGE_PATH line, the ordinary state of a config.env an earlier install step wrote. Next line is `[ -n "$existing" ]`. Measured: 1. mod_docker_wsl ls exits 2 with no Docker Desktop installed for the Windows user. Next line is `[ -z "$settings" ]` guarding a module_fail that names that exact cause — so the script died one line before it could explain itself. Measured: exit 2. Guarded with `|| true` plus a comment naming the already-handled empty case, per the burn-down rule: read a piped substitution WITH ITS NEXT LINE, then either guard it with a stated reason or let it fail honestly. 3. RAM DETECTION REPORTS ZERO ON WINDOWS 11 24H2+. The arm gates on `command -v wmic`, and WMIC WAS REMOVED IN 24H2 — on 26200 it is absent, so the else-branch set IC_RAM_MIB=0 on a machine with 64914 MiB and every RAM-based tier decision downstream was made on that zero. The replaced comment called wmic "the most portable across Windows versions", true when written and backwards now. wmic stays first (still present and fast on Win10 and pre-24H2 Win11); PowerShell CIM is the fallback. A non-numeric reading now WARNS rather than silently becoming 0, because "we could not look" is a different fact from "this machine has no RAM" and IC_RAM_MIB has one representation for both. Verified on Windows 11 26200 / Git Bash, old vs new through the same harness: cold-storage old exit 1 / new exit 0; docker old exit 2 / new exit 0; RAM arm old IC_RAM_MIB=0 / new IC_RAM_MIB=64914. NOT verified by the shared precommit hook: this checkout has no .git/hooks/pre-commit installed, so the hook did not run on this commit. Flagged separately; not bypassed with --no-verify. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
joelteply
added a commit
that referenced
this pull request
Sep 5, 2026
Three defects on the FRESH-INSTALL path (install.sh -> lib/install-common.sh). None is a #3736 regression: install.sh has run `set -eo pipefail` on line 26 since d9cd959 (2026-07-05) and sources this library into that shell, so the first two have been live for two months and reverting pipefail from the -e scripts does not reach them. 1+2. TWO PIPELINES ABORT THE INSTALL, both the same shape — a pipeline whose EMPTY result the very next line was already written to handle: mod_cold_storage grep exits 1 when config.env has no CONTINUUM_STORAGE_PATH line, the ordinary state of a config.env an earlier install step wrote. Next line is `[ -n "$existing" ]`. Measured: 1. mod_docker_wsl ls exits 2 with no Docker Desktop installed for the Windows user. Next line is `[ -z "$settings" ]` guarding a module_fail that names that exact cause — so the script died one line before it could explain itself. Measured: exit 2. Guarded with `|| true` plus a comment naming the already-handled empty case, per the burn-down rule: read a piped substitution WITH ITS NEXT LINE, then either guard it with a stated reason or let it fail honestly. 3. RAM DETECTION REPORTS ZERO ON WINDOWS 11 24H2+. The arm gates on `command -v wmic`, and WMIC WAS REMOVED IN 24H2 — on 26200 it is absent, so the else-branch set IC_RAM_MIB=0 on a machine with 64914 MiB and every RAM-based tier decision downstream was made on that zero. The replaced comment called wmic "the most portable across Windows versions", true when written and backwards now. wmic stays first (still present and fast on Win10 and pre-24H2 Win11); PowerShell CIM is the fallback. A non-numeric reading now WARNS rather than silently becoming 0, because "we could not look" is a different fact from "this machine has no RAM" and IC_RAM_MIB has one representation for both. Verified on Windows 11 26200 / Git Bash, old vs new through the same harness: cold-storage old exit 1 / new exit 0; docker old exit 2 / new exit 0; RAM arm old IC_RAM_MIB=0 / new IC_RAM_MIB=64914. NOT verified by the shared precommit hook: this checkout has no .git/hooks/pre-commit installed, so the hook did not run on this commit. Flagged separately; not bypassed with --no-verify. Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc Co-authored-by: Claude Opus 5 (1M context) <[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.
Card aad30dee. Finder's-right from the pipe-ate-the-exit-code incident.
The defect
Without
pipefaila pipeline's exit status is its last command's. Socargo build … 2>&1 | tail -12reportstail's success while cargo failed. That cost an evening: a rebuild was reported green by its own harness, no binary was produced, and the node ran a stale core hosting zero citizens for hours.set -edoes not cover this. Every one of these scripts could carryset -eand still swallow the exit code of the command that mattered — which is what makes it survive review. The script looks defended.The concrete one, in the gate nobody may bypass
git-prepush.shcounted ESLint errors by grepping the linter's merged output:A linter that crashed (missing module, bad config, wrong cwd) writes diagnostics the regex doesn't match —
Error: Cannot find modulehas a capital E and no trailing whitespace class — so the count is0,0 -le BASELINEholds, and the push sails through under a green checkmark:|| trueguaranteed the pipeline could not fail independently of pipefail. So the fix is not the flag: it now checks eslint's exit status (0 = clean, 1 = found errors, ≥2 = the linter itself failed) and refuses loudly on ≥2.|| LINT_RC=$?there is load-bearing:set -eaborts on a failing command substitution and eslint exits 1 for the ordinary "found errors" case, so without it the script dies on the exact path it exists to report.Proven by execution, not by reading
Against a stubbed eslint:
set -eFAILED=1CURRENT=0→ green checkmarkScope: deliberately not
-euo-u(nounset) makes a bare reference to an unset variable fatal.start-server.shalone carries 193 bare references against 11 guarded — optional per-host env vars are how it adapts to each machine. Turning nounset on there is a behaviour change to the deploy path, testable on no box I have, whose failure mode is an install that dies instantly on hardware nobody can reproduce. Worse than the hole being closed, and it lands hardest on the tier least able to recover.-ubelongs in its own per-file audit with its own ratchet. Agreed with M5 before writing this.The ratchet
21 scripts gained
set -o pipefail; all 40 verified to still parse (bash -n). Baseline is zero.Its CI job runs a mutation step: strip pipefail from
start-server.sh, assert the gate goes red, restore. A ratchet that cannot be shown to fail is decoration — and this one was written by someone who, while testing it, rancheck-pipefail.sh | tail -6, readexit=0, and briefly believed a red gate was green. The bug caught its own author mid-fix. That is why the mutation step is in CI rather than a note.Both triggers carry the same
pathsfilter, per the comment onts-persona-forbidden-strings-ratchet.ymlwhere a missing filter onpushproduced 100/100 red and taught everyone to ignore the X.🤖 Generated with Claude Code
https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE