PR Merge Queue
Process open PRs in batches with explicit pause/summary points. Designed to replace ad-hoc ralph loops that hit usage limits and wrong-branch commits.
Protocol
- Enumerate.
gh pr list --json number,title,headRefName,mergeable,isDraft,statusCheckRollup,reviewDecision. Skip drafts. - Batch size = 5. Process 5 at a time, then STOP for summary.
- Per-PR steps:
git branch --show-current— verify NOT on PR branch before any operation- Check CI status; if red and trivial (lint/type) → rebase + fix on PR branch only
- If mergeable + approved → squash merge via
gh pr merge --squash --auto - If conflicts → rebase onto main; if non-trivial, skip + log reason
- NEVER edit
prisma/schema.prisma, migrations, or protected paths. Flag + skip.
- Checkpoint after each batch:
- Post summary comment listing: merged / skipped+reason / blocked
- Pause for user confirmation OR auto-resume only if explicitly authorized
- Stop conditions:
- Backlog cleared
- 3 consecutive failures → stop + escalate
- Protected-path PR encountered → stop + ask
- Usage approaching limit → checkpoint summary + exit cleanly
Verification
Before any gh pr merge or git push:
- Confirm target branch via
gh pr view <n> --json baseRefName - Confirm local branch != PR head (avoid accidental fixup commits to feature branch)
Output
Final report: [merged: N] [skipped: M reasons] [escalated: K reasons]. One line per PR.