Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .agents/skills/work-issue/references/ci-and-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ Refresh a reviewed branch by merging `origin/main` and pushing. A rebase
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
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
failure the next green main run reopens it. They also refuse it until its PR
body has an `## Off-main qualification` section linking a replay or dispatch
run on the exact head, or on an ancestor with no proof-system change after it.
Read the window with `bun scripts/integrate.ts lane --json` instead of polling
runs; product candidates and declared red-main fixes are never held
([proof-system lane](../../../../docs/decisions/ci-utility.md#lane-and-qualification-gates)).

While main is red, a declared fix for the open record, forward fix or
targeted revert alike, may use `bun scripts/integrate.ts confirm <pr>
--fixes-main-run <run-id> --issues owner/repo#N,...`. It dispatches fix probes
Expand Down
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ bun run check:pr --base origin/main
tested parent/head/checkout and selected proof; see
docs/process/github.md#stacked-pull-requests. -->

<!-- Proof-system PRs only (bun scripts/proof-system.ts classify): keep the
next heading and fill it in; otherwise delete it. Name the replay or
dispatch run URLs, the head SHA they ran on and the comparison they
establish. The merge path refuses a proof-system PR without a linked run
on the head, or on an ancestor with no proof-system change after it;
declared red-main fixes are exempt
(docs/decisions/ci-utility.md#lane-and-qualification-gates). -->
### Off-main qualification

<!-- check:pr prints its receipt block at the end of every run. Replace the
two markers below with that block, keeping one receipt only. The merge
path refuses a PR with no receipt, and refuses one whose skipped,
Expand Down
44 changes: 44 additions & 0 deletions docs/decisions/ci-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,50 @@ Each implementation task is tracked separately:
([fields](../process/ci-throughput.md#proof-policy-epochs));
- off-main qualification evidence: [#3271](https://github.com/schlessera/brain-kit/issues/3271).

#### 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
`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.

- **Stability window** ([#3269](https://github.com/schlessera/brain-kit/issues/3269),
answers 1 and 2, as
[amended to a single run](https://github.com/schlessera/brain-kit/issues/2938#issuecomment-6580707195)).
The last proof-system squash is the newest first-parent main commit, within
200, whose diff to its parent classifies as one. Each squash's run is the
newest main-push `ci.yml` run at that SHA. A run has settled once it has
completed, and a squash with no run has settled once a later squash exists,
because it never gets one; a queued or in-progress run, or no run yet at the
newest squash, has not. The squash's own run must settle first. The lane is
then open when the newest settled run from that squash on is green, and
closed when it failed, was cancelled or timed out, or never existed. So the
own green run opens the lane without waiting for later runs, and after any
failure the next green main run reopens it. That includes a failed own run:
a rerun at a squash that broke main would stay red, and the decision is
"if a main run fails, the lane reopens at the next green main run". No
rerun or revoke is needed. The check reads the own run, then later squashes
newest first, and stops at the first settled one: at most ten main runs. If
all nine later runs it reads are unsettled and older squashes were not read,
the lane is `unknown` and refused. The refusal names the blocking squash and
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
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
section, outside HTML comments, links a GitHub Actions run of this
repository whose head SHA is the candidate head, or an ancestor of it whose
diff to the head is not a proof-system change. At most five linked runs are
read. Whether the evidence is sufficient stays a review question.
- **Exemption.** A declared red-main fix skips both gates: one merged with
`--fixes-main-run`, and one declared on the open record and confirmed
ordinarily because its failures are category-level. A fix that had to
wait for the window it repairs could never land.

### Red-main record and coordinator

The [2026-10-25 red-main and coordination decisions](https://github.com/schlessera/brain-kit/issues/2934#issuecomment-6402400614)
Expand Down
48 changes: 45 additions & 3 deletions scripts/integrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { expeditedProblems, expeditedTests, fixProbeTitle, probeReceipt, type Fe
import { receiptFromBody, receiptRefusal } from "./check-receipt";
import { reviewGate } from "./review-receipt";
import type { API } from "./proof-api";
import { classify } from "./proof-system";
import { checkQualification, laneRefusal, readLane, type MainRun } from "./proof-system-lane";

/**
* A refusal no retry can cure: the candidate changed or the reservation no longer
Expand Down Expand Up @@ -112,6 +114,38 @@ if (import.meta.main) {
if (child.exitCode !== 0) throw new Error(new TextDecoder().decode(child.stderr).trim());
} catch (error) { console.error(`Expedited fix merged but its record is incomplete; record it by hand: ${String(error)}`); }
}
function ensureCommit(sha: string) {
if (Bun.spawnSync(["git", "cat-file", "-e", `${sha}^{commit}`], { cwd: store!.root }).exitCode !== 0) store!.git(["fetch", "origin", sha]);
}
/** The main-push CI run at one squash: the newest of at most ten, one API read. */
async function mainRunAt(sha: string): Promise<MainRun | null> {
const runs = (await api.json(`actions/workflows/ci.yml/runs?event=push&branch=main&head_sha=${sha}&per_page=10`)).workflow_runs ?? [];
const run = runs.filter((r: any) => r.head_sha === sha).sort((a: any, b: any) => b.id - a.id)[0];
return run ? { id: run.id, status: run.status, conclusion: run.conclusion ?? null } : null;
}
/**
* Proof-system lane (#3269, #3271): a proof-system candidate needs off-main qualification on the PR
* and an open stability window. Product candidates are never refused here. A declared red-main fix,
* expedited or confirmed ordinarily, is exempt: a fix that waited for the window it repairs could never land.
*/
async function refuseProofSystemLane(desired: Candidate, fixesRun: number | undefined) {
if (fixesRun !== undefined || store!.read().redMain.open?.fixes.includes(desired.pr)) return;
for (const sha of [desired.base, desired.head]) ensureCommit(sha);
const from = store!.git(["merge-base", desired.base, desired.head]);
const candidateClass = classify(from, desired.head, { cwd: store!.root });
if (!candidateClass.proofSystem) return;
const problems: string[] = [];
const qualification = await checkQualification({ body: (await api.json(`pulls/${desired.pr}`)).body, repository, head: desired.head, cwd: store!.root, ensure: ensureCommit,
async readRun(id) {
const run = await api.json(`actions/runs/${id}`).catch(() => null);
return run ? { id, headSha: run.head_sha ?? null, repository: run.repository?.full_name ?? null } : null;
} });
if ("refusal" in qualification) problems.push(qualification.refusal);
const lane = laneRefusal(await readLane(desired.base, mainRunAt, { cwd: store!.root }));
if (lane) problems.push(lane);
const paths = [...new Set(candidateClass.reasons.map(reason => reason.path))].join(", ");
if (problems.length) throw new Error(`Proof-system candidate refused (${paths}): ${problems.join(". ")}`);
}
/** One renewal tick: a transient failure is logged and retried next tick until the safety margin (#3302). */
async function tick() {
if (lost) return;
Expand Down Expand Up @@ -224,6 +258,8 @@ if (import.meta.main) {
// Read again here: a review posted while the candidate was being proved is the newest record.
const unreviewed = await reviewRefusal(desired);
if (unreviewed) throw new Error(unreviewed);
// Read again here too: a main run may have failed while the candidate was being proved.
await refuseProofSystemLane(desired, fixesRun);
tree = proof.checkout.tree; candidateRun = proof.run;
} else {
expedited = await expeditedEvidence(desired, fixesRun, after);
Expand Down Expand Up @@ -274,7 +310,12 @@ if (import.meta.main) {
store = new GitReservationStore(process.cwd());
const remote = store.git(["remote", "get-url", "origin"]).replace(/^git@github.com:/, "https://github.com/").replace(/\.git$/, "");
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository) || remote !== `https://github.com/${repository}`) throw new Error("Authenticated repository and origin differ");
if (command === "main-status") {
if (command === "lane") {
if (target !== "--json" || options.length) throw new Error("usage: bun scripts/integrate.ts lane --json");
store.git(["fetch", "origin", "main"]);
const decision = await readLane(store.git(["rev-parse", "FETCH_HEAD"]), mainRunAt, { cwd: store.root });
console.log(JSON.stringify({ ...decision, refusal: laneRefusal(decision) }));
} else if (command === "main-status") {
if (target !== undefined && target !== "--json") throw new Error("usage: bun scripts/integrate.ts main-status [--json]");
const snapshot = store.read();
console.log(JSON.stringify({ red: snapshot.redMain.open !== null, source: snapshot.oid, record: snapshot.redMain }));
Expand Down Expand Up @@ -354,7 +395,8 @@ if (import.meta.main) {
}
if (lost) throw lost;
} else {
if (command === "confirm") await contractPassed(desired);
// Before any lease or candidate CI: a closed lane would refuse the merge anyway.
if (command === "confirm") { await refuseProofSystemLane(desired, fixesRun); 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 Expand Up @@ -385,7 +427,7 @@ if (import.meta.main) {
if (lost) throw lost;
}
}
} else throw new Error("usage: bun scripts/integrate.ts inspect | main-status [--json] | declare-fix <pr> | acquire/confirm/merge <pr> [--lease id --token token] [--issues owner/repo#N,...] [--fixes-main-run <run-id>] | renew/release <id> [--token token] | revoke <reason>");
} else throw new Error("usage: bun scripts/integrate.ts inspect | main-status [--json] | lane --json | declare-fix <pr> | acquire/confirm/merge <pr> [--lease id --token token] [--issues owner/repo#N,...] [--fixes-main-run <run-id>] | renew/release <id> [--token token] | revoke <reason>");
} catch (error) {
console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1;
} finally {
Expand Down
Loading
Loading