# The queue finds the pull request that broke main and reverts it.

Five pull requests land as one batch. When it goes red, the queue bisects it, reverts the culprit and merges the rest.

[Set up the queue](https://sailfork.com/docs/branches#merge-queue) [Stack pull requests](https://sailfork.com/docs/pull-requests#stacked-pull-requests)

Merge queue acme/shop, guarding main

Batch a41f9c2

red, bisecting

|||||
|-|-|-|-|
|#412|Paginate order historyana|ana|passes|
|#413|Add currency to cart totalsbo|bo|passes|
|#414|Cache product lookupsana|ana|passes|
|#415|Switch tax rounding to centsravi|ravi|breaks it|
|#416|Fix empty cart redirectbo|bo|lands after the break|

\#415 breaks it: the checks pass before it landed and fail after.

Waiting, queued as one stack

\#417 #418 #419

## A red batch is searched until one pull request is left.

Nothing more lands. The queue tests the landings between the last good tip and the red one, and names the first that fails.

[How the bisect works](https://sailfork.com/docs/branches#merge-queue)

1. \#412

   Not tested

2. \#413

   Not tested

3. \#414

   Test 1: green

4. \#415

   Test 2: red

5. \#416

   Not tested

- Last good tip

  main before #412

- Result

  \#415 is the first landing that fails

Left the queue

sailfork queue status

||||
|-|-|-|
|#412|Paginate order history In batch a41f9c2, landed by ana|merged|
|#413|Add currency to cart totals In batch a41f9c2, landed by bo|merged|
|#414|Cache product lookups In batch a41f9c2, landed by ana|merged|
|#415|Switch tax rounding to cents Reverted in #420|reverted|
|#416|Fix empty cart redirect Tested again after the revert|merged|

\#420 Revert "Switch tax rounding to cents"

Opened by the queue as ravi, who queued #415. Tested before the next batch went in.

## The culprit is reverted and the rest keep their merge.

The queue lands a revert through an ordinary pull request, as whoever queued the culprit, and tests it before the next batch goes in.

[What the queue reverts](https://sailfork.com/docs/branches#merge-queue)

## A stack lands bottom first, one level at a time.

Base a pull request on another with pr create --onto. Each shows only its own commits, and each level moves onto main as the one below it merges.

[Stacked pull requests](https://sailfork.com/docs/pull-requests#stacked-pull-requests)

1\. Queued

- \#419 open

  ship-ui into ship-api

- \#418 open

  ship-api into ship-rates

- \#417 open

  ship-rates into main

2\. Bottom lands

- \#419 open

  ship-ui into ship-api

- \#418 open

  ship-api into main

- \#417 merged

  into main

3\. Middle lands

- \#419 open

  ship-ui into main

- \#418 merged

  into main

- \#417 merged

  into main

4\. Top lands

- \#419 merged

  into main

- \#418 merged

  into main

- \#417 merged

  into main

## The head you reviewed is the head that merges.

If the branch moved after the review, the merge is refused and nothing lands. The queue pins the reviewed head the same way.

[Merge options](https://sailfork.com/docs/pull-requests#merge)

\#418 Shipping rate API

Merge refused

- Head you reviewed

  3f2a9c1

- Head on the branch now

  8be41d0

ana pushed one more commit after the review. Nothing merged, and the command exited with 10.

## The same afternoon from the terminal

Queue, read the status, hit a moved head, then merge the stack.

\~/acme/shop

```
~/acme/shop $ sailfork pr merge 416 --auto
Queued #416 for the merge queue (place 5): it lands as bo when its checks pass and the rules allow it, if the branch is still at 5d0c7e1
~/acme/shop $ sailfork queue status
Merge queue of acme/shop, guarding main
Waiting: none
Batch a41f9c2 red: #412, #413, #414, #415, #416 (#415 breaks it: the checks pass before it landed and fail after. It was reverted in #420.)
Left: #415 (reverted in #420)
~/acme/shop $ sailfork pr merge 418 --match-head-commit 3f2a9c1
error: pull request #418: the branch is no longer at the head you reviewed (3f2a9c1)
hint: review the new commits, then merge with the current --match-head-commit
~/acme/shop $ echo $?
10
~/acme/shop $ sailfork pr stack 419
#417 open checks passing review approved Add shipping rates table  ship-rates -> main
  #418 open checks passing review approved Shipping rate API  ship-api -> ship-rates
    #419 open checks passing review approved Checkout shows shipping options  ship-ui -> ship-api  <- this
~/acme/shop $ sailfork pr merge 419 --stack
#417: merged at 9ad41e2
#418: merged at c07b3f8
#419: merged at 4e1d6a0
~/acme/shop $ 
```

## Limits

- A batch holds 1 to 10 pull requests, 1 by default, and 4 landed batches may be untested at once, up to 32, before the queue waits for CI.
- A tip that shows no check at all for 10 minutes counts as tested.
- Queue status lists what left the queue and why for 7 days.
- A stack merges up to 32 levels, bottom first.
- A merge with --match-head-commit exits 10 and merges nothing when the branch moved.

## Questions

###

A repository admin turns on Use a merge queue under Settings, Merge queue. Someone with write access then queues a pull request with sailfork pr merge N --auto.

###

The batch stays failed with the reason in its note, and nothing lands until a person resolves it.

###

No. Merging past the queue needs a person in the browser and a reason, which goes to the audit log. A token is refused.

###

The stack waits in the queue as one unit and lands bottom first. Without the queue, sailfork pr merge TOP --stack merges the levels below first, stops at the first failure and names what merged.
