Repository navigation
fix(ship): match origin's HEAD advertisement in-shell so grep -q cannot SIGPIPE the default check (sc-6615) - #286
Conversation
…ot SIGPIPE the default check (sc-6615) Fixes [sc-6615] ## What was wrong `ship_origin_default_still` (`cli/lib/ship/origin-base.sh`) checked origin's `ls-remote` advertisement with `printf '%s\n' "$out" | grep -qxF …`. Its callers run under `set -euo pipefail`. - bash line-buffers stdout, so printf writes the advertisement one line at a time. - `grep -q` exits as soon as line 1 (`ref: refs/heads/main<TAB>HEAD`) matches. - If printf still has a line to write, that write gets SIGPIPE (exit 141). pipefail turns it into `return 1`: "the default moved". - `ship_suggested_base_proven` then falls back to the nearest ancestor. That produced `ancestor 0.0.8` instead of `default main`, the exact output of both CI failures: line 404, and line 412 in the report's correction. This race was not limited to tests. Under load, a real `devkit ship` could suggest a stale ancestor branch as `--base`. ## Fix - Match the advertisement inside the shell with `case`, using exact whole-line patterns anchored by a newline on both sides. Nothing is piped, so there is no early-exit reader. - Remove the branch that ran when no oid was passed. All four callers pass one, so `oid` is now required. ## Proof - **Cause, at CI size, on Linux** (node:24-bookworm, bash 5.2.15, 10 CPU burners): the old 3-line pipe failed 100 of 20,000 runs, all with exit 141. The new `case` match failed 0 of 20,000. - **New regression test** "still answers the default when grep -q would exit before the advertisement is written". It pads origin with 3,000 `refs/heads/padN/HEAD` refs; `ls-remote` tail-matches `HEAD`, so they join the advertisement. That makes the race happen on every run. - On the old code it fails with `out: "ancestor 0.0.8"` on macOS (bash 3.2) and in the Linux container. - On the fix it passes. - **Story AC** (Linux container, under parallel CPU load): the "no tracking ref", "unseen default" and new test, 50 runs each, gave `pass=50 fail=0`. - vitest has no `--repeat` CLI flag, so this is a shell loop. - The flake rate was about 1 in 1,500 per test, so 50 runs alone cannot tell old code from new. The deterministic red/green test above is the discriminating proof. - **Existing coverage of the new branches:** I made each check never reject and reran the suites. - Disabling the HEAD-line check fails "never names a default whose origin HEAD was repointed…" and "reuses one proven base across a refusal…". - Disabling the oid check fails "does not fall back to a default force-pushed between its judgment and its re-proof". - **Test runs:** `ship-origin-base.test.mts` passes 43/43. `ship-base-ancestry` and `ship-base-and-self-checkout` pass 80/80. - **Match semantics:** exact whole-line matching was checked on bash 3.2, 5.2 and 5.3. A 2 MB, 30,000-ref advertisement matches in 132 ms or less. - `dist/cli/lib/ship/origin-base.sh` is unchanged; it is release-only. ## Follow-ups (not in this PR) - `cli/lib/ship/queue/slot.sh:66` has the same `printf | grep -Fxq` shape under pipefail (bug, sev 3, traced). - An opt-in trace naming which resolver probe silently failed (feature). - A transient file:// `ls-remote` failure is still a possible second cause. It is unevidenced and now unlikely (bug, sev 3, claimed). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Complete against acceptance criteria: yes
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Fixes [sc-6615]
What was wrong
ship_origin_default_still(cli/lib/ship/origin-base.sh) checked origin'sls-remoteadvertisement withprintf '%s\n' "$out" | grep -qxF …. Its callers run underset -euo pipefail.grep -qexits as soon as line 1 (ref: refs/heads/main<TAB>HEAD) matches.return 1: "the default moved".ship_suggested_base_proventhen falls back to the nearest ancestor. That producedancestor 0.0.8instead ofdefault main, the exact output of both CI failures: line 404, and line 412 in the report's correction.This race was not limited to tests. Under load, a real
devkit shipcould suggest a stale ancestor branch as--base.Fix
case, using exact whole-line patterns anchored by a newline on both sides. Nothing is piped, so there is no early-exit reader.oidis now required.Proof
casematch failed 0 of 20,000.refs/heads/padN/HEADrefs;ls-remotetail-matchesHEAD, so they join the advertisement. That makes the race happen on every run.out: "ancestor 0.0.8"on macOS (bash 3.2) and in the Linux container.pass=50 fail=0.--repeatCLI flag, so this is a shell loop.ship-origin-base.test.mtspasses 43/43.ship-base-ancestryandship-base-and-self-checkoutpass 80/80.dist/cli/lib/ship/origin-base.shis unchanged; it is release-only.Follow-ups (not in this PR)
cli/lib/ship/queue/slot.sh:66has the sameprintf | grep -Fxqshape under pipefail (bug, sev 3, traced) (sc-9021).Not filed
$(...).ls-remotefailure as a second cause — unverified, could not trace: the SIGPIPE cause is proven at CI size, and nothing points to an ls-remote failure.🤖 Generated with Claude Code
Complete against acceptance criteria: yes
Automated evidence
Merge verdict: 🟢 auto-merge-eligible · advisory, at
7e8fa5db79e0✅ Regression evidence · captured: 1 of 1 red-failing tests passed on green (setup 9s, red 60s, green 53s, cleanup 5s)
Head
7e8fa5db79e0· base3d8cb408a261Failed on red (1 test)
origin-base.sh — ship_suggested_base prefers a default that contains the candidate (sc-3409) still answers the default when grep -q would exit before the advertisement is written:AssertionError: expected { status: +0, …(2) } to match object { status: +0, out: 'default main' } (1 matching property omitted from actual)Test command
Captured runs, not proof of causality. Dependencies are the shipping checkout's installed packages. Stale unless the PR head is
7e8fa5db79e0cbfce2ab5a497a561f4e14466aec.