Skip to content

fix(scripts): pipefail must not kill the deploy where an empty result is normal - #3738

Merged
joelteply merged 3 commits into
canaryfrom
fix/pipefail-substitution-guards
Sep 5, 2026
Merged

joelteply merged 3 commits into
canaryfrom
fix/pipefail-substitution-guards

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Regression from my own #3736. Two command substitutions in start-server.sh whose pipelines fail on a healthy machine now abort the script, because set -e (line 26) + set -o pipefail turns an expected-empty result into a fatal error.

Measured — both exit 1 before this commit

1. start-server.sh:411 — 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 exits silently with no FATAL line, because it dies at a substitution rather than at a guarded check.

2. start-server.sh:255 — lane-adopt port probe

port="$( ps -o command= -p "$pid" 2>/dev/null | sed -n 's/.*--port[ =]\([0-9]\{1,\}\).*/\1/p' )"

ps fails when the pid died between listing and probing — the ordinary race this 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.

The fix

|| 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. Every other pipe in the script keeps the new behaviour.

Verified by running, not reading:

case result
no airc socket (fresh install) guard handles it, script alive
dead pid during lane adoption guard handles it, script alive
genuine false | cat under the same settings still exits 1 — pipefail intact

Why #3736 missed it

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

… 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
…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

Copy link
Copy Markdown
Contributor Author

M5-core review: CHANGE REQUESTED — the two deploy-path sites are right, but the precommit hook has the same defect and it blocks every commit from a canary-tip checkout. Reproduced in a dry shell, not by grep:

bash -c 'set -e -o pipefail; S=$(find examples/widget-ui/.continuum/jtag/sessions/user/*/screenshots/*.png 2>/dev/null | head -1); echo survived'
→ exit 1, "survived" never printed

That is tools/scripts/git-precommit.sh:658 (SCREENSHOT_SESSION=$(find … | head -1), no || true) under the hook's own set -e + the new set -o pipefail (line 3). On any checkout without that screenshots directory — most of them — the hook dies at the screenshot step. Add || true there with the reason (an absent screenshot session is the normal case), and do the same audit for download-avatar-models.sh (7 sites), install-livekit.sh (6), install-tailscale.sh (4), git-prepush.sh (4), uninstall.sh (3): each site either has a next line that handles empty (→ || true + reason) or was a latent bug (→ leave pipefail's verdict). List the 43 in the description with the verdict per site. Then no objection; I re-run the hook's front half and the two probes in a dry shell.

…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
@github-actions github-actions Bot added size: M and removed size: S labels Sep 5, 2026
@joelteply

Copy link
Copy Markdown
Contributor Author

M5-core re-review on 3f1aa35: NO OBJECTION. Verified by running, not reading: on the head, the nine set -e scripts no longer set pipefail (check-pipefail.sh keeps both, correctly), and under the scripts' real flags all three sites survive with empty results — hook :658 screenshot find, Case A (no machine socket), Case B (dead pid) — each printing 'survived []'. The nine-entry baseline is the honest state: pipefail only where a script is audited site by site; ratchet it to zero one script at a time with a || true + reason per legitimate-empty site. Merging on green.

@joelteply
joelteply merged commit 485cde6 into canary Sep 5, 2026
7 checks passed
@joelteply
joelteply deleted the fix/pipefail-substitution-guards branch September 5, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant