Skip to content

fix(ship): match origin's HEAD advertisement in-shell so grep -q cannot SIGPIPE the default check (sc-6615) - #286

Merged
norvalbv merged 1 commit into
mainfrom
sc-6615-ship-origin-base-no-tracking-ref-flake
Nov 20, 2026
Merged

norvalbv merged 1 commit into
mainfrom
sc-6615-ship-origin-base-no-tracking-ref-flake

Conversation

@norvalbv

@norvalbv norvalbv commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

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) (sc-9021).

Not filed

  • Opt-in trace naming which resolver probe silently failed — design choice this PR keeps: origin-base.sh's contract is that a failed read means "no", and its output runs inside consumers' $(...).
  • Transient file:// ls-remote failure 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

  • captured-proof
✅ Regression evidence · captured: 1 of 1 red-failing tests passed on green (setup 9s, red 60s, green 53s, cleanup 5s)

Head 7e8fa5db79e0 · base 3d8cb408a261

run what ran exit passed failed skipped
red PR test files on the PR base 1 42 1 0
green PR head 0 43 0 0
Failed 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
[
  "node_modules/.bin/vitest",
  "run",
  "--reporter=json",
  "--outputFile.json=.devkit-evidence-report.json",
  "cli/__tests__/ship-origin-base.test.mts"
]

Captured runs, not proof of causality. Dependencies are the shipping checkout's installed packages. Stale unless the PR head is 7e8fa5db79e0cbfce2ab5a497a561f4e14466aec.

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

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

ship_origin_default_still now requires the advertised OID to match the expected OID as well as the default branch. A regression test checks suggested-base resolution when the remote advertises many refs.

Changes: Origin default verification

Layer / File(s) Summary
Verify origin default and suggested base
cli/lib/ship/origin-base.sh, cli/__tests__/ship-origin-base.test.mts
ship_origin_default_still now requires an expected OID and checks the branch and OID in one remote advertisement. The regression test creates 3,000 additional refs and checks that suggestedOf returns default main.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 7e8fa

This fixes an intermittent false result in origin default detection that could cause a stale suggested base. It includes a regression test and has no identified merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the specific fix: matching origin's HEAD advertisement in-shell so that grep -q cannot cause SIGPIPE in the default check. The raw summary confirms that ship_origin_default_still now m…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the specific fix: matching origin's HEAD advertisement in-shell so that grep -q cannot cause SIGPIPE in the default check. The raw summary confirms that ship_origin_default_still now matches the ls-remote advertisement in-shell rather than through a printf | grep -q pipeline, and that a regression test was added. The title is concise and specific, though its length (107 characters) is on the long side and it includes a ticket reference.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2da233af-b857-43c8-9697-bd81b75d6b8d
Commits

Reviewing files that changed from the base of the PR and between 3d8cb40 and 7e8fa5d.

Files selected for processing: 2

  • cli/__tests__/ship-origin-base.test.mts
  • cli/lib/ship/origin-base.sh

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@norvalbv
norvalbv merged commit 1627394 into main Nov 20, 2026
6 checks passed
@norvalbv
norvalbv deleted the sc-6615-ship-origin-base-no-tracking-ref-flake branch November 20, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant