Sub topic 8
Grouping strategy and what happens when a group fails
This chapter assumes you know how a merge queue builds temporary gh-readonly-queue branches, and that you have a workflow running on the merge_group event. Here you will see how the grouping strategy setting decides what must pass before a group merges. You will also see what the queue does when a group fails.
Recap: what a group is
When the queue has several entries, GitHub can build one merge group for more than one pull request. A merge group is a temporary branch. It starts from the latest base branch and adds the changes from the pull requests in the group, in queue order. Your required checks run once against that branch.
If the group passes, GitHub merges all its pull requests into the base branch together. If it fails, GitHub has to work out which pull request caused the failure. The grouping strategy controls how strict that process is.
The grouping strategy setting
The queue has a grouping_strategy setting with two values. They appear in the ruleset JSON from the previous chapters and in the settings UI.
| API value | UI label | Meaning |
|---|---|---|
| `ALLGREEN` | All Green | Every group must pass its required checks before it merges. |
| `HEADGREEN` | Only merge non-failing pull requests | Only the head (newest) entry in the group needs to pass. |
The setting also interacts with two numbers: max_entries_to_build and max_entries_to_merge. The first limits how many entries can have builds running at once. The second limits how many pull requests can merge in one group. A third setting, min_entries_to_merge, sets how many entries must be waiting before a group is formed, and min_entries_to_merge_wait_minutes sets how long the queue waits for that minimum before it proceeds anyway.
ALLGREEN
With ALLGREEN, the checks must pass on the group's own merge commit before that group is merged. This is the conservative choice. The branch that lands on main is exactly the branch that was tested.
Use ALLGREEN when a red main is expensive, for example when main deploys automatically, or when tests are known to be flaky in ways that depend on combinations of changes.
HEADGREEN
With HEADGREEN, the queue builds a branch for each entry, stacked on the entries ahead of it. A group can merge when the checks pass on its head entry's branch. That branch already contains every change ahead of it, so a green head means the combined result was tested.
The benefit is throughput. If an entry ahead of the head fails its own checks but the head still passes, the head's tested state includes the changes that did the work. The queue does not need to rebuild everything just to confirm. The cost is that you rely on the head's checks covering everything. Treat the exact semantics as something to verify in a test repository before you depend on it, because they interact with your required checks and group size.
A practical rule: start with ALLGREEN. Move to HEADGREEN only when you measure that queue wait time is a problem and your checks are reliable.
Settings that shape group behavior
The values below are from the ruleset example used earlier in this tutorial.
{
"type": "merge_queue",
"parameters": {
"merge_method": "SQUASH",
"grouping_strategy": "ALLGREEN",
"min_entries_to_merge": 1,
"max_entries_to_merge": 5,
"min_entries_to_merge_wait_minutes": 5,
"max_entries_to_build": 5,
"check_response_timeout_minutes": 60
}
}Reading it as a group-formation policy:
- With
min_entries_to_mergeof 1, a single pull request forms a group immediately. - With
max_entries_to_mergeof 5, a group never merges more than five pull requests at once. - With
max_entries_to_buildof 5, up to five builds can run at the same time. - With
check_response_timeout_minutesof 60, a required check that does not report within an hour counts as failed.
Raising min_entries_to_merge above 1 makes the queue wait to batch pull requests. That saves CI runs, because one run covers several pull requests. It also adds latency, up to min_entries_to_merge_wait_minutes, to a lone pull request.
What happens when a group fails
A failure inside the queue does not break main. The failed branch is temporary and is never merged. What changes is the queue's state.
The sequence is:
- A required check on a merge group branch fails or times out.
- GitHub removes the pull request that caused the failure from the queue. If a group contained several pull requests, GitHub identifies the failing entry from the per-entry builds.
- The pull requests that were queued behind it are not removed. GitHub rebuilds their merge group branches without the removed pull request.
- The checks run again on the new branches, and the queue continues.
The removed pull request stays open. Its author sees that it left the queue, fixes the problem, and adds it again.
Why a failure costs more than one build
Entries behind a failing pull request had builds that included its changes. Once that pull request is removed, those builds describe a state that will never exist. GitHub discards them and starts new ones. This is the main cost of failures in a deep queue.
Consider a queue with pull requests A, B, C, and D, where B fails.
| Step | State |
|---|---|
| Before failure | Branches: A, A+B, A+B+C, A+B+C+D |
| B fails | B is removed from the queue |
| After rebuild | Branches: A (kept), A+C, A+C+D |
The build for A is unaffected because it did not depend on B. The builds for C and D are wasted and restarted. The deeper the queue and the higher max_entries_to_build, the more work a single failure discards.
That leads to a trade-off:
- A large
max_entries_to_buildlowers waiting time when everything passes. - It raises wasted CI minutes when something fails.
- A flaky test makes this worse, because a false failure on B discards the work for every entry behind it.
Failure causes worth separating
Not every red check means the pull request is wrong. When a pull request is removed, check which case you are in before you re-queue.
| Cause | Typical sign | Action |
|---|---|---|
| The change is incompatible with `main` or with queued changes | Check passes on the pull request branch, fails on the `gh-readonly-queue` branch | Fix the code, then re-queue |
| Flaky test | Same test passes on re-run | Fix or quarantine the test, then re-queue |
| Check never reported | Timeout removal after `check_response_timeout_minutes` | Add the `merge_group` trigger to the workflow |
| Infrastructure failure | Runner or service error | Re-run the job, then re-queue |
The first row is the case the queue exists to catch. It shows up as a failing run on the temporary branch. Open the run from the pull request's checks list and read the log for the failing step.
A workflow that supports the queue
Failures from missing triggers are common and easy to avoid. The workflow must run on merge_group, or its required check never reports on the group branch.
name: CI
on:
pull_request:
branches: [main]
merge_group:
types: [checks_requested]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: make testThe test job runs on both events, so the required check named test is reported on the pull request and on the group branch.
Choosing a strategy: decision criteria
- Pick
ALLGREENwhenmainmust always be releasable, when you deploy frommain, or when you are new to merge queues. - Pick
HEADGREENwhen queue wait is the main complaint, your tests are stable, and a short-lived failure on a combination is acceptable to resolve afterward. - Keep
max_entries_to_mergesmall, such as 2 to 5, while you learn how often groups fail. - Raise
max_entries_to_buildonly after you know your CI can run that many jobs in parallel without queuing for runners.
Summary
The grouping strategy decides how strictly a group must prove itself before merging. When a check fails, the queue removes the failing pull request and rebuilds the entries behind it. The cost of that rebuild grows with queue depth, which is why group size, build concurrency, and test reliability are tuned together.
Exercise
A queue has pull requests A, B, C, and D, with maxentriestobuild set to 4. Pull request B fails its required check on its merge group branch. Which builds are kept, which are discarded, and what does this tell you about the cost of setting maxentriestobuild high?
Show answer
A's build is kept because it does not include B. The builds for C and D included B's changes, so they are discarded and restarted without B (as A+C and A+C+D). B is removed from the queue and stays open for its author to fix. A high maxentriesto_build speeds up the all-green case but wastes more CI work each time an early entry fails, so it is a poor fit when failures or flaky tests are common.
Exercise
A pull request is removed from the queue exactly 60 minutes after it was added, and the required check never appears in the group's run list. What is the most likely cause and the fix?
Show answer
The workflow that provides the required check does not have a mergegroup trigger, so it never ran on the temporary branch. The queue waited for checkresponsetimeoutminutes (60) and then removed the pull request. Add mergegroup (with types: [checksrequested]) to the workflow's on: block, then re-queue the pull request.