Repository navigation
fix(scripts): pipefail must not kill the deploy where an empty result is normal - #3738
Conversation
… 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
|
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: That is tools/scripts/git-precommit.sh:658 ( |
…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
|
M5-core re-review on 3f1aa35: NO OBJECTION. Verified by running, not reading: on the head, the nine |
Regression from my own #3736. Two command substitutions in
start-server.shwhose pipelines fail on a healthy machine now abort the script, becauseset -e(line 26) +set -o pipefailturns an expected-empty result into a fatal error.Measured — both exit 1 before this commit
1.
start-server.sh:411— airc socket derivationX="$( ls -1t "$HOME"/.airc/runtime/airc-machine-*-v5.sock 2>/dev/null | grep -v '\.lock$' | head -1 )"lsfails when no socket matches;grep -vexits 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 probeport="$( ps -o command= -p "$pid" 2>/dev/null | sed -n 's/.*--port[ =]\([0-9]\{1,\}\).*/\1/p' )"psfails 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
|| trueinside 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:
false | catunder the same settingsWhy #3736 missed it
I ran
bash -non all 40 scripts and reported "all parse". Parsing is syntax; this is runtime behaviour, andbash -ncannot see it. I let "40/40 parse" stand in for "the deploy path still works" — the same substitution error as readingtail'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
-euosweep 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