Skip to content

7. Merging

By the end of this chapter you will know why a pull request is waiting for you, what to do about it, and how to make sure the commit that merges is the one you read.

The short version: approve the pull request on GitHub once no run is in progress, and the merge bot merges the commit you approved within a minute. No agent merges its own work. The flow, as a diagram: when a pull request merges.

Live and shadow

A pull request merges with no human only when its class is live and every one of its checks holds: CI is green, the reviewer approved the current commit, the diff stays inside the class’s limits, and the class’s daily cap is not reached.

A shadow class runs the same checks and records what it would have done, then hands the pull request to you. Each shadow decision you merge unchanged is evidence; a class goes live only on enough of it. So when you merge a shadow pull request without changes, you are also teaching the gate.

Most classes are neither: they always come to you. That is the default, not a failure.

Why a pull request comes to you

The hand-off comment carries a reason. The ones you will meet:

ReasonWhat it meansWhat you do
class_unarmedThis kind of change never merges on its ownReview it; approve to merge, or request changes
policy_pendingThe repository’s policy waits for a maintainerApprove the current commit
shadow_would_armA shadow class would have merged itReview it; approve if the gate was right
approval_staleYour approval was of an older commit, or came while an agent was pushingApprove again, on the current head
approval_requiredThe diff touches files that always need a maintainerReview those files, then approve
auto_merge_cap, class_pausedA live class hit its daily cap, or the breaker paused itApprove, or wait for tomorrow’s cap
human_commit_in_prA person pushed a commit to the agent’s branchRead that commit; an admin merges, or close the pull request

The last row is the one an approval cannot fix. The factory cannot vouch for a commit it did not make, so the merge bot refuses it, and the ruleset blocks a plain merge. A maintainer with admin rights and the ruleset bypass merges it by hand, after reading it.

Every reason, with the check behind it: the gate’s reasons.

Approve the exact head

GitHub attaches an approval to the latest commit at the moment it arrives. If an agent pushes while you read, a command-line approval can approve a commit you never saw, and the merge bot then merges it.

  1. Wait until the room shows no run in progress: no NOW line, the rail’s last node finished.
  2. Approve from GitHub’s web page, which shows you the commit you are approving.
  3. From a terminal, name the commit you read:
gh api repos/<owner>/<repo>/pulls/<number>/reviews \
  -f commit_id=<sha> -f event=APPROVE

If the factory comments approval_stale, a new commit arrived after your approval: read it, approve again.

The merge policy in the room

Every factory room has a Merge policy fold. Open it to see the task’s class and mode (live, shadow or disabled), the class’s conditions, what it takes to merge, and, once there is one, the gate’s decision. It is read-only: a repository’s policy changes through a pull request.

Maintainers change a class, check a change and promote a shadow class from the Settings pages: chapter 11.

Undo a merge

Label a pull request the factory merged on its own factory/revert, within 7 days. The factory opens a pull request that undoes it, and the class’s breaker counts the revert. A merge you approved, you revert by hand, as usual.

The design behind all of this: the merge gate.

Next: chapter 8 brings the factory into your terminal and your coding agent.