From 65eec7dbff35bf0ca6690668cda45a54625dbf54 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 17 Nov 2026 10:40:52 +0000 Subject: [PATCH] fix(ci): enforce proof-system lane during lease acquisition --- .../work-issue/references/ci-and-merge.md | 5 ++- docs/decisions/ci-utility.md | 11 ++++--- scripts/integrate.ts | 3 +- tests/integration-command.test.ts | 31 ++++++++++++++++--- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/.agents/skills/work-issue/references/ci-and-merge.md b/.agents/skills/work-issue/references/ci-and-merge.md index e72a6c9518..daafae619f 100644 --- a/.agents/skills/work-issue/references/ci-and-merge.md +++ b/.agents/skills/work-issue/references/ci-and-merge.md @@ -323,7 +323,7 @@ rewrites the reviewed commits and discards the record's coverage. A refresh that needed a conflict resolution also needs a new review. A proof-system candidate (`bun scripts/proof-system.ts classify --base ---head `) waits its turn in the proof-system lane. `confirm` (before +--head `) waits its turn in the proof-system lane. `acquire`, `confirm` (both before acquiring) and `merge` refuse it until the last proof-system squash on main has a completed main-push run of its own and the newest completed main run from that squash on is green: its own green run opens the lane, and after a @@ -375,6 +375,9 @@ the full lane, use `integrate.ts confirm` as above. Otherwise: 3. Take the lease, so the merge cannot race another session's confirmation: `bun scripts/integrate.ts acquire ` (it prints a lease id and a holder token). If another session holds it, wait. Never merge past a live lease. + For a proof-system candidate, `acquire` first enforces the stability window + and off-main qualification, with the same declared red-main fix exemption + as `confirm`; the fast lane skips neither gate. `acquire` needs the PR's recorded base to be main's current tip. If main has moved, merge `origin/main` into the branch, push, and repeat step 2 on the new head ("An open ordinary exact-main candidate is required" means this). diff --git a/docs/decisions/ci-utility.md b/docs/decisions/ci-utility.md index c09676054c..975f187efe 100644 --- a/docs/decisions/ci-utility.md +++ b/docs/decisions/ci-utility.md @@ -1357,8 +1357,8 @@ Each implementation task is tracked separately: #### Lane and qualification gates -`bun scripts/integrate.ts confirm` and `merge` classify the candidate from -its merge base with the exact base to its exact head, using `classify` from +`bun scripts/integrate.ts acquire`, `confirm` and `merge` classify the +candidate from its merge base with the exact base to its exact head, using `classify` from `scripts/proof-system.ts`, and hold only a proof-system candidate. Both gates and `lane --json` live in `scripts/proof-system-lane.ts`; neither lists a glob. @@ -1385,8 +1385,8 @@ glob. the run found at each squash it read, and says `1 more green main run required`. `bun scripts/integrate.ts lane --json` prints the same decision (`state`, `ownGreen`, `required`, `window`, `decisive`) with that refusal, - or `null` when the lane is open. `confirm` checks before it takes the - reservation or requests candidate CI, and the merge checks again, because a + or `null` when the lane is open. `acquire` and `confirm` check before taking the + reservation or requesting candidate CI, and the merge checks again, because a main run may fail while the candidate is proved. - **Off-main qualification** ([#3271](https://github.com/schlessera/brain-kit/issues/3271), answer 3). The PR body needs an `Off-main qualification` heading whose @@ -1841,6 +1841,9 @@ PRs below. changesets and affected fast invariants); - main is not red; - it holds the merge lease, so that it does not race a confirmation. + `integrate.ts acquire` enforces the proof-system stability window and + off-main qualification before taking that lease, with the same declared + red-main fix exemption as `confirm`. The fast lane skips neither gate. - **What it relies on.** Draft CI runs only the metadata gates, so a fast-lane PR reaches main with no hosted unit run before the merge. Its local receipt and the squash's own main run, which proves every affected diff --git a/scripts/integrate.ts b/scripts/integrate.ts index 1af166b418..c80b2e92ff 100644 --- a/scripts/integrate.ts +++ b/scripts/integrate.ts @@ -396,7 +396,8 @@ if (import.meta.main) { if (lost) throw lost; } else { // Before any lease or candidate CI: a closed lane would refuse the merge anyway. - if (command === "confirm") { await refuseProofSystemLane(desired, fixesRun); await contractPassed(desired); } + await refuseProofSystemLane(desired, fixesRun); + if (command === "confirm") await contractPassed(desired); own = await acquire(desired); // Only an explicit acquire prints the holder token, once; confirm keeps it in memory. console.log(JSON.stringify(command === "acquire" ? { acquired: own, token } : { acquired: own })); diff --git a/tests/integration-command.test.ts b/tests/integration-command.test.ts index 9b38715056..3bb6c9001a 100644 --- a/tests/integration-command.test.ts +++ b/tests/integration-command.test.ts @@ -98,14 +98,14 @@ async function runScenario(mode: string, owner: Scenario): Promise kind === "holder" ? ["--token", TOKEN] : kind === "wrong" ? ["--token", OTHER] : []; if (mode === "renew-push-fail") writeFileSync(failPush, "1"); - const command = mode.startsWith("lane-") && mode.endsWith("-read") ? ["lane", "--json"] : mode === "acquire" ? ["acquire", "7"] : mode === "renew-push-fail" ? ["renew", id, "--token", TOKEN] : lifecycle ? [lifecycle[1]!, id, ...presented(lifecycle[2]!)] + const command = mode.startsWith("lane-") && mode.endsWith("-read") ? ["lane", "--json"] : mode.startsWith("acquire") ? ["acquire", "7"] : mode === "renew-push-fail" ? ["renew", id, "--token", TOKEN] : lifecycle ? [lifecycle[1]!, id, ...presented(lifecycle[2]!)] : [mode.startsWith("confirm-") ? "confirm" : "merge", "7", ...(mode.startsWith("confirm-") ? [] : ["--lease", mode === "wrong-id" ? "2".repeat(32) : id, ...presented(mode === "no-token" ? "none" : mode === "wrong-token" ? "wrong" : "holder")]), ...(delivered.length ? ["--issues", delivered.join(",")] : []), ...(mode.startsWith("expedite-") ? ["--fixes-main-run", "11"] : [])]; @@ -684,3 +684,26 @@ test("declared red-main fixes are exempt from the stability window and off-main expect(fix.dispatched).toBe(true); } }); + +test("acquire enforces the proof-system lane before taking a reservation (#4178)", async () => { + for (const [mode, message] of [ + ["acquire-lane-own-busy", "has no settled main run of its own yet"], + ["acquire-lane-open-unqualified", 'no "Off-main qualification" section'], + ] as const) { + const result = await scenario(mode); + expect(result.code, `ACQUIRE_REFUSES_PROOF_SYSTEM_CANDIDATE:${mode}: ${result.err}`).toBe(1); + expect(result.err).toContain("Proof-system candidate refused (scripts/ci-shards.ts)"); + expect(result.err).toContain(message); + expect(result.state.last, `ACQUIRE_REFUSES_BEFORE_RESERVATION:${mode}`).toBeNull(); + expect(result.requested).toBe(false); + expect(result.dispatched).toBe(false); + } + for (const mode of ["acquire-lane-open", "acquire-lane-own-red-unqualified-product", "acquire-red-main-fix-lane-own-red-unqualified"]) { + const result = await scenario(mode); + expect(result.code, `ACQUIRE_ACCEPTS:${mode}: ${result.err}`).toBe(0); + expect(result.state.active?.candidate.pr).toBe(7); + expect(JSON.parse(result.out).token).toMatch(/^[a-f0-9]{64}$/); + expect(result.requested).toBe(false); + expect(result.dispatched).toBe(false); + } +});