A land that waits on an earlier CI run decides on what that run did, and main's reuse skips cancelled runs (GST-3634) (#4763)

A land that waits on an earlier CI run now goes by that run's real
result, and main's Free Tests run skips a cancelled run when it looks
for a land's run.

Why: a green run rerun at the moment land picked it up could have its
red result ignored, and a cancelled run made main rerun the whole suite.

Nothing to do.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-24 03:31:21 +00:00
1 parent 6ef3861302
commit 7c321fff5d
6 files changed
+25 -8

No files matched your search

+1
View File
@@ -0,0 +1 @@
**A land that waits on an earlier CI run now decides on what that run actually did.** If a green run was rerun at the moment land picked it up, a red or still-running rerun used to be ignored and land would start another run. Now the rerun's result counts. Main's own Free Tests run also skips a cancelled run when it looks for the run a land already did, so it reuses the earlier green one instead of running the whole suite again.
+1 -1
View File
@@ -1600,7 +1600,7 @@ workflow on the merged commit, on the scratch branch `gstack-land/<n>`
([ship-policy.md](ship-policy.md#land-direct)), and GitHub's merge has that
same tree unless main moved again before the merge. So when the head's tree
differs, `find` takes the newest `workflow_dispatch` run on `gstack-land/<n>`
and reuses it only when `verifyRun` accepts it and its `tested-tree` record
that wasn't cancelled (land passes cancelled runs over too) and reuses it only when `verifyRun` accepts it and its `tested-tree` record
names the pushed tree (`no_verified_run` or `tree_mismatch` otherwise; a branch
with no such run keeps `tree_mismatch`). Only the newest run counts, newest by run id
rather than start time, so a red retry on the same tree is never hidden
+5 -5
View File
@@ -37,8 +37,8 @@ export interface CiDeps {
now(): number;
url(id: number): string;
}
/** `run`: the run the refusal is about: a red run, or one still going that the next land on the same merged tree waits on. */
export type CiResult = { ok: true; line: string } | { ok: false; red: boolean; detail: string; run?: number };
/** `run`: the run the refusal is about: a red run, or one still going that the next land on the same merged tree waits on. `unproved`: the run finished green but does not prove the merged tree. */
export type CiResult = { ok: true; line: string } | { ok: false; red: boolean; detail: string; run?: number; unproved?: true };
type CiInput = { pr: string; commit: string; tree: string; ci: MergedCi; timeoutMs?: number };
/** The newest workflow_dispatch run of `ci.workflow` on the scratch branch or at the merged commit whose head commit has the merged tree, unless it was cancelled. */
@@ -62,8 +62,8 @@ function settle(deps: CiDeps, o: CiInput, branch: string, first: ApiRun | undefi
const at = `${o.ci.workflow} run ${deps.url(run.id)} on the merged tree ${o.tree.slice(0, 12)}`;
if (run.conclusion !== 'success') return { ok: false, red: true, run: run.id, detail: `${at} concluded ${run.conclusion ?? 'unknown'}` };
const v = deps.verify(run.id);
if (!v.ok) return { ok: false, red: false, detail: `${at} passed, but it does not prove the tree under ${o.ci.profile}: ${v.detail}` };
if (v.head !== run.head_sha || v.tree !== o.tree) return { ok: false, red: false, detail: `${at} tested ${v.head.slice(0, 12)} (tree ${v.tree.slice(0, 12)}), not the merged commit ${o.commit.slice(0, 12)} or a commit with its tree` };
if (!v.ok) return { ok: false, red: false, unproved: true, detail: `${at} passed, but it does not prove the tree under ${o.ci.profile}: ${v.detail}` };
if (v.head !== run.head_sha || v.tree !== o.tree) return { ok: false, red: false, unproved: true, detail: `${at} tested ${v.head.slice(0, 12)} (tree ${v.tree.slice(0, 12)}), not the merged commit ${o.commit.slice(0, 12)} or a commit with its tree` };
const earlier = run.head_sha === o.commit ? '' : `; run by an earlier land at ${run.head_sha.slice(0, 12)}, not dispatched again`;
return { ok: true, line: `MERGED_CI: pass ${at} (profile ${o.ci.profile}${earlier})` };
}
@@ -74,7 +74,7 @@ export function runMergedCi(deps: CiDeps, o: CiInput): CiResult {
const earlier = earlierRun(deps, o, branch);
if (earlier) {
const r = settle(deps, o, branch, earlier, deps.now());
if (r.ok || earlier.status !== 'completed' || earlier.conclusion !== 'success') { deps.remove(branch); return r; }
if (r.ok || !r.unproved || earlier.status !== 'completed') { deps.remove(branch); return r; }
}
const pushed = deps.push(o.commit, branch);
if (pushed) return { ok: false, red: false, detail: `cannot push the merged commit ${o.commit.slice(0, 12)} to ${branch}: ${pushed}` };
+2 -2
View File
@@ -19,7 +19,7 @@
* first one lib/run-evidence.ts verifyRun accepts under the profile in the pushed tree's
* .gstack/pregate.json. A pull_request run counts only when its merge commit's tree is its head's tree
* (verifyRun). When the head's tree differs (land merged a stale-base pin), the only candidate is the newest
* workflow_dispatch run on landBranch(<pr>), the run land.merged_ci gated the merge on, and it counts only when
* workflow_dispatch run on landBranch(<pr>) that was not cancelled, the run land.merged_ci gated the merge on, and it counts only when
* verifyRun accepts it with the pushed tree as its tested tree (newest by run id, so a re-run of an older land run
* never outranks a later red one): that run executed this same tree's workflow, so
* the rules it ran under are the ones now on main. It writes reused=true, run_id, run_url and tree to GITHUB_OUTPUT, or reused=false and a
@@ -79,7 +79,7 @@ export function findReuse(deps: ReuseDeps, o: { repo: string; base: string; push
const mismatch = `#${pr.number}'s head ${pr.head.sha.slice(0, 12)} has tree ${headTree.slice(0, 12)}, the push has ${pushTree.slice(0, 12)}`;
const branch = landBranch(pr.number);
const land = events.includes('workflow_dispatch')
? deps.runsForBranch(o.workflow, branch).filter(r => r.event === 'workflow_dispatch' && r.head_branch === branch).sort((a, b) => b.id - a.id)[0]
? deps.runsForBranch(o.workflow, branch).filter(r => r.event === 'workflow_dispatch' && r.head_branch === branch && r.conclusion !== 'cancelled').sort((a, b) => b.id - a.id)[0]
: undefined;
if (!land) return refuse('tree_mismatch', `${mismatch}, and ${branch} has no workflow_dispatch run of ${o.workflow}`);
const v = verifyRun(deps, { repo: o.repo, runRef: String(land.id), profileName: o.profileName, profile: o.profile, now: o.now });
+5
View File
@@ -101,6 +101,11 @@ describe('findReuse: candidate discovery for a main push', () => {
expect(rerunOlder).toMatchObject({ reused: false, reason: 'no_verified_run', detail: expect.stringContaining('land run 301 on gstack-land/42 reason=run_not_success') });
});
test('a cancelled land run is passed over, as land itself passes it over: the older green run on the same tree is reused', () => {
const LAND2 = '7'.repeat(40);
expect(find(stale([landRun(), landRun({ id: 301, head: LAND2, conclusion: 'cancelled', started: '2026-10-30T10:40:00Z' })], { [LAND2]: TREE }))).toMatchObject({ reused: true, run_id: 300 });
});
test('a land run that tested another tree (main moved before the merge) is refused, and the suite runs', () => {
const v = find(stale([landRun({ record: { tree: OTHER } })], { [LAND]: OTHER }));
expect(v).toMatchObject({ reused: false, reason: 'tree_mismatch' });
+11
View File
@@ -178,6 +178,17 @@ describe('land.merged_ci reuses an earlier run on the merged tree (GST-3634)', (
expect(calls.at(-1)).toBe('remove gstack-land/42');
});
test('a green run that is rerun between listing and polling decides on what land polled: red refuses as red and a timeout names it, never a fresh dispatch', () => {
const listed = earlier({});
const rerun = { ...listed, run_attempt: 2, status: 'in_progress', conclusion: null };
const red = fake({ earlier: [listed], runs: [[rerun], [{ ...rerun, status: 'completed', conclusion: 'failure' }]], verify: provesOld });
expect(run(red.deps)).toMatchObject({ ok: false, red: true, run: 9 });
expect(red.calls.some(c => c.startsWith('push ') || c.startsWith('dispatch '))).toBe(false);
const slow = fake({ earlier: [listed], runs: [[rerun]], verify: provesOld });
expect(run(slow.deps, 60_000)).toMatchObject({ ok: false, red: false, run: 9 });
expect(slow.calls.some(c => c.startsWith('push ') || c.startsWith('dispatch '))).toBe(false);
});
test('a timed-out wait names the run the next land adopts, and that land adopts it after the scratch branch was deleted', () => {
const going: ApiRun = { ...queued, id: 77, head_branch: 'gstack-land/42', head_commit: { tree_id: TREE } };
const first = fake({ runs: [[going]] });