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
4 changes: 3 additions & 1 deletion .agents/skills/work-issue/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ nonpassing final gate. Before `confirm`, run `bun scripts/collisions.ts --json -
and record its collisions (or none) with the PR head in the PR. For ordinary candidates, acquire the exact-candidate integration reservation
with `bun scripts/integrate.ts confirm <pr> --issues owner/repo#N,...` before
requesting expensive confirmation; it handles the draft-to-ready transition,
minute renewal and shared proof-checked merge. Hold competing confirmation and
minute renewal and shared proof-checked merge. The PR body must carry the
`check:pr` receipt; skipped or timed-out local checks need exact-head hosted
coverage. A declared red-main fix may use `--fixes-main-run <run-id>`. Hold competing confirmation and
main merges while another lease is live. See the CI reference for explicit
acquire/renew/release/revoke, expiry, hard cap and unsupported native candidates.
After the last push, convert to draft and mark ready under that reservation to
Expand Down
16 changes: 16 additions & 0 deletions .agents/skills/work-issue/references/ci-and-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ actor/time/reason and immediately removes the old authority without waiving
proof. Native candidates need separately qualified prefix integration; this
ordinary command rejects them. See the [binding decision](../../../../docs/decisions/ci-utility.md#exact-candidate-integration-reservation).

The merge path also reads the `check:pr` receipt from the PR body. It refuses
a PR with no receipt (`confirm` says so before acquiring), and one whose
skipped, timed-out or preempted checks map to hosted categories the exact-head
proof did not run, naming each. Rerun the check locally and paste the new
receipt, or get the category selected; never edit a receipt by hand
([local check receipts](../../../../docs/decisions/ci-utility.md#local-check-receipts)).

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
that must show the record's failing test files red on the exact base and green
on the exact head, waits for the exact-head fast invariants and squashes under
the reservation. It refuses category-level failures; use ordinary confirmation
for those. Never merge a red-main fix any other way
([expedited red-main fixes](../../../../docs/decisions/ci-utility.md#expedited-red-main-fixes)).

While main is red, `confirm` and `merge` refuse every PR that is not a
declared fix, and hosted proof containing the bad commit is refused or
cancelled. Do not retry it; follow [the red-main incident steps](red-main.md)
Expand Down
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ bun run check:pr --base origin/main
tested parent/head/checkout and selected proof; see
docs/process/github.md#stacked-pull-requests. -->

<!-- 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,
timed-out or preempted checks map to a hosted category its exact-head
proof did not run (docs/decisions/ci-utility.md#local-check-receipts). -->
<!-- brain-check-pr-receipt:start -->
<!-- brain-check-pr-receipt:end -->

## Checklist

- [ ] Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof.
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/red-main-probe.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Triage probe for the red-main coordinator (#2942). Reruns only the named test
# files at one SHA. A probe never counts as proof and never makes anything
# mergeable; the coordinator reads its result to decide whether main is red.
# files at one SHA. A flake or bisect probe never counts as proof and never makes
# anything mergeable; the coordinator reads its result to decide whether main is
# red. A fix probe is the expedited fix evidence `integrate.ts --fixes-main-run`
# reads (#2940): red at the bad base, green at the fix head. The coordinator
# ignores it.
name: red-main-probe
run-name: red-main probe ${{ inputs.purpose }} ${{ inputs.source_run }} ${{ inputs.sha }}

on:
workflow_dispatch:
inputs:
purpose:
description: flake or bisect
description: flake, bisect, or fix (expedited red/green evidence for integrate.ts, #2940)
required: true
type: choice
options: [flake, bisect]
options: [flake, bisect, fix]
source_run:
description: The main CI run whose failure is triaged
required: true
Expand Down Expand Up @@ -63,4 +66,5 @@ jobs:
timeout-minutes: 30
env:
PROBE_TESTS: ${{ inputs.tests }}
PROBE_PURPOSE: ${{ inputs.purpose }}
run: bun tooling/scripts/red-main-cli.ts probe --target target
93 changes: 88 additions & 5 deletions docs/decisions/ci-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Local import-graph feedback uses eight workers on the measured 32-CPU,
47-GiB host. The default is
`max(1, min(floor(cores / 4), floor(RAM * 0.7 / 2 GiB)))`, with
`--import-graph-workers=N` as the override (`localUnitWorkerCount`,
`scripts/unit-workers.ts:15-17`). Changed-mode workers use one fresh prepared
`scripts/unit-workers.ts:16-18`). Changed-mode workers use one fresh prepared
build and private overlay views; `unit-workers --private-tree` retains the
ordinary private-build comparison. Hosted explicit-file partitions retain
`balanceTests`, their private builds and N=2.
Expand Down Expand Up @@ -1336,7 +1336,13 @@ claimed as completion. Failures exit 1, with best-effort owned cleanup.

This is mandatory cooperative procedure, not an atomic GitHub branch lock.
Direct API/UI merges under existing permissions can bypass it or race the
final read; actual squash checks still own reconciliation. No protection,
final read; actual squash checks still own reconciliation. The
[#2940 investigation](https://github.com/schlessera/brain-kit/issues/2940#issuecomment-6574325914)
found 157 merges from 2026-10-22 to 2026-10-26 that bypassed it, and every
merge since 2026-10-26T23:44Z under an exact-head lease. So that a bypass is
visible rather than inferred, `scripts/ci-timings.ts` reports each merged PR's
merge path (`recorded`, `expedited`, `unrecorded` or `unknown`) from the
reservation history and the expedited-fix events. No protection,
permission, provider or native merge-queue change is introduced. Native stack
candidates remain unsupported by this command pending separately qualified
prefix integration; do not flatten them into an ordinary receipt or bypass
Expand Down Expand Up @@ -1478,7 +1484,7 @@ main run that printed the same open record as included. The first step of a
non-draft PR run refuses with `main red at <sha>, incident #<n>` when its merge
ref contains the bad commit and the PR is not a declared fix. Draft runs keep
their cheap gates. One ancestry rule decides every refusal and cancellation
(`gateDecision`, `scripts/red-main.ts:209-216`): proof is doomed only when the
(`gateDecision`, `scripts/red-main.ts:223-230`): proof is doomed only when the
tree it tests contains the bad commit and its PR is not a declared fix
([#3321](https://github.com/schlessera/brain-kit/issues/3321)). The coordinator
cancels a queued or running PR proof run only when its PR's base or head, as
Expand All @@ -1488,7 +1494,7 @@ GitHub did not record, or whose ancestry cannot be determined, is left alone.
So proof for a PR against an integration or release branch forked before the
bad commit keeps running. `integrate.ts` applies the same rule to the
candidate's base and head before confirming or merging, and refuses when
ancestry is unknown (`refuseWhileRed`, `scripts/integrate.ts:62-66`). A non-fix squash
ancestry is unknown (`refuseWhileRed`, `scripts/integrate.ts:64-68`). A non-fix squash
that lands while red is reported once on its PR and on the incident, and
recorded as an `incident` event through `scripts/ci-timings.ts record` in the
coordinator's `red-main-events` artifact.
Expand All @@ -1499,7 +1505,84 @@ runs, dispatch probes, read logs and artifacts), `issues: write` (incident and
flake issues) and `pull-requests: write` (landed-while-red reports). It runs
trusted default-branch tooling and parses candidate logs and artifacts as data.
`red-main-probe.yml` has `contents: read` only. The incident workflow in the
skills is #2944, and the expedited fix merge is #2940.
skills is #2944, and the expedited fix merge is #2940
([below](#expedited-red-main-fixes)). The probe's `fix` purpose serves only
that merge; the coordinator ignores fix probes.

### Expedited red-main fixes

[#2940](https://github.com/schlessera/brain-kit/issues/2940) implements answer 7
of the proof-system lane ruling. `bun scripts/integrate.ts confirm <pr>
--fixes-main-run <run-id> --issues owner/repo#N,...` requires an open red-main
record whose opening run is `<run-id>`, declares the PR a fix and acquires the
ordinary exact-candidate reservation. It then dispatches `red-main-probe.yml`
with purpose `fix` and the record's failing test files twice: at the exact
base, where they must fail, and at the exact head, where they must pass. Each
probe prints one `BRAIN_RED_MAIN_PROBE` line with its SHA, the files it ran and
its exit code; the merge reads that line, not only the run conclusion, so a
probe that failed during setup is not red evidence. The command also requests a
fresh ready run of `ci.yml` at the exact head and waits only for its metadata
gate and `verify` job: the affected fast invariants. It does not wait for the
rest of that run. When all three are in, it squashes under the reservation with
the same live-candidate, lease, milestone, parent and ancestry checks as an
ordinary merge; the expected tree is the exact base merged with the exact head.
`merge <pr> --lease <id> --fixes-main-run <run-id>` does the same with evidence
that already exists.

It refuses a run that is not the open record's, any category-level failure
(no test file to show red and green: use ordinary confirmation as a declared
fix), evidence for other SHAs or other files, a base that did not fail, a head
that did not pass, a draft-cadence run and failed fast invariants. A failing
test file may be absent at the head only when the fix deletes it relative to
the base, which is how a targeted revert removes the failing test its reverted
commit added; a revert is otherwise held to the same evidence as a forward fix.
The local check receipt is not required in this mode: the ruling defines the
expedited proof, and the next main run is the backstop.

After the squash it appends an `expedited` entry to the open record (fix PR,
head, base, squash, both probe runs, the fast-invariant run, the numeric actor
ID and server time) and records an `expedited-fix` event through
`scripts/ci-timings.ts record` under `tmp/ci-timings`. The record stays open:
the next main run includes the red set, and only its green result clears the
record. A new failure there opens a new incident. No controller merges a fix
by itself.

### Local check receipts

`check:pr` writes `tmp/check-pr-receipt.json` (`--receipt <path>` overrides
it) and prints it at the end as a block for the PR body; the PR template holds
its markers. The receipt names the head, the base ref and mode, and every
selected check with the hosted categories that prove it and one outcome:
`passed`, `failed`, `skipped`, `timed-out` or `preempted`. It is rewritten
after every change, and a started check reads `timed-out` until it settles, so
a run killed from outside still leaves an honest receipt.

- `--check-timeout=<seconds>` gives each check a budget. A check that exceeds
it is killed with its process group and recorded `timed-out`; the run goes
on. A signal to `check:pr` records the running check `timed-out` and the
rest `skipped`.
- `--skip <check name>` records a deliberate skip instead of an unrecorded one.
- `preempted` is a check that exited with status 75, host admission's
cancellation ([#2943](https://github.com/schlessera/brain-kit/issues/2943)).
It is neither checked nor failed: `check:pr` exits 75 so it is rerun.
- A failure still stops the run and exits 1; later checks read `skipped`.
Timed-out and skipped checks alone exit 0 with a warning, because the merge
path enforces them.

`integrate.ts merge` maps each skipped, timed-out or preempted check to its
hosted categories and refuses the candidate when none of them ran successfully
in the exact-head selected proof, naming every such check and the categories it
needs. A category retained by validated proof reuse counts as run. The metadata
gate always runs, so lint, leakage and changeset checks are always covered; an
unknown check maps to no category and can never be covered.

A PR body with no receipt, or only the template's empty markers, is refused.
`confirm` checks this before it acquires the reservation or requests proof, so
an in-flight PR learns it at once, with the command that fixes it, and never
after a full hosted run. Running `check:pr` and pasting its block is the whole
remedy. The receipt's head is recorded but need not equal the candidate's:
skips are a property of the local run, and coverage is judged against the
exact-head proof.

#### Incident workflow and recovery

Expand Down
8 changes: 7 additions & 1 deletion docs/process/ci-throughput.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ execution. It is not complete lifetime cost without complete lifetime coverage.
| CI concurrency | Time-weighted executed-job overlap, peak and means while active/across the interval. Adjacent end-exclusive intervals do not invent overlap. |
| PR verification concurrency | Distinct PRs with verification intervals, merging overlapping attempts of one PR. Includes queueing; not active agent count. |
| Reservation occupancy | Authorized lease intervals, including inferred expiry. Time without observed candidate jobs includes queue/admission/verification and missing observations; not proven waste. |
| Merge path | Per merged PR: `recorded` when the reservation history holds an `integrate.ts` lease for the merged head, `expedited` when an `expedited-fix` event names the PR, `unrecorded` when neither (a merge that bypassed `integrate.ts`), `unknown` when no reservation history was collected (`--reservations`). |

Means, medians, p90 and sample counts accompany durations. First-main failing
job categories and supplied failure classifications help distinguish pipeline
Expand Down Expand Up @@ -94,6 +95,8 @@ ID/time permit attributed historical observations. IDs cannot be overwritten
with different content. Pairs are `work-started`/`work-finished` and
`wait-started`/`wait-finished`; waits require `reason` set to `reservation`,
`ci`, `review`, `conflict` or `other`. Each pair shares worker/task/reason.
Host admission records each wait for a heavy local slot as a pair with reason
`other` and task `admission-<slot>` ([host admission](testing.md#host-admission-for-heavy-local-commands)).
Unmatched records remain unknown; overlapping tasks on one worker do not create
two workers. Complete task intervals measure task lifetime, not CPU busy time
or token cost. No records means unknown worker concurrency. This endpoint does
Expand All @@ -103,7 +106,10 @@ preserve every worker's archive, including unsuccessful/unmerged work.
`failure-classified` requires run, attempt, classification (`product`, `test`,
`infrastructure`, `stale-candidate`, `intentional-feedback`) and public repository
evidence. `incident`/`revert` require affected `pr` and evidence; `relatedPR` can
name a repair/revert. These are supplied annotations, not independently verified
name a repair/revert. `expedited-fix` requires the fix `pr`, the failing main
`run` and evidence (the head fix probe run); `integrate.ts --fixes-main-run`
records it after an expedited squash
([#2940](../decisions/ci-utility.md#expedited-red-main-fixes)). These are supplied annotations, not independently verified
diagnoses. No incident surveillance means unknown overall incident rate.
Arbitrary fields such as prompts, names, hosts and prose are refused. Keep event
files with normalized snapshots under ignored `tmp/`, not in the public tree.
Expand Down
Loading
Loading