/ship reuses CI's passing run when a base merge changed no file, and stops before long local test runs or an unknown base (GST-3019) (#4461)

/ship's preflight and its CI-run lookup now reuse a passing CI test run
when a base merge left the files unchanged, stop instead of quietly
starting an hour-long test suite on the local machine, and refuse a
`--base` that names no commit instead of reporting an empty diff.

Why: gbrain #9662 lost a green CI run to a no-op base merge, then ran a
50-minute suite on a 4-CPU box, and its audit read a commit sha as a
branch and saw zero changed files.

Nothing to do: `--run-uncarried-here` restores running an uncovered
suite locally under `--tests-only`.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: s11/outside-voice#1 reader=outside-voice
Review-Finding: s11/outside-voice#2 reader=outside-voice
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-17 20:56:07 +00:00
1 parent 76535826f5
commit da98d0a0eb
18 files changed
+354 -45

No files matched your search

+10 -5
View File
@@ -9,13 +9,15 @@
* find: the newest verified run of each profile (default: every profile the base branch's
* ship_lanes_from names) at HEAD's clean tree. With --command, the base branch's mapping for that exact lane
* command supplies the profiles and the inventory the runs must cover (a pin-file command, so it needs
* --allow-repo-commands). Prints CI_CARRY: accepted <receipt> (exit 0) or CI_CARRY: none (<reason>) (exit 1).
* --allow-repo-commands). Prints CI_CARRY: accepted <receipt> (exit 0) or CI_CARRY: none (<reason>) (exit 1). A run at
* one of HEAD's ancestors whose tree git reads as HEAD's (a base merge that changed no file) carries too, and CI_CARRY_FROM
* names that run and commit (GST-3019).
* wait: polls the newest run of the profile's workflow at HEAD (REST, at least 60 s apart) until it completes (default timeout 1800 s),
* prints CI_WAIT: green|red|running|none, and on green runs find. Exit 0 green and carried, 1 red or not
* carried, 3 still running or no run. Logic: lib/ci-carry.ts; the run checks are lib/run-evidence.ts.
*/
import { spawnSync } from 'node:child_process';
import { findCarry, laneMapping, mappingCoverage, waitForRun } from '../lib/ci-carry';
import { carriedFromLine, findCarry, laneMapping, mappingCoverage, treeTwins, waitForRun } from '../lib/ci-carry';
import { isConfigUnavailable, loadConfigFromBase, loadConfigFromHead } from '../lib/pregate/config';
import { buildRunCheck } from '../lib/pregate/run-check';
import { wtreeFingerprint } from '../lib/script-invocation';
@@ -24,11 +26,12 @@ import { resolveBaseBranch } from '../lib/ship-policy';
const HELP = `gstack-ci-carry — use a verified CI run at HEAD's exact tree instead of running the suite again (docs/pregate.md#ci-carry)
find [--base <branch>] [--profile <name>]... [--command <exact lane command> --allow-repo-commands] [--json]
CI_CARRY: accepted <receipt> (exit 0) or CI_CARRY: none (<reason>) (exit 1)
CI_CARRY: accepted <receipt> (exit 0) or CI_CARRY: none (<reason>) (exit 1); a run at an earlier commit with
HEAD's exact tree (git rev-parse <sha>^{tree}) carries too, and CI_CARRY_FROM: names that run and commit
--policy-from head --simulate: the same check under the branch's own map and profiles, every line starting
SIMULATION:; a dry run that proves a new mapping before it lands (find never writes evidence; nothing clears)
wait [--base <branch>] [--profile <name>] [--timeout <s>] [--interval <s>]
poll the newest run at HEAD (default 1800 s, every 60 s at least, plus jitter): CI_WAIT: green|red|running|none, then find on green;
poll the newest run at HEAD or an earlier commit with its tree (default 1800 s, every 60 s at least, plus jitter): CI_WAIT: green|red|running|none, then find on green;
exit 0 carried, 1 red or not carried, 3 still running or no run
Profiles and ship_lanes_from come from origin/<base>'s .gstack/pregate.json only (a simulation reads the branch's). Only a clean, committed tree
@@ -70,6 +73,8 @@ function find(): number {
const v = findCarry(check as Exclude<typeof check, { error: string }>, { profiles, head, tree, wtree, ...(mapping ? mappingCoverage(mapping, root) : {}) });
if (argv.includes('--json')) out(JSON.stringify(v));
else out(v.ok ? `CI_CARRY: accepted ${v.receipt}` : `CI_CARRY: none (${v.reason}: ${v.detail})`);
const from = v.ok && !argv.includes('--json') ? carriedFromLine(v.runs, head) : undefined;
if (from) out(from);
return v.ok ? 0 : 1;
}
@@ -79,6 +84,6 @@ const interval = Number(flag('--interval') ?? '60');
if (!(timeout >= 0 && timeout <= 21_600) || !(interval >= 1 && interval <= 600)) usage('--timeout is 0-21600 seconds and --interval 1-600');
const profile = check.profiles[profiles[0]!];
if (!profile) usage(`${profiles[0]} is not a run_profiles name on origin/${base}`);
const w = await waitForRun(check.deps, { workflow: profile!.workflow, events: profile!.events, head, timeoutMs: timeout * 1000, intervalMs: interval * 1000, sleep: ms => Bun.sleep(ms), clock: Date.now });
const w = await waitForRun(check.deps, { workflow: profile!.workflow, events: profile!.events, head, also: treeTwins(check.deps, head, tree), timeoutMs: timeout * 1000, intervalMs: interval * 1000, sleep: ms => Bun.sleep(ms), clock: Date.now });
out(`CI_WAIT: ${w.state} ${profiles[0]} ${'run' in w ? `run=${w.run.id}/${w.run.run_attempt}${w.state === 'red' ? ` failing=${w.failing.join(',') || '-'}` : ''}` : w.reason}`);
process.exit(w.state === 'green' ? find() : w.state === 'red' ? 1 : 3);
+5 -1
View File
@@ -100,7 +100,7 @@ import { resultLine } from "../lib/result-codes";
import { isUnavailable, loadPolicyFromBase, resolveBaseBranch } from "../lib/ship-policy";
import { versionAtRef } from "../lib/restamp";
import { bashCommandInvocation, runScriptSync, wtreeFingerprint } from "../lib/script-invocation";
import { findCarry, laneMapping, mappingCoverage, perFileCommand } from "../lib/ci-carry";
import { carriedFromLine, findCarry, laneMapping, mappingCoverage, perFileCommand } from "../lib/ci-carry";
import { DEFAULT_MAX_AGE_HOURS, runChanged } from "../lib/run-evidence";
import { isConfigUnavailable, loadConfigFromBase } from "../lib/pregate/config";
import { buildRunCheck } from "../lib/pregate/run-check";
@@ -806,6 +806,8 @@ async function cmdRecordCi(argv: string[]): Promise<number> {
if (prior) {
console.error(recordedCiLine(prior));
if (prior.not_owed) console.error(`gstack-evidence: not owed: ${prior.not_owed}`);
const priorFrom = carriedFromLine(v.runs, head);
if (priorFrom) console.error(priorFrom);
console.error(`CI_RECORD_REUSED: label=${label} runs=${runs.join(",")} tree=${tree.slice(0, 12)} policy=${loaded.label} (the ledger's CI row for this exact tree, run and selection; nothing ran here)`);
return 0;
}
@@ -870,6 +872,8 @@ async function cmdRecordCi(argv: string[]): Promise<number> {
appendJsonl(paths.file, rec, { mode: 0o600 });
console.error(recordedCiLine(rec));
if (v.notOwed) console.error(`gstack-evidence: not owed: ${v.notOwed}`);
const from = carriedFromLine(v.runs, head);
if (from) console.error(from);
if (exception) console.error(`TEST_LANE_EXCEPTION: ${testLaneExceptionText(exception)}`);
return 0;
}