Skip to content

Compare merge groups against the queue base, or fail closed - #155

Open
PavelMakarchuk wants to merge 5 commits into
mainfrom
ci/merge-group-base-guards
Open

PavelMakarchuk wants to merge 5 commits into
mainfrom
ci/merge-group-base-guards

Conversation

@PavelMakarchuk

@PavelMakarchuk PavelMakarchuk commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

TheAxiomFoundation/rulespec-us#612 proposes a GitHub merge queue for rulespec-us main. The goal: the full validation, the full waiver audit included, runs once before the merge on the exact merged result. The duplicate full run on push to main can then be dropped in a follow-up.

The queue reports the required check validate / validate on a merge_group event. On that event github.event.pull_request.* and github.event.before are empty; the base is github.event.merge_group.base_sha and the head is github.sha. This workflow already handles most of that event. Four steps took a wrong base or skipped their check.

Changes

  • .github/workflows/validate-rulespec.yml
    • Reject unsupported tracked paths, Reject unmanifested RuleSpec content: BASE_SHA includes merge_group.base_sha. A merge group without an exact base commit fails (UnsupportedTrackedPathBaseMissing, UnmanifestedRuleSpecBaseMissing). Before: the first step skipped its diff, the second passed with no scan (SCAN_MODE=none).
    • Verify immutable retired-schema freeze: uses merge_group.base_sha; fails for a merge group without an exact base. Before: HEAD^.
    • Enforce validation waiver ratchet: new merge_group branch, base read from env (ValidationWaiverBaseMissing). Before: HEAD~1.
    • Reject manual RuleSpec changes refuses the all-zero SHA as a base.
    • No change for pull_request, push, schedule, workflow_dispatch.
  • scripts/test_validate_rulespec_workflow.py: four tests for merge groups (three from the first cycle, one new; see Tests).
  • This update: main merged into the branch (19 commits, Verify RuleSpec PRs with encoder main: encoder-verifier input (axiom-encode#2093) #154 included; no conflict), and the new test.

Design claims, checked in the code

Claim Where Result
A merge group gets the full matrix and all modules shards / Compute validation shards: every event other than pull_request selects all legs. validate / Select RuleSpec validation targets: mode full-push. True. New test compares the merge-group selection with the push selection.
"Changed files" use the queue base Dependency inputs, both pre-checks, freeze, ratchet, manifest audit and manual-change guard read merge_group.base_sha. True after this PR.
No base, no pass Each of those steps fails for an empty, zero, short or symbolic base. True; tests and a dry run on real merges.
validate / validate reports on merge groups Job validate-complete, name validate, if: always(), no event condition. True. A skipped or failed matrix reports a failed check.
No concurrency group cancels a merge-group run Neither this workflow nor the rulespec-us caller declares concurrency. True; the new test asserts it for this workflow.
The strict oracle-coverage step runs on merge groups `if: github.event_name != 'pull_request'
The encoder-main verifier (#154) keeps the full run Scoping applies only when the event is pull_request. True.

Where a merge-group run does less than today's push run

Read from the workflow code at this branch (merged with main, 03d4a67).

Item Push to main today Merge group Effect
Matrix, modules, waiver audit, YAML, companion tests, proofs, money atoms, pytest Full Full, identical selection (test added) None
Strict oracle-coverage step Runs Runs The gap of TheAxiomFoundation/axiom-encode#2174 moves from "red main after the landing" to "entry removed from the queue before the landing"
drift-alarm (caller) Opens the red-main issue Does not start Intended. A red group never reaches main.
Rollback rewind proof Supported Not supported; the gates use the queue base Stricter, not weaker. A rollback pull request that needs the proof passes on pull_request and fails in the queue.
Reviewed-migration authorization Supported Fails closed if requested rulespec-us does not request it.
Other rulespec-us workflows (engine-root-load, source-staleness with its reverse-index job, waiver-issues, source-conflicts; program-artifacts runs on pull requests only) Run on push Do not run on merge groups They are not required and continue on pull_request and push as today.

Three checks run only on pull_request and not on a merge group (the same as on push): the changed-file oracle steps, the canonical-toolchain removal guard, and the encoder-main scope. The pull-request run before the queue still executes them.

Oracle pending file. No workflow runs oracle-coverage-pending sync. A candidate with unmapped outputs and no entry in oracle-coverage-pending.yaml passes its pull-request run and then fails in the queue after a full run (about 3 hours). The sync must be in the pull request before it enters the queue (option 1 of TheAxiomFoundation/axiom-encode#2174, not built). Two queued pull requests that both edit that file can conflict (TheAxiomFoundation/rulespec-us#612).

Runner cost. A pull request must be green before it enters the queue. Measured runs: pull request about 2,700 runner-minutes, push about 3,100.

State Runs for each landing Runner-minutes
Today pull request + push (+ one more pull-request run for each open pull request that must update) about 5,800 + 2,700 for each update
Queue on, push run kept pull request + merge group + push about 8,900
Queue on, push run dropped (follow-up) pull request + merge group about 5,800
Queue on, push run dropped, pull-request run scoped (follow-up, #130) small pull-request run + merge group about 3,200 to 3,800

The queue alone adds one full run to each landing. It removes the update runs at once. The halving needs both follow-ups: drop the push run, and make the pull-request run small. Neither is in these two pull requests.

Activation steps (for an organization admin, in this order)

The same text is in #155 and TheAxiomFoundation/rulespec-us#2160.

Order rules. Read these first.

  • Do not create or activate the merge-queue ruleset before step 3 is complete. The queue waits for validate / validate on a merge_group event. Without the trigger on main, no run starts, each queued pull request waits until the timeout, and nothing merges.
  • Do not create or activate it before step 2 either. With the current pin (882c5f1), the unmanifested-content pre-check does not scan a merge group, and the ratchet and the freeze compare against HEAD~1 / HEAD^.
  • Do not switch off "Require branches to be up to date" before the first queued merge shows that the queue waits for validate / validate (step 6 comes after step 5). With the queue not waiting and that setting off, a pull request with an old green run can land.
  • Do not add a second required check. Only validate / validate reports on merge groups. The other workflows of rulespec-us (engine-root-load, source-staleness, reverse-index, waiver-issues, program-artifacts, source-conflicts) have no merge_group trigger. A required check that never reports stalls the queue.

1. Merge #155. Use a merge commit or a squash. Then read the SHA that the merge put on .github main:

gh api repos/TheAxiomFoundation/.github/pulls/155 --jq .merge_commit_sha

2. Re-pin rulespec-us. Push one commit to the branch of TheAxiomFoundation/rulespec-us#2160 (ci/merge-group-trigger):

  • File: .github/workflows/repository-checks.yml, line 68 on that branch (job validate, key uses:).
  • Old: TheAxiomFoundation/.github/.github/workflows/validate-rulespec.yml@882c5f11545ec3343fc5ed170e01d65aa2c5bb3e
  • New: the same path with @<the 40-character SHA from step 1>.
  • Use the commit on first-parent main of .github (the merge or squash commit), not the head of the pull-request branch. encoder-guard.yml refuses a pin that is not on first-parent main or that moves backward, when its organization ruleset is applied. Nothing enforces this on rulespec-us today.
  • Change no other file in that commit. The validator accepts a pin change only in a configuration-only pull request; #2160 changes only this file, so it qualifies.
  • The pin change makes the pull-request run a full run (full-toolchain-bump: all legs, all modules, strict oracle-coverage step). Wait for green (about 3.5 to 4.5 hours). This run is also the first run of rulespec-us on the validator of .github main (6 merges, 39 commits after the current pin). It runs all that a merge-group run runs, plus the pin-change audits (protected-base manifest audit, manual-change guard over all manifests). If it is red, stop here; the queue is not the cause.

3. Merge TheAxiomFoundation/rulespec-us#2160 in the usual way (the queue is still off).

4. Create the merge-queue ruleset on rulespec-us. Settings → Rules → Rulesets → New branch ruleset. Name main merge queue; enforcement Active; bypass list empty; target: default branch; two rules: Require merge queue and Require status checks to pass (validate / validate, source GitHub Actions, "Require branches to be up to date" not selected in the ruleset).

Setting (UI name / API field) Value Reason
Merge method / merge_method Merge (MERGE) The last landings on main are merge commits (signed pull requests, merge trains). The first parent of the group commit is the queue base, so the diff of the group is the diff of the pull request. Squash is also valid for the validator; the queue applies one method to every pull request and ignores the per-PR choice.
Build concurrency / max_entries_to_build 1 One entry is built at a time, so merge_group.base_sha is always the tip of main, and one queue run uses 20 of the 60 runners of the organization.
Minimum pull requests to merge / min_entries_to_merge 1 A landing does not wait for a second entry.
Wait time / min_entries_to_merge_wait_minutes 5 No effect while the minimum is 1.
Maximum pull requests to merge / max_entries_to_merge 1 One pull request for each push to main. The push run on main compares before..after; with two pull requests in one push, a waiver pull request plus any other pull request fails the waiver rule changed_paths == companion_paths on main.
Only merge non-failing pull requests / grouping_strategy ON (ALLGREEN) Each entry must pass its own run. With HEADGREEN, a failed entry can land when the entry behind it passes, and that entry was compared only against the failed one.
Status check timeout / check_response_timeout_minutes 360 The maximum. Measured wall time of a full run on main: median 228 minutes, maximum 256 (5 runs). The default of 60 removes every entry.
Required status checks validate / validate (GitHub Actions), in this ruleset and, as today, in the branch protection It is the aggregate job of the validator. It runs with if: always() and reports for every event and every matrix result. The copy in the ruleset is there because the documentation does not say that a ruleset queue reads the checks of a classic branch protection.

The same ruleset as an API body (POST /repos/TheAxiomFoundation/rulespec-us/rulesets):

{
  "name": "main merge queue",
  "target": "branch",
  "enforcement": "active",
  "bypass_actors": [],
  "conditions": {"ref_name": {"include": ["~DEFAULT_BRANCH"], "exclude": []}},
  "rules": [{
    "type": "required_status_checks",
    "parameters": {
      "strict_required_status_checks_policy": false,
      "required_status_checks": [{"context": "validate / validate", "integration_id": 15368}]
    }
  }, {
    "type": "merge_queue",
    "parameters": {
      "merge_method": "MERGE",
      "max_entries_to_build": 1,
      "min_entries_to_merge": 1,
      "min_entries_to_merge_wait_minutes": 5,
      "max_entries_to_merge": 1,
      "grouping_strategy": "ALLGREEN",
      "check_response_timeout_minutes": 360
    }
  }]
}

5. First queued merge: what to look at. "Require branches to be up to date" is still on. Use a small pull request that is green and up to date. Select "Merge when ready".

  1. A Repository Checks run with event merge_group starts on a branch gh-readonly-queue/main/pr-<number>-<sha>. If no run starts in a few minutes, go to Rollback.
  2. Job validate / shards: the step "Compute validation shards" selects every leg (52 today). The step "Reject unmanifested RuleSpec content" prints scan=diff.
  3. Each leg: the steps "Enforce validation waiver ratchet" and "Validate PolicyEngine oracle coverage classification" run and are not skipped.
  4. The pull request stays in the queue until validate / validate completes on the group commit. If it merges at once, the queue does not wait for the check: go to Rollback. Then validate / validate reports success, and drift-alarm is skipped. Record the wall time of the run (limit 360 minutes).
  5. After the merge, the new SHA of main is equal to the head SHA of the merge group (merge_group.head_sha of the green run). Record the result: the follow-up that drops the push run depends on it.
  6. The push run on main still starts and passes. This duplicate is expected until the follow-up.

6. Switch off "Require branches to be up to date before merging" in the branch protection of main (strict: false). The queue tests each pull request on the current main, so the setting gives nothing more. Today, with the setting on, each landing makes every open pull request update and run again (about 2,700 runner-minutes each). Not verified: whether GitHub ignores the setting when a queue is required. Switch it off so that the result does not depend on that. Then check that a pull request that is behind main can enter the queue with no branch update.

7. Rollback. If step 6 was done, first switch "Require branches to be up to date" on again. Then set the ruleset to Disabled (or delete it). Pull requests merge directly again under the branch protection. The merge_group trigger and the new pin stay; they do nothing with the queue off. Entries that are in the queue at that time can leave the queue; merge them again.

Later: several entries for each landing

  • The settings that allow it: max_entries_to_merge and min_entries_to_merge above 1 (with a wait time), max_entries_to_build above 1, and grouping_strategy: HEADGREEN if one run must decide for the full group.
  • Keep max_entries_to_merge = 1, min_entries_to_merge = 1 and ALLGREEN until three things are decided: the content-bound merge guard (it binds one candidate to one validated result); the push run on main is dropped or its waiver rule accepts a push of more than one pull request; and a live queue shows how many runs one group costs.
  • max_entries_to_build can go above 1 before that, but only while ALLGREEN is on. The base of an entry is then the entry ahead, and two concurrent queue runs need 40 of the 60 runners of the organization.
  • The GitHub documentation says that the queue creates one merge commit and one merge_group event for each entry. If that is correct, a group of N entries still costs N full runs, and "several candidates in one run" needs one pull request that holds several candidates (a merge train) as one queue entry. Not observed on a live queue.

Not verified (needs a live queue)

  • A real merge_group event: the payload fields, the secrets and variables that the run gets, and the check name on the group commit.
  • That the queue reads the required check from the existing branch protection when the queue itself comes from a ruleset.
  • That the SHA of main after the merge is the head SHA of the merge group.
  • That a pull request behind main can enter the queue while "Require branches to be up to date" is on.
  • That the merge_commit_sha of a pull request merged by the queue is the commit on main. The rollback landing lookup of the validator needs that equality for later rollback proofs.
  • How many runs GitHub starts for a group of more than one entry.
  • If the caller job workflow-toolchain fails on a group for any reason (a bad pin file, a checkout fault), the validator is skipped and validate / validate does not report. The entry, and with build concurrency 1 the queue, then waits for the timeout (360 minutes).
  • actionlint was not run (not installed locally; no download).

Documented, not observed: gh pr merge --auto --squash (the dispatcher) adds the pull request to the queue, and the method flag has no effect (gh pr merge --help).

Tests

  • CI test job (test-shared-workflows.yml, Linux, all scripts): see the checks of this pull request. It is the authoritative run.
  • New test test_merge_group_runs_the_full_gate_and_reports_the_required_check: runs the real shard and target selection for one changed module as pull_request (one leg, one module), merge_group and push (all legs, all modules, equal results); asserts that no step of any job depends on the event or the ref, other than the strict oracle step and the pull-request-only changed-file steps; asserts the aggregate job and that no concurrency key exists. Four mutants fail it: a scoped matrix for merge_group, mode changed for merge_group, a ref condition on the waiver ratchet, and a merge_group exclusion on a shards step.
  • Local (macOS, bash 3.2; some other tests in the script need bash 4): the four merge-group tests of this pull request pass one at a time on the merged branch.
  • Dry run of the two pre-check steps (the real run: scripts of this branch and of the current pin 882c5f1) on real merges of rulespec-us main, as a merge_group event with the first parent as the queue base:
Group Paths against the queue base Paths against HEAD~1 (pin behaviour for ratchet and freeze) This branch Pin 882c5f1
TheAxiomFoundation/rulespec-us#2305 (merge commit) 3 3 pass, scan=diff, 1 module checked pass, no scan
TheAxiomFoundation/rulespec-us#2045 (squash) 3 3 pass, scan=diff, 1 module checked pass, no scan
TheAxiomFoundation/rulespec-us#2205 (merge train) 9 9 pass, scan=diff, 3 modules checked pass, no scan
Two entries: #2045 then #2205 12 9 (3 missed) pass, scan=diff, 4 modules checked pass, no scan
Each group, base removed n/a n/a both steps fail closed pass

Review record

  • Cycle 1 (2026-11-10): independent review, 7 findings; fixes in b2c5353 (base through env, zero SHA refused, effect tests). Findings 1 and 2 (the base of an entry is the entry ahead; a push of more than one pull request breaks the waiver companion rule on main) have no code defence. The queue settings in the activation steps are the defence.
  • Cycle 2 (2026-11-23): main merged; the design claims read again in the merged file; one test added with mutants; dry run on real merges; activation steps written against the GitHub ruleset reference. Independent review of the code, the new test and this text: no blocker; 4 should-fix and 7 minor findings, all applied (activation order and rollback order, check copied into the ruleset, runner-contention risk, stronger test conditions, corrections of text).

Open risks

Refs TheAxiomFoundation/rulespec-us#612, TheAxiomFoundation/rulespec-us#783, TheAxiomFoundation/rulespec-us#1980, #130, TheAxiomFoundation/axiom-encode#2174.

🤖 Generated with Claude Code

On a merge_group event the validator already runs the full matrix and
the dependency-input gate, the supervised manual-change guard and the
protected-base manifest audit already use merge_group.base_sha. Four
steps did not:

- Enforce validation waiver ratchet fell back to HEAD~1.
- Verify immutable retired-schema freeze fell back to HEAD^.
- Reject unmanifested RuleSpec content chose SCAN_MODE=none.
- Reject unsupported tracked paths skipped the diff.

A merge group can hold more than one commit (several queued pull
requests, or one pull request the queue rebased), so HEAD~1 is not its
base. Each step now uses merge_group.base_sha and stops when a merge
group has no exact base commit. Behaviour on every other event is
unchanged; rollback rewind stays unsupported for merge groups.

Refs TheAxiomFoundation/rulespec-us#612, #130,
TheAxiomFoundation/axiom-encode#2174.

Co-Authored-By: Claude <noreply@anthropic.com>
- Waiver ratchet reads the queue base from env (MERGE_GROUP_BASE_SHA),
  not from an expression interpolated into the script.
- Reject manual RuleSpec changes refuses the all-zero SHA as a base.
- Tests now run the real steps on multi-commit groups: an unsupported
  path that only the diff from the queue base names, the waiver ledger
  and changed paths the ratchet receives, and the freeze base tree.
  Each new case fails when its comparison is removed or uses HEAD~1.

Co-Authored-By: Claude <noreply@anthropic.com>
PavelMakarchuk and others added 3 commits November 23, 2026 23:46
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…heck

A merge group must select every leg and every module, as a push to main
does, run the strict oracle-coverage step, report the aggregate
`validate` job for every result, and never be cancelled by a concurrency
group. Mutants that scope the merge-group matrix or its targets fail.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review cycle 2: scan the steps of all jobs, allow only the strict oracle
step and the pull-request-only changed-file steps to depend on the event
or the ref, and cover a caller that does not pass import-aware-selection.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@PavelMakarchuk
PavelMakarchuk marked this pull request as ready for review November 24, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant