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
16 changes: 16 additions & 0 deletions .agents/skills/work-issue/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,22 @@ type/area/`contract` labels; do not copy readiness labels onto the PR.
monitor actual completion. Do not ask again for permission included in
the end-to-end request.

## Main is red

When any command prints `main red at <sha>` (the hosted gate, a cancelled
proof run or an `integrate.ts` refusal), or `bun scripts/integrate.ts
main-status --json` reports `"red": true`, follow
[the red-main incident steps](references/red-main.md). In short: stop
requesting proof for non-fix PRs; find the one incident issue named in the
record and link duplicates there; try `bun scripts/red-main-incident.ts claim`
— exactly one orchestrator wins it; the claimant assesses the cause, records
its choice of a fix PR or a targeted revert PR (or explicit uncertainty) with
the rationale, declares the PR and merges it through the normal route;
everyone else posts evidence with `bun scripts/red-main-incident.ts evidence`.
Keep coding and running fast checks meanwhile, and resume proof when
`main-status` reports green. Never open a second incident. This does not end
or replace work on your own claimed issue.

## Finish or hand off

For a stack, the actor merging it owns closure reconciliation for **every
Expand Down
7 changes: 7 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,13 @@ 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).

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)
and resume when `main-status` reports green. A fix or targeted revert PR for
the incident is declared with `bun scripts/integrate.ts declare-fix <pr>` and
then uses this same reservation and merge procedure.

## Merge and verify

Before every merge, assign the PR and each completed/advanced issue a release
Expand Down
139 changes: 139 additions & 0 deletions .agents/skills/work-issue/references/red-main.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Main is red: work the incident

Read this when any command prints `main red at <sha>` — the hosted gate on
your PR's proof, a cancelled proof run, or `bun scripts/integrate.ts`
refusing `confirm`/`merge` — or when `main-status` reports `"red": true`.
The binding rules are in
[the CI decision](../../../../docs/decisions/ci-utility.md#red-main-record-and-coordinator).

Every orchestrator notices the same red main. Coordination goes only through
the red-main record and the one incident issue the coordinator filed; never
message other agents and never open a second incident.

## Identities

- **Worker ID**: the claim token of the issue you are working
(`wi-<date>-<random>`). A worker with no claimed issue makes a fresh token.
- **Orchestrator ID**: a stable random token for your orchestrator session,
such as `orch-<random>`, reused by every worker it runs.

Both are opaque tokens (`[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}`), written to the
public coordination ref and incident: never a hostname, path, account or
person's name.

## Detect

1. Read `bun scripts/integrate.ts main-status --json` at most every 15
minutes while you hold work that needs proof, and immediately after any
`main red at <sha>` message. Never tight-poll.
2. `red: false` means there is nothing to do here. `record.open` is the
incident: `firstBad`, `failures`, `incident` (issue number or `null`),
`fixes` (declared PRs) and `claim`.
3. `incident: null` means the coordinator has not filed the issue yet. Do not
file one. Keep working (see **Wait and resume**) and read again later.

## Stop doomed proof

4. Do not request proof, `confirm` or `merge` for a PR that is not a declared
fix while main is red. Do not rerun refused or cancelled proof. Your own
issue stays claimed and its branch stays yours.

## Find and deduplicate

5. Open the incident issue named in the record and read its body and every
comment, newest last, before doing anything else.
6. Search open issues for each failing test path. Link any other open issue
for the same failure on the incident instead of filing a new one:

```sh
bun scripts/red-main-incident.ts evidence --worker <w> --orchestrator <o> \
--kind duplicate --issue <n> --summary "<one line>"
```

Use `--kind related --issue <n>` for an issue that is related but not the
same failure.

## Claim the fix, or contribute

7. If `record.open.claim` is absent, `null` or expired, try to claim it:

```sh
bun scripts/red-main-incident.ts claim --worker <w> --orchestrator <o>
```

The claim is written into the record by compare-and-swap, so exactly one
concurrent claimant wins. The winner is mirrored to the issue's assignment
and a claim comment; taking over an expired claim posts a takeover comment
naming the previous claimant.
8. `Fix claimed by worker … until …` means someone else owns the fix. You are
a contributor: go to step 12.
9. As claimant, renew before the term ends (one hour from the last renewal),
for example with every push or every 30 minutes:
`bun scripts/red-main-incident.ts renew --worker <w> --orchestrator <o>`.
If you stop owning the fix, `release` it so the next orchestrator can claim
it without waiting for expiry.

## Claimant: assess, choose, record

10. Make a quick assessment, then choose a **fix PR** or a **targeted revert
PR**. Decide from causal and current-tree evidence: a bisect or probe that
reproduces at the first bad SHA and passes at its parent, a reproduction
on current main, the failing assertion and the change that reaches it. A
red check or the latest squash alone is not proof of cause. Assess what
depends on or conflicts with the suspect change: a revert must preserve
unrelated and later good work, so revert only the causal change and only
when later squashes do not build on it. When neither change is
supportable yet, say so and keep gathering evidence; do not guess.
11. Record the choice and its rationale on the incident before opening the PR:

```sh
bun scripts/red-main-incident.ts evidence --worker <w> --orchestrator <o> \
--kind decision --choice fix|revert|uncertain --sha <first-bad> \
--summary "<one line>" --details-file <rationale.md>
```

The details file states the cause evidence, the dependency and conflict
assessment and, for `uncertain`, what evidence is still missing.
Then open the PR against `main` with `Refs #<incident>`, and declare it,
whether it is a fix or a revert:
`bun scripts/integrate.ts declare-fix <pr>`. It then follows the normal
route — required review, `check:pr`, hosted candidate proof, the
collisions check and `bun scripts/integrate.ts confirm <pr> --issues …` —
through the declared-red-main-fix path. Nothing merges it automatically,
and a failed fix gets a new assessment and decision comment, not a retry
loop. After the squash lands, read the main run that includes the failing
set: only its green result clears the record. Record the merged SHA and
that run on the incident as the exact recovery proof.

## Everyone: add evidence

12. Post what you learn in the fixed format, one comment per finding:

```sh
bun scripts/red-main-incident.ts evidence --worker <w> --orchestrator <o> \
--kind reproduction|bisect|log|ruled-out|fix-attempt \
--summary "<one line>" [--sha <sha>] [--details-file <file>]
```

Kinds: `reproduction` (reproduced or not, at which SHA), `bisect` (probe
results), `log` (an excerpt with a link to the run), `ruled-out` (a
hypothesis eliminated, and how), `fix-attempt` (an alternative change you
tried). Read existing evidence first and do not repeat it. The command
refuses while the incident is pending and never files an issue.
13. A contributor may also open an alternative declared fix PR when the
claimant's approach stalls; it names the incident and follows the same
route. Add a `fix-attempt` evidence comment linking it.

Add `--dry-run` to any command above to print the writes instead of sending
them.

## Wait and resume

14. While red, a worker whose proof was refused or cancelled keeps working
without proof: code, `bun run test <files>`, `bun run check:pr`, review
fixes, or evidence on the incident. Do not release your own issue's claim
because main is red.
15. Resume proof when `main-status` reports `red: false`: rebase only if your
change requires it, then request candidate confirmation as usual. A
claimant whose fix merged releases nothing extra: clearing the record
removes the claim.
74 changes: 74 additions & 0 deletions docs/decisions/ci-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,55 @@ 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.

#### Incident workflow and recovery

[#2944](https://github.com/schlessera/brain-kit/issues/2944) is how
orchestrators work the incident, following the 2026-10-25 direction that they
work it like any other issue. All coordination goes through the record and
the incident issue; agents never message each other.

- **One fix claim, written atomically.** `bun scripts/red-main-incident.ts
claim` writes `open.claim` into `red-main.json` through the same
compare-and-swap: the claimant's worker and orchestrator IDs (opaque
tokens), when it claimed and last renewed, and an expiry one hour after the
last renewal. Exactly one concurrent claimant wins. The claim is then
mirrored to the issue's assignment and a claim comment; a rerun mirrors it
once. `renew` extends the term and `release` drops it. An expired claim may
be taken over: the new claim keeps the expired claimant in `takeover`, and a
takeover comment names it on the issue. Clearing the record removes the
claim. Records written before claims existed have no `claim` field and stay
valid; a present claim is validated strictly.
- **Evidence in one fixed format.** `evidence` appends one comment to the
incident named in the record: a marker, the kind, the incident, who posted
it and whether they hold the claim, an optional SHA or issue, a one-line
summary and fenced details. The kinds are reproduction, bisect, log,
ruled-out, related, duplicate, fix-attempt and decision. A duplicate issue is
linked on the incident and pointed back to it. The command never files an
issue and never writes the record, and every comment passes the leakage
gate.
- **Waiting.** Workers whose proof was refused or cancelled keep coding, run
fast checks or add evidence, and resume proof when `main-status` reports
green.

The [2026-11-02 recovery ruling](https://github.com/schlessera/brain-kit/issues/2934#issuecomment-6574880345)
settles what the claimant does:

1. **Fix or targeted revert, from evidence.** After a quick assessment the
incident owner chooses a fix PR or a targeted revert PR. The choice rests on
causal and current-tree evidence; a red check or the latest squash alone is
not proof of cause.
2. **The rationale is on the incident.** The owner records the choice and why
as `decision` evidence (`--choice fix|revert|uncertain`, with details),
including the dependency and conflict assessment. A revert preserves
unrelated and later good work. When neither change is supportable, the
decision says so explicitly instead of guessing.
3. **The normal route, no shortcut.** Either PR is a declared fix and follows
normal required review, proof and recorded merge handling, including the
declared-red-main-fix route where it applies, with exact proof of the
resulting main: the green main run that includes the failing set. The
controller never merges anything itself, and there is no unbounded
recovery loop; a failed attempt gets a new assessment and decision.

### Hosted heavy feedback on draft heads

The [#2939 ruling](https://github.com/schlessera/brain-kit/issues/2939#issuecomment-6403978097)
Expand Down Expand Up @@ -1560,6 +1609,31 @@ branch, so the request always runs main's admission code.
[#2942](https://github.com/schlessera/brain-kit/issues/2942). Whichever of
#2942 and #3272 lands second adds that gate to the admission job.

### Conditional concurrency direction

The [2026-11-02 maintainer decision on #2934](https://github.com/schlessera/brain-kit/issues/2934#issuecomment-6574700840)
replaces the October deferral with a conditional direction. Concurrent integration
is permitted: base-tolerant confirmation for candidates whose affected closures are
disjoint, with reservations keyed by closure. That permission only takes effect
once all three of these hold:

1. **Stability gate.** Seven consecutive days within one proof-policy epoch,
first-main green at or above 80%, and every red incident attributed.
2. **Measured benefit.** A complete measured baseline shows a material benefit
from reducing lease waits and reconfirmation.
3. **Qualification.**
- Complete affected closures and global inputs are qualified.
- Unknown or changed graphs, and conflicts, are serialized conservatively.
- Coordination is deterministic.
- Each merge has an exact head/base/squash audit.
- Main runs full combined-tree proof, and each incident has an owner.

Selected proof, the red-main controls and the current permissions are preserved.
This is a policy direction, not a finding that any gate is met. Until a
qualified rollout, the exact-base confirmation and the single exact-candidate
reservation above still apply. Before any implementation, this record and the
concrete child task briefs on #2934 are updated.

## Historical measurement and upstream guidance

The following guidance records the paid-provider investigation which motivated
Expand Down
6 changes: 4 additions & 2 deletions scripts/red-main-coordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const incidentMarker = (run: number) => `<!-- brain-red-main: run ${run}
export const flakeMarker = (key: string) => `<!-- brain-flake: ${key} -->`;

/** Retries a compare-and-swap update of the shared record; an unchanged result writes nothing. */
export async function updateRecord(io: CoordinatorIO, update: (record: RedMainRecord, now: number) => RedMainRecord): Promise<{ before: RedMainRecord; after: RedMainRecord }> {
export async function updateRecord(io: Pick<CoordinatorIO, "read" | "publish" | "now">, update: (record: RedMainRecord, now: number) => RedMainRecord): Promise<{ before: RedMainRecord; after: RedMainRecord }> {
for (let attempt = 0; attempt < 5; attempt++) {
const snapshot = io.read(), after = update(snapshot.redMain, await io.now());
if (after === snapshot.redMain) return { before: snapshot.redMain, after };
Expand Down Expand Up @@ -114,7 +114,9 @@ export async function ensureIncident(io: CoordinatorIO, record: RedMainRecord):
"Failing tests and categories:",
...open.failures.map(f => `- \`${f.test ?? f.category}\` (${f.category}; ${f.reasons.join(", ")}; run ${runUrl(io, f.run)})`),
"",
"Hosted proof whose merge ref contains this commit is refused or cancelled, and `integrate.ts` refuses ordinary confirmation and merges, until a main run that includes this failing set is green. Declare a fix PR with `bun scripts/integrate.ts declare-fix <pr>`; the first confirmed fix wins. Only a green main run that includes this failing set clears the record, so a failure that does not reproduce still needs a declared fix to land.",
"Hosted proof whose merge ref contains this commit is refused or cancelled, and `integrate.ts` refuses ordinary confirmation and merges, until a main run that includes this failing set is green. Declare a fix or targeted revert PR with `bun scripts/integrate.ts declare-fix <pr>`; the first confirmed fix wins. Only a green main run that includes this failing set clears the record, so a failure that does not reproduce still needs a declared fix to land.",
"",
"One orchestrator owns the fix: it claims it with `bun scripts/red-main-incident.ts claim --worker <id> --orchestrator <id>`, which writes the claim into the red-main record. After a quick assessment the claimant chooses a fix PR or a targeted revert PR from causal and current-tree evidence, and records that choice and its rationale here as `decision` evidence; a red check or the latest squash alone is not proof of cause. Every other orchestrator adds evidence here with `bun scripts/red-main-incident.ts evidence ...` instead of opening another issue.",
...(related.size ? ["", `Possibly related open issues: ${[...related].sort((a, b) => a - b).map(n => `#${n}`).join(", ")}.`] : []),
];
const issue = await io.write("POST", `repos/${io.repository}/issues`, {
Expand Down
Loading
Loading