Skip to content
Merged
5 changes: 4 additions & 1 deletion .agents/skills/work-issue/references/ci-and-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,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 <merge-base>
--head <head>`) waits its turn in the proof-system lane. `confirm` (before
--head <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
Expand Down Expand Up @@ -381,6 +381,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 <pr>` (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).
Expand Down
11 changes: 7 additions & 4 deletions docs/decisions/ci-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -1365,8 +1365,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.
Expand All @@ -1393,8 +1393,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
Expand Down Expand Up @@ -1862,6 +1862,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
Expand Down
3 changes: 2 additions & 1 deletion scripts/integrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down
31 changes: 27 additions & 4 deletions tests/integration-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ async function runScenario(mode: string, owner: Scenario): Promise<ScenarioResul
setup(root, "push", "origin", `${base}:refs/heads/main`, `${synthetic}:refs/heads/proof-fixture`, `${squash}:refs/heads/squash-fixture`);
const candidate = { repository: "https://github.com/odysseus/brain-kit", pr: 7, head, base };
const id = "1".repeat(32), store = new GitReservationStore(root), snapshot = store.read();
const state = mode === "missing" || mode === "acquire" || mode.startsWith("confirm-") ? emptyReservation() : reservationTransition(emptyReservation(), { kind: "acquire", candidate, id, ...(mode.startsWith("legacy-") ? {} : { token: TOKEN }) }, mode === "wrong-owner" ? 202 : 101, mode === "expired" ? NOW - 300_000 : NOW);
const state = mode === "missing" || mode.startsWith("acquire") || mode.startsWith("confirm-") ? emptyReservation() : reservationTransition(emptyReservation(), { kind: "acquire", candidate, id, ...(mode.startsWith("legacy-") ? {} : { token: TOKEN }) }, mode === "wrong-owner" ? 202 : 101, mode === "expired" ? NOW - 300_000 : NOW);
expect(store.publish(snapshot, state)).toBe(true);
if (mode.startsWith("red-main") || mode.startsWith("expedite-")) {
if (mode.includes("red-main") || mode.startsWith("expedite-")) {
const failure = { test: mode === "expedite-category" ? null : "tests/raft.test.ts", category: mode === "expedite-category" ? "browser" as const : "unit" as const,
verdict: "real" as const, reasons: ["in-affected-closure"], run: 11, sha: base };
// A sibling squash of the base is red on another line: the candidate's merge ref does not contain it.
const red = openRed(emptyRedMain(), { firstBad: mode === "red-main-unrelated" ? squash : base, run: 11, failures: [failure] }, NOW);
expect(store.publishRedMain(store.read(), mode.startsWith("red-main-fix") ? declareFix(red, 7, NOW) : red)).toBe(true);
expect(store.publishRedMain(store.read(), mode.includes("red-main-fix") ? declareFix(red, 7, NOW) : red)).toBe(true);
}
const sentinel = join(dir, "merged"), apiState = join(dir, "api.json");
writeFileSync(apiState, JSON.stringify({ mode, revoked: false, merged: false, now: NOW, requested: false, draft: false }));
Expand Down Expand Up @@ -266,7 +266,7 @@ fi`);
const lifecycle = /^(?:legacy-)?(renew|release)-(holder|none|wrong)$/.exec(mode);
const presented = (kind: string) => 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"] : [])];
Expand Down Expand Up @@ -691,3 +691,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);
}
});
Loading