From 7530280407b9a466fc4a546f026f1cc3eff8211a Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sun, 22 Nov 2026 04:24:05 -0800 Subject: [PATCH] A skipped CI run no longer blocks reusing a passing run on the same commit (GST-3514) (#4695) When one commit gets two runs of the same workflow and the newer one skipped every job, the passing run can now be reused, and the CI wait no longer reports that commit red. gbrain hit this when a pull request run that skipped all its jobs, created in the same second as a passing manual run, blocked that passing run. Nothing to do: a newer failed, cancelled or still-running run still blocks reuse exactly as before. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=red-team --- changelog.d/ci-reuse-skipped-run-no-veto.md | 1 + docs/pregate.md | 6 +++++- lib/ci-carry.ts | 3 ++- lib/run-evidence.ts | 2 +- test/ci-carry.test.ts | 9 +++++++++ test/run-evidence.test.ts | 9 +++++++++ 6 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 changelog.d/ci-reuse-skipped-run-no-veto.md diff --git a/changelog.d/ci-reuse-skipped-run-no-veto.md b/changelog.d/ci-reuse-skipped-run-no-veto.md new file mode 100644 index 000000000..3cd9ed818 --- /dev/null +++ b/changelog.d/ci-reuse-skipped-run-no-veto.md @@ -0,0 +1 @@ +**A skipped CI run no longer blocks reuse of a passing run on the same commit.** When a workflow fired twice for one commit, say a manual dispatch plus a pull request run whose jobs all skipped, the skipped run was treated as a newer failure: `gstack-pregate` refused the passing run with `newer_run_vetoes`, and `gstack-ci-carry wait` reported the commit red. Both now pass over the skipped run. A newer failed, cancelled or still-running run still blocks reuse. diff --git a/docs/pregate.md b/docs/pregate.md index 83f3ddbca..527e21d5e 100644 --- a/docs/pregate.md +++ b/docs/pregate.md @@ -914,7 +914,11 @@ once: (`tree_mismatch` otherwise). The API answers with the newest attempt, so an earlier green attempt under a newer red one is refused, and the run is read again after the evidence is collected: a new - attempt meanwhile is `run_changed`. + attempt meanwhile is `run_changed`. A newer run of the same workflow on the + head, of any event, vetoes it (`newer_run_vetoes`) when that run failed, was + cancelled or is still running. A newer green run doesn't, and neither does a + newer skipped run, which ran no job and so says nothing about the tree + (GST-3514). - Every job the profile names appears exactly once in that attempt and succeeded. Jobs and runs are read across every page. - `tree.json` (an artifact of at most 8 MiB) names this run, attempt, event and diff --git a/lib/ci-carry.ts b/lib/ci-carry.ts index 8061adc21..a548fdb5d 100644 --- a/lib/ci-carry.ts +++ b/lib/ci-carry.ts @@ -175,7 +175,8 @@ const PASSING = ['success', 'skipped', 'neutral']; export async function waitForRun(deps: RunDeps, o: { workflow: string; events: string[]; head: string; also?: string[]; timeoutMs: number; intervalMs: number; sleep: (ms: number) => Promise; clock: () => number; random?: () => number }): Promise { const end = o.clock() + o.timeoutMs; for (;;) { - const newest = [o.head, ...(o.also ?? [])].flatMap(h => deps.runsForHead(o.workflow, h)).filter(r => o.events.includes(r.event)).sort(newestFirst)[0]; + const runs = [o.head, ...(o.also ?? [])].flatMap(h => deps.runsForHead(o.workflow, h)).filter(r => o.events.includes(r.event)).sort(newestFirst); + const newest = runs.find(r => !(r.status === 'completed' && r.conclusion === 'skipped')) ?? runs[0]; if (newest?.status === 'completed') { if (newest.conclusion === 'success') return { state: 'green', run: newest }; const failing = deps.jobs(newest.id, newest.run_attempt).filter(j => !PASSING.includes(j.conclusion ?? '')).map(j => j.name); diff --git a/lib/run-evidence.ts b/lib/run-evidence.ts index cd2fe3d11..f220b19d4 100644 --- a/lib/run-evidence.ts +++ b/lib/run-evidence.ts @@ -223,7 +223,7 @@ export function verifyRun(deps: RunDeps, o: { repo: string; runRef: string; prof } const heads = [...new Set([run.head_sha, ...(o.vetoHeads ?? []).filter(h => SHA.test(h))])]; for (const head of heads) { - const newer = deps.runsForHead(p.workflow, head).filter(r => !(r.id === id && r.run_attempt === run.run_attempt) && r.id !== o.ignoreRun && started(r) >= (run.created_at ?? '') && !(r.status === 'completed' && r.conclusion === 'success')); + const newer = deps.runsForHead(p.workflow, head).filter(r => !(r.id === id && r.run_attempt === run.run_attempt) && r.id !== o.ignoreRun && started(r) >= (run.created_at ?? '') && !(r.status === 'completed' && (r.conclusion === 'success' || r.conclusion === 'skipped'))); if (newer.length) return fail('newer_run_vetoes', `newer run ${newer[0]!.id} of ${p.workflow} on ${head.slice(0, 12)} is ${newer[0]!.status === 'completed' ? newer[0]!.conclusion : newer[0]!.status}`); } if (p.skippable && p.skippable.jobs.every(j => skippedJobs.includes(j)) && o.docsOnly?.(run.head_sha)) { diff --git a/test/ci-carry.test.ts b/test/ci-carry.test.ts index 12b292f37..947d34c0f 100644 --- a/test/ci-carry.test.ts +++ b/test/ci-carry.test.ts @@ -137,6 +137,15 @@ describe('waitForRun', () => { expect((await o([run(4, { status: 'in_progress', conclusion: null })])).state).toBe('running'); expect((await o([])).state).toBe('none'); }); + + // Value: protects=the wait agrees with verifyRun (GST-3514): a newer skipped run leaves the green dispatch green; fails_when=the skipped run is read as red + test('a newer skipped run is passed over for the run before it; a lone skipped run is still red', async () => { + const o = (runs: ApiRun[]) => waitForRun(source(runs).deps, { workflow: 'free-tests.yml', events: PROFILE.events, head: HEAD, timeoutMs: 60_000, intervalMs: 20_000, ...clockAt() }); + const skipped = run(5, { event: 'pull_request', conclusion: 'skipped', created_at: run(4).created_at }); + expect(await o([run(4), skipped])).toMatchObject({ state: 'green', run: { id: 4 } }); + expect((await o([run(4, { conclusion: 'failure' }), skipped])).state).toBe('red'); + expect(await o([skipped])).toMatchObject({ state: 'red', run: { id: 5 } }); + }); }); describe('ship_lanes_from config and the ci_carried receipt field', () => { diff --git a/test/run-evidence.test.ts b/test/run-evidence.test.ts index 3bb2860cf..d6e2e6708 100644 --- a/test/run-evidence.test.ts +++ b/test/run-evidence.test.ts @@ -102,6 +102,15 @@ describe('verifyRun', () => { expect(reason(world({ run: { ...w.run, run_started_at: '2026-10-29T12:00:00Z' }, others: [newer('completed', 'failure')] }))).toBe('newer_run_vetoes'); }); + test('a skipped run cannot veto: a pull_request run created in the same second with every job skipped leaves the dispatch green (GST-3514)', () => { + const w = world(); + const skipped = (over: Partial = {}): ApiRun => ({ ...w.run, id: 101, event: 'pull_request', status: 'completed', conclusion: 'skipped', ...over }); + expect(reason(world({ others: [skipped()] }))).toBe('ok'); + expect(reason(world({ others: [skipped({ event: 'workflow_dispatch' })] }))).toBe('ok'); + expect(reason(world({ others: [skipped({ event: 'workflow_dispatch', conclusion: 'failure' })] }))).toBe('newer_run_vetoes'); + expect(reason(world({ others: [skipped({ event: 'workflow_dispatch', status: 'in_progress', conclusion: null })] }))).toBe('newer_run_vetoes'); + }); + test('a newer failure on another head the consumer names (same tree, the lane\'s own head) vetoes too', () => { const w = world(); const other = 'e'.repeat(40);