Repository navigation
feat(ci): the merge bus — batch the ready PRs and prove the combination green - #448
Conversation
f36f3e8 to
5977e70
Compare
|
Rebased onto current Added: the bus now tells a bad batch apart from a starved accountWhile verifying this, the account ran out of Actions minutes. Every job on every branch — That is a problem for the bus as originally written: it would have seen So the bus now reads execution rather than conclusion — a starved run and a legitimately failing one are both Measured on this repo: starved runs sum to 0 steps, real ones to 5, 5 and 202. Two uses:
Cause 0 is now documented in the Verified offline (no CI required)Both gates were observed working on real failures, not just passing:
Blocked onNothing in this PR. The gate cannot go green until the account's Actions spending limit is raised or the monthly allowance resets — the three runs on this head failed with 0 steps executed, same as every other branch. |
Added: a simulator, and mutation testing that found a real blind spot
It runs the workflow's real step scripts with a runner's semantics for the parts that carry bugs — per-step Ten scenarios, 45 assertions, covering the green path and every failure path:
Mutation testing, and the blind spot it caughtEvery guard was deliberately deleted from the workflow to confirm the suite goes red. Seven mutants, seven caught — but only after a fix:
Deleting the land step's tree assertion changed nothing, because in all nine scenarios the tree matched. The check could not fail, so it was not yet a check — exactly the defect this repo's "observe it failing" rule exists to catch, in my own work. The Hand-run, like a skill's Still blockedUnchanged — the account's Actions quota. Every run on every branch, |
…on green `main` has `strict: false`, so a PR merges on a green it earned against a base that may since have moved. With five or six PRs open at once that is not theoretical: four PRs each green against an older `main` can all merge and leave `main` red, because no run ever examined the combination. `merge-bus.yml` is that run. It batches the PRs carrying the `merge-bus` label, opens an ordinary PR for the combination so the existing gate judges it, and squash-merges the members in order only if it goes green. Red merges nothing. GitHub's merge queue is exactly this feature and cannot be enabled here — it is organization-only, private repositories needing Enterprise Cloud. Probed rather than assumed: `rulesets` is `[]` and `mergeQueue(branch:"main")` is `null`. The self-hosted options are worse: bors-ng is archived, and rust-lang/bors and Prow's `tide` are GitHub Apps wanting a hosted service, a webhook endpoint and an App key, each restating the required checks where they can drift from protection. Opening a PR rather than emulating `merge_group` is what made this cost no edits elsewhere: the three required workflows trigger on bare `pull_request`, so a batch branch earns every context with correct `detect` behaviour. The native queue would have been more work — `merge_group` is not a `pull_request` event, so all three `detect` jobs fall through to their fail-safe default and every merge-group build would run every gate at full cost. Eligibility asks GitHub instead of restating the required set: with reviews at zero, `mergeStateStatus == CLEAN` IS "every required check is satisfied", so no context is enumerated here and nothing can drift. `DIRTY` is rejected by name, because a conflicted PR runs zero workflows and reports no checks — "nothing is failing" would read that as green. `gh pr list` returns UNKNOWN and does not trigger the computation, so the authoritative read is a per-PR `gh pr view`. Two invariants make the landing sound. `main` must still be at the SHA the batch was cut from, or the green no longer describes what merging would produce. And after the squashes `main`'s TREE must equal the tree the gate examined — because `state: MERGED` is not evidence: a stacked PR whose base branch is deleted is marked merged, with a real mergeCommit, while its code never reaches `main`. For that reason the bus also retargets stacked children onto `main` before merging their parent, which is the only time `gh pr edit --base` still works. It also tells a bad batch apart from an account that has run out of Actions minutes. That state fails every job in seconds with `steps: []` and no log, repository-wide, while githubstatus reads operational — so a bus run during one would otherwise accuse the batch of a failure nothing compiled. The bus reads EXECUTION rather than conclusion (measured here: starved runs sum to 0 steps, real ones to 5, 5 and 202), refuses to build when the last five completed runs all executed nothing, and reports `starved` rather than red if capacity runs out mid-validation — no label, and no comment on the members, because during an outage every PR is equally stuck. Cause 0 is now documented in the skill, which had no entry for it. Dispatch-only and `dry_run: true` by default, so the predicate can be exercised before it is trusted. `merge bus` must never become a required status check. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`merge-bus.yml` is bash that merges to `main`, and `workflow_dispatch` fires
only for a workflow already on the default branch — so its live path cannot be
exercised until it is merged. That is a bad place to have no tests.
`scripts/ci/merge-bus-test.sh` runs the workflow's REAL step scripts with a
runner's semantics for the parts that carry bugs: per-step `$GITHUB_OUTPUT`,
`${{ }}` resolution in `env:`, `if:` gating, and a failed step halting the job.
`gh` is stubbed; git operations are genuine, against a local bare repo seeded
with branches and the `refs/pull/<n>/head` refs GitHub synthesizes.
Ten scenarios cover the green path and every failure path: green, stacked, red,
starved, preflight, moved, partial, reject, collide, lying. 45 assertions.
Every scenario was mutation-tested — the matching guard deleted from the
workflow, the suite confirmed red. Seven mutants, seven caught: no-basesha,
no-retarget, starved-blames, no-dirty-reject, no-tree-assert, no-preflight,
no-eject-continue.
That exercise earned its keep immediately. Deleting the land step's tree
assertion left EVERY scenario still green, because in all of them the tree
matched — the check could not fail, so it was not yet a check. The `lying`
scenario closes it by having `gh pr merge` report success while landing
nothing, which is the real shape of the trap it guards: a stacked PR marked
MERGED, with a real mergeCommit, whose code never reached `main`. With it, the
mutant is caught and the assertion is load-bearing.
Hand-run, like a skill's `evals.md`, and deliberately not a CI job: it needs
python3 with PyYAML, and a required check may not be added here before it has
been observed failing.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
76e70bd to
6569cb6
Compare
Why
main's protection hasstrict: false— "require branches up to date beforemerging" is off — so a PR merges on a green it earned against a base that may since
have moved. With five or six PRs open at once that is not theoretical: four PRs each
green against an older
maincan all merge and leavemainred, because no run everexamined the combination.
This adds that run.
What it does
merge-bus.yml(dispatch only,dry_run: trueby default):merge-buslabel, oldest first, capped atmax_batch(input, else theMERGE_BUS_MAX_BATCHvariable, else 4).merge-bus/<run_id>cut frommain's tip.Why not GitHub's merge queue
It is this feature, and it cannot be enabled here: merge queue is organization-only,
with private repositories needing Enterprise Cloud. Probed rather than assumed —
gh api repos/:owner/:repo/rulesetsreturns[], andrepository(…).mergeQueue(branch:"main")returnsnull.The self-hosted options are worse rather than better. bors-ng — the original,
which batches and bisects — was archived 2024-04-04 and its README now points at
GitHub's merge queue. rust-lang/bors and Prow's
tideare alive and capablebut each is a long-running GitHub App wanting a hosted service, a public webhook
endpoint and an App private key: more standing credential than a workflow file, not
less. Each also replaces branch protection as the merge authority, restating the
required checks in bot config where they can drift from it silently.
Design notes worth reviewing
It opens a PR rather than emulating
merge_group, and that is why it cost noedits elsewhere. The three required workflows trigger on bare
pull_request, soa batch branch earns every required context with correct
detectbehaviour. Thenative queue would have been more work:
merge_groupis not apull_requestevent, so all three
detectjobs fall through to their fail-safe default(
code=true,frontend=true, "assuming infra changed") and every merge-groupbuild would run every gate at full cost.
Eligibility asks GitHub instead of restating the required set. With reviews at
zero,
mergeStateStatus == CLEANis "every required check is satisfied", so nocontext is enumerated here and nothing can drift from protection — and no
admin-scoped protection read is needed, which
GITHUB_TOKENdoes not have.DIRTYis rejected by name. A conflicted PR runs zero workflows and reports"no checks reported", so any predicate phrased as "nothing is failing" reads it as
green. Related:
gh pr listreturnsmergeStateStatus: UNKNOWNand does nottrigger the computation — only
gh pr viewdoes, so the authoritative read isper-PR with a retry.
Two invariants make the landing sound.
mainmust still be at the SHA thebatch was cut from, or the green no longer describes what merging would produce.
And after the squashes,
main's tree must equal the tree the gate examined —because
state: MERGEDis not evidence. A stacked PR whose base branch is deletedgets marked
MERGEDwith a realmergeCommitwhile its code never reachesmain(observed on fix(deploy): drain on SIGTERM instead of dying mid-response #438). For the same reason the bus retargets stacked children onto
mainbefore merging their parent, which is the only point at whichgh pr edit --basestill works.It stops on red and does not bisect. The member comments say the combination
failed; they do not accuse any one PR. The bus PR is left open because its branch
is the only place the failing combination exists. A conflict is ejected instead
of stopping the batch — that is found before any CI is spent and names the culprit
exactly.
Required status checks
merge busmust never become one. It runs onworkflow_dispatchonly, so it cannever report on a PR, and a required context that never reports blocks every PR
forever. The generated
required-checks.mdis regenerated in this commit, which ismandatory rather than tidy:
scripts/skills-check.shderives that table from.github/workflows/*.yml, and its drift check runs inside the requiredfmt + clippy + docsjob.Scopes
This is the first hand-written workflow here with
contents: writeandpull-requests: write; the other four arecontents: readplusid-token: write.It adds no repository secret —
GITHUB_TOKENis minted per run. It isdeliberately not an admin, which tightens rather than loosens things: every merge
it makes must satisfy the required checks, whereas a human running
gh pr merge --adminbypasses all of them.Repository configuration this depends on
Applied out-of-band (none of it a secret):
The first is needed because
GITHUB_TOKENcannot open a PR while "Allow GitHubActions to create and approve pull requests" is off.
Verification
Done locally:
skipped fix(blocking): the largest-block figure was n^2, and the UI called it "pairs" #442 (
stacked on 'bm/profile-p5-read-api', not main) and fix(ci): the dev deploy had become unreachable — give it its own workflow #444(
conflicts with main (runs no CI, so reports no checks)), and resolved everyUNKNOWNthrough the retry.run:block passesbash -n; the workflow parses; the oneuses:satisfiesthe S9 SHA-pin pattern.
scripts/skills-check.sh all→ exit 0.Still to do, per this repo's rule that a gate is trusted only after it has been
observed failing: watch the red path, the
main-moved abort, and a real greenlanding at N=2 before raising
max_batchor adding aschedule:.🤖 Generated with Claude Code