Co-authored-by: Kandev Agent <agent@kandev.dev>
11 KiB
Enabling the merge queue
Everything in this document except the final section is already in the repository. Nothing here is switched on: the workflows are prepared, and the ruleset change that turns a merge queue on is a separate, deliberate decision.
Why
main's ruleset (id 13341245) has deletion, non_fast_forward,
required_linear_history, and pull_request rules, and no
required_status_checks rule at all. Merges are not gated on CI in any way.
That is how #2681 (38c94e7d0) landed red. Its E2E checks were fully green, but
they had run 23 hours earlier against a merge ref that predated the retry loop
added by #2569 (15788438b). Neither change is wrong on its own; together they
put a roughly 4.5-second floor under content search, just over the 5-second
default assertion in the test #2681 added. Both pull requests were green, and
their merge was not.
Required status checks alone would not have caught it -- #2681's checks were green. A merge queue would: it builds the actual merge result and runs the checks against that, at merge time, in queue order.
What changed in the workflows
The merge_group trigger
Six workflows gained merge_group: types: [checks_requested]:
| Workflow | Gate job | Check name to require |
|---|---|---|
e2e-tests.yml |
e2e-gate |
E2E Tests Passed |
backend-tests.yml |
test |
Run Backend Tests |
frontend-tests.yml |
frontend-gate |
Frontend Tests Passed |
architecture-lint.yml |
lint |
Architecture boundaries do not regress |
lint-action-pinning.yml |
lint |
All action refs are SHA-pinned |
lint-harness-files.yml |
lint |
Harness files pass lint |
Deliberately excluded, because they cannot report in a queue and would stall it forever, or because their redness is not a property of the merge:
pr-title.yml,claude-code-review.yml,opencode-code-review.yml,preview-env.yml,notify-docs.yml-- allpull_requestorpull_request_targetscoped. There is no pull request in a merge group, so they never run and never report.cargo-audit.yml-- also runs on a weeklyschedule, by design: a newly published RUSTSEC advisory turns it red with no change to the code. In a queue that would block every merge in the repository until somebody bumped a crate. It stays a pull-request and scheduled check.ci-base-image.yml,universal-rebuild.yml-- these publish images rather than test a merge.release.ymland the plugin registry workflows -- out of scope.
The path-filter problem, and the approach chosen
Most of these workflows were heavily path-filtered (apps/web/**, !**/*.md,
and so on). That is a problem for a queue in two independent ways.
- A workflow skipped by a trigger-level
paths:filter reports no conclusion at all. GitHub's documentation is explicit that "checks associated with that workflow will remain in a 'Pending' state". A required check that stays pending blocks a pull request from being added to the queue, and blocks a merge group from ever merging. merge_groupdoes not supportpaths:in the first place. It takestypes:andbranches:only. So the filters could not simply be mirrored onto the queue side even if we wanted them there.
Two approaches were available: mirror each filter onto an inverse trigger with a "skipped reports success" shim job, or make the gating jobs always run and short-circuit internally.
The shim was rejected, and the internal short-circuit implemented. The
deciding factor is that paths with ! exclusions has no exact inverse. Take
frontend-tests' old filter, apps/web/** followed by !**/*.md. A pull request
that touches only apps/web/README.md is skipped by that filter, and is also
skipped by the mirrored paths-ignore list, because every changed file appears
in it. Both halves skip, no conclusion is ever reported, and the queue waits
forever -- the exact failure the shim exists to prevent, reintroduced by the
shim. Making the inversion correct would mean hand-deriving a second pattern
list per workflow and keeping the two in sync by eye. Worse, the shim needs a
job whose name matches the real check, which for e2e-tests.yml would mean
reproducing fourteen shard names and six container shard names.
So: the trigger-level paths: filters are gone, and each expensive workflow
grew a cheap changes job that applies the same list one level down.
changes ──> static_checks ─┐
└─> test_shards ───┼──> test <- the required check, if: always()
└─> ... ──┘
.github/scripts/changed-paths.py implements GitHub's filter-pattern semantics
(*, **, ?, leading !, last match wins) and is unit-tested in
changed-paths_test.py, which also asserts the pattern lists still live in the
workflows and still select what they used to. It rejects +, [...], and
{...} rather than quietly matching them as literals.
Two properties of this shape matter:
- The gate job always runs. It is
if: always()and treats askippeddependency as a pass and acancelledone as a failure. This is on purpose: it means the required check never depends on how GitHub reports a conditionally-skipped job, only on a conclusion the workflow computes itself. - The gate covers every job in its workflow. A queue gates on check names an
admin picks by hand, so a job outside the gate's
needsis a job whose failure would never block a merge, silently.backend-tests.yml'spostgres-bootandtest-windowswere outside its aggregate before this change and are now inside it.
Two workflows -- lint-action-pinning.yml and lint-harness-files.yml -- have
no changes job. They are a checkout plus a handful of short linters, so they
simply always run: cheaper than the job that would decide whether to run them,
and it closes the gap where a subject outside their hand-maintained lists
changed and nothing checked it. Their contract tests were updated to assert the
absence of a filter rather than the presence of specific entries.
PR context in a merge group
A merge_group run has no github.event.pull_request and no
github.event.before. Every expression that read one has been made explicit
about the event it is on, and given the merge-group equivalent,
github.event.merge_group.base_sha -- the commit the queue branch was cut from,
which is the merge group's base:
architecture-lint.yml-- the two mutually exclusivepull_request/pushlint steps were collapsed into one, behind a baseline-resolving step. Under the old shape a merge-group run would have executed the linter's self-tests and then linted nothing at all, reporting green having compared the branch against no baseline.backend-tests.yml--Resolve base SHA.frontend-tests.yml--Check formatting, the i18n new-code ratchet, and the E2E sleep ratchet.e2e-tests.yml-- the GHCR login guard readsgithub.event_name != 'pull_request' || <fork check>, which resolves to the first operand on a merge group. That is correct: the queue branch lives in this repository and its token is a base-repository token.
Concurrency groups were checked too. None of the six keyed on a PR number
(preview-env.yml does, and it is not a gate). All six now set
cancel-in-progress: ${{ github.event_name != 'merge_group' }}, because a queue
reads a cancelled check as a failure and ejects the pull request.
Enabling it
- Add a
merge_queuerule to themainruleset. - Add a
required_status_checksrule and select exactly the six check names in the table above. Do not select any per-shard name (E2E Shard 3/14,Backend Tests (1/2), ...) -- they are covered by the gates, and a queue configured against them breaks the next time a shard count changes. - Do not select
lint(frompr-title.yml),Validate public docs, or anyclaude-review-*/opencode-review-*/deploy-*check. Those never run in a merge group and the queue will wait on them indefinitely.
Caveat: the ruleset can still be bypassed
The main ruleset lists one bypass actor:
{ "actor_type": "OrganizationAdmin", "bypass_mode": "always" }
bypass_mode: always means an organization admin can merge past whatever is
configured here, queue included, without a review request or a temporary
override. Configuring required checks constrains everybody else; it does not
constrain an org admin. If the point of enabling the queue is that nothing red
reaches main, that entry needs to change as well -- to pull_request mode, or
removed -- and that is a separate decision about who is trusted to break glass.
What is verified, and what is not
Verified locally on this branch:
actionlintv1.7.12 is clean on every file touched here. Its one repository finding is pre-existing and inrelease.yml(queue: maxunderconcurrency, a key it does not know).zizmorv1.29.0, run over the six workflows before and after: one finding removed (atemplate-injectionerror infrontend-tests.yml, from movinggithub.base_refout of an inline expression intoenv:), none added.- Every
.github/scripts/*_test.pycontract test passes, as doeslint-action-pinning.pyover all 18 workflows. changed-paths_test.pypasses, and fails when the guarantees are broken: restoring apaths:filter to a gating trigger, deleting amerge_grouptrigger, and reordering!**/*.mdabove the includes were each confirmed to fail it.
Not verified, and not verifiable until a queue is switched on:
- No
merge_groupevent has ever fired against these workflows. Everything about the merge-group path -- thatgithub.event.merge_group.base_shais populated as expected, that thechangesjob resolves a usable base from it, that the gate jobs report under the names in the table -- is read from GitHub's documented payload, not observed. - Whether GitHub blocks a pull request from entering the queue on a check that reports nothing. The design assumes it does, which is why the filters moved; if it turns out not to, the change is still correct, just more cautious than it needed to be.
- The cost. Every pull request now starts six workflows instead of however many
its paths selected, and each merge group runs the full E2E suite. The
changesjobs keep the expensive work filtered, but the floor per pull request is higher than it was.
The cheapest way to close the first gap is to enable the queue on a low-traffic day and watch the first merge group's check names against the table above.