Sub topic 8
Grouping strategy and what happens when a group fails
This chapter assumes you already know how merge groups and the gh-readonly-queue/... temporary branches work. It also assumes you can read a ruleset's merge_queue parameters. Here you will see how the grouping strategy decides which check results count, and how the queue reacts when a check fails.
Groups and entries
Each pull request in the queue is an entry. The queue builds a merge group from one or more entries and runs your merge_group workflows on it. Two settings control the group size:
max_entries_to_mergeis the largest number of entries merged in one group.min_entries_to_mergeis the smallest group the queue will merge.min_entries_to_merge_wait_minutesis how long the queue waits to reach that minimum before it merges a smaller group.
If both are 1, every pull request is tested and merged alone.
The two strategies
The ruleset parameter grouping_strategy takes one of two values.
| Value | A group may merge when | Effect |
|---|---|---|
| `ALLGREEN` | Required checks pass for every entry in the group | Safest. A failure in any entry blocks the group. |
| `HEADGREEN` | Required checks pass on the last (head) entry of the group | Cheaper and faster. The head commit contains the changes of the entries before it, so a pass there covers them. |
HEADGREEN saves work when checks on earlier entries are slow or flaky. The cost is that a failed check on an earlier entry can be overridden by a later passing one. Pick it only if your checks on the head commit really test everything.
{
"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
}
}What happens when a group fails
Entries are stacked. Each merge group is built on top of the groups ahead of it. If an entry fails, the commits behind it were tested with a change that will never reach main, so those results are no longer valid.
The queue handles this in three steps:
- It removes the failing pull request from the queue.
- It discards the merge group branches that were built on top of the failed entry.
- It rebuilds the groups for the remaining entries, without the failed change, and reruns their checks.
The author of the removed pull request gets a notification. They fix the problem and add the pull request to the queue again, at the back.
Cost of a failure
A failure costs more than one rerun. Everything queued behind the failed entry is tested again, and those entries wait longer. Larger groups and higher build concurrency speed up the happy path, but they also increase how much work a single failure throws away. Under ALLGREEN, one flaky test in a group of five can remove a pull request that did nothing wrong.
Timeouts count as failures
If required checks do not report within check_response_timeout_minutes, the queue treats the entry as failed. A common cause is a workflow that does not run on merge_group. In that case the check never reports and the entry times out. Confirm that every required workflow includes the merge_group trigger.
Exercise
A queue uses ALLGREEN with maxentriesto_merge set to 3. Entries A, B and C are in one group, and the required check fails on B. What does the queue do with B and C, and why does C need new checks?
Show answer
The queue removes B from the queue and notifies its author. It rebuilds C's group without B's changes and reruns the checks. C's earlier results were produced on a branch that included B, which will not reach main, so those results no longer describe what would be merged.