View as Markdown

Merge Queue Batches

Test several queued pull requests in one CI run, to merge more of them for less CI.


A batch tests several queued pull requests together, in one CI run, and merges them all when it passes. The queue then merges more pull requests an hour, for fewer CI runs, than one that tests each pull request on its own.

Use them when pull requests arrive faster than your CI can test them one at a time, or when each CI run is expensive. A batch pays off when most pull requests pass: one that fails takes the batch down with it, and finding it costs extra CI runs.

Set batch_size on the queue rule:

.mergify.ymlyaml
queue_rules:
- name: default
batch_size: 5
batch_max_wait_time: 5 min
Effect

Mergify waits up to 5 minutes for five pull requests, then tests the batch with what it has.

A longer batch_max_wait_time fills batches and saves CI; a shorter one merges sooner.

Mergify pushes each batch to a branch of its own, on top of the base branch and the batches ahead of it, and by default opens a draft pull request for it, so your CI runs on the batch like on any pull request. Run CI on a Batch covers your CI’s side, and Keep Merge Queue Pull Requests Out of Your Way the drafts. When the batch passes, Mergify merges the original pull requests and closes the draft. To merge the tested commit itself, see fast-forward and merge-batch.

With a {min, max} range as batch_size, Mergify spreads the queue over the free parallel checks: batches stay at min while the queue is light and grow toward max when it backs up.

.mergify.ymlyaml
queue_rules:
- name: default
batch_size:
min: 1
max: 10
check 1 check 2 check 3 check 4 check 5 3 queued 1 PR 1 PR 1 PR 1 PR 1 PR 1 PR 7 queued 2 PRs 2 PRs 2 PRs 2 PRs 1 PR 1 PR 1 PR 1 PR 1 PR 1 PR 10 queued 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 12 queued, 2 wait 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs check 1 check 2 check 3 check 4 check 5 3 queued 1 PR 1 PR 1 PR 1 PR 1 PR 1 PR 7 queued 2 PRs 2 PRs 2 PRs 2 PRs 1 PR 1 PR 1 PR 1 PR 1 PR 1 PR 10 queued 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 12 queued, 2 wait 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs 2 PRs
With 5 free checks and a batch_size from 1 to 2, the queue is shared over the free checks: a light queue stays in batches of 1 and leaves checks idle, the larger batches come first as it grows, and past 10 pull requests the rest wait for a check.

How pull requests are grouped into a batch

Section titled How pull requests are grouped into a batch

A batch is not always the next pull requests in the queue. Mergify fills it with pull requests that touch the same scopes, or the same directories without scopes, so a failure drags fewer unrelated changes with it. It never takes a pull request ahead of a higher priority, and keeps a stack in one batch. Parallel mode batches by scope differently: see Batching in parallel mode.

cluster_batch1 Batch 1 cluster_batch2 Batch 2 PR1 PR #1 (api/) PR3 PR #3 (api/) PR2 PR #2 (docs/) PR4 PR #4 (web/) cluster_batch1 Batch 1 cluster_batch2 Batch 2 PR1 PR #1 (api/) PR3 PR #3 (api/) PR2 PR #2 (docs/) PR4 PR #4 (web/)
With batch_size: 2, PR #3 joins PR #1, which touches the same area, ahead of PR #2

In-place checks (no batch PRs)

Section titled In-place checks (no batch PRs)

With batch_size: 1 and max_parallel_checks: 1 in serial mode, Mergify can test each pull request in place, on its own branch, with no draft pull request: max_parallel_checks lists every condition. Mergify updates that branch itself, which GitHub refuses for some pull requests, such as one opened by another bot: see Combining merge and update methods.

Handling batch failure or timeout

Section titled Handling batch failure or timeout

When a batch fails, or its checks time out, Mergify splits it to find the pull request that broke it: that one leaves the queue and the others merge. The batches tested on top of the failed one are cancelled, and their pull requests are tested again. While it runs, the batches report a batch status such as bisecting in the dashboard and the CLI.

With batch_max_failure_resolution_attempts, Mergify stops splitting after that many rounds, and the pull requests it could not clear leave the queue with a dequeue reason that says so.

With skip_intermediate_results, a batch that passes also merges the batches it was tested on top of, so a flaky failure there no longer holds them up.

When a Batch Fails draws the split, the batch sizes that split cleanly, both options, and Fail First, which makes each split cheaper.

Under queue_rules:

batch_max_failure_resolution_attemptsinteger or null·defaultnull#

The number of attempts to resolve a batch failure before dequeueing pull requests. By default, Mergify will attempt to resolve a batch failure by splitting the batch multiple times until it finds the root cause of the failure. You can stop this process earlier by limiting the number of resolution attempts. Setting this to 0 will dequeue all the pull requests from a batch when a batch fails.

batch_max_wait_timeduration·default30 seconds#

The maximum amount of time to wait for additional pull requests before processing a batch that hasn't reached batch_size. The timer starts when the first pull request enters the batch. If batch_size is reached before this time expires, the batch processes immediately. This does not enforce a minimum delay between batches.

batch_sizeinteger or {min, max}·default1#

The number of pull requests per speculative check in the queue. Either a single integer (fixed size, 1-128) or an object {min, max} for dynamic batching: the queue uses min when parallel-check slots are plentiful and grows toward max to keep the backlog at zero.

Under merge_queue:

skip_intermediate_resultsboolean·defaultfalse#

Allow PRs to merge even if their own speculative check fails, as long as later downstream checks including them pass and test every scope they touch between them, and schedule conditions are valid.

Was this page helpful?