Land a merge request: close its claimed ticket, check the gate record on a gated base, merge pinned to the reviewed head, read the result back, sync local main. Cleanup is left to /roar.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Merge?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/minhhaduong-merge)
---
metadata:
category: build
order: 5
name: merge
description: "Land a merge request: close its claimed ticket, check the gate record on a gated base, merge pinned to the reviewed head, read the result back, sync local main. Cleanup is left to /roar."
user-invocable: true
argument-hint: "[pr-number]"
---
# Merge $ARGUMENTS
Run each command yourself, from the merge request's own worktree on its head
branch, and read each exit code on its own line, never the tail of a pipe.
For helper commands, set `IDH_ROOT="${IDH_ROOT:-$(p="<loaded-SKILL.md>"; [ -d "$p" ] || p=$(dirname "$p"); cd -P "$p/../.." && pwd -P)}"` in the same shell call. Replace `<loaded-SKILL.md>` with the absolute path the runtime supplied for this skill, its SKILL.md or its directory; a pre-set `IDH_ROOT` wins. This follows a projected skill symlink to the canonical checkout; do not derive the helper root from the project cwd.
Close claims, short ids, fences, the attribution warning and the edge-case
index: `references/claims.md`. Read it when the body carries a `Ticket` line
you are unsure of, or a case below sends you there.
## Gating tiers
The tier is read from the diff, never judged:
`python3 "$IDH_ROOT/scripts/merge-gate.py" tier --base origin/<base> --head HEAD`
answers 0 bookkeeping (with `--since`, also `unchanged`), 1 full (an empty
diff included), 3 could not read (treat as full). A seat report added as a
plain `.md` under `tickets/reviews/` is bookkeeping; an edited, deleted or
executable one is full.
| Tier | Gating |
|------|--------|
| bookkeeping | Mechanical checks only: on a gated base, the record; on an ungated base, the repo's CI. No gaze, no verify-gate, no review seat. |
| full | gaze, then verify-gate APPROVED; on a gated base, the record. |
Before merging a foreign ticket-only PR, apply the substantive receiving-project
Imagine acceptance review in `rules/workflow.md` § Cross-project work, including
its completion-log case. This is receiving-owner judgment before mechanical
landing; the tier governs merge checks and grants no implementation priority.
**Two moments, whatever the tier** (ticket 1245, tracker 1226). On a gated
base, `.merge-gate.json` declares the full check set (`"checks"`) and its
cheap subset (`"before"`): ticket validator, guards, catalog drift and
`make lint`, no test suite. *Before the merge*, the record (steps 4 to 6)
runs the before set on the candidate and is what the merge rests on.
*After the merge*, step 9 runs the full set, test suite included, on the
new tip of main; a red there is reported, never reverted (Trust, Verify,
Monitor). A change to the gate itself is therefore fully tested only once
it is on main.
**The review evidence is on notes** (F1, ticket 1301): a gaze record is the
review's latest `answer` entry (`review_notes.py answers --unit pr:<n> --latest`)
and a verdict is its `verdict` entry; the PR comments are one-line pointers to
them. **A gaze record with `seats: self-only`, or with no `seats:` line, is a
review like any other** (author ruling 2026-11-01; definition:
`skills/gaze/SKILL.md` § 4): the gate takes it, and reuse follows its result
and its head. A panel is preferred, never required.
**A branch review carries over to the PR** (ticket 1379). A gaze answered on
`branch:<name>` before the PR existed is the PR's review when its reviewed
head is the head that lands, or the PR adds bookkeeping to it
(`review_notes.open_review` adopts it when the `pr:<n>` review is opened);
any other delta discards it and the PR gets a fresh review. One gaze per
request at a time still holds.
This is what lets an escalation's built option be reviewed before the author
answers (`skills/route/SKILL.md` § Escalation, step 2). The 5-minute cap
binds the building only. Gaze `branch:<name>` on the recommended option, plus
the option the author is likely to pick, not on every option. The question to
the author carries the result, or is dropped when the result settles it. Each
option is built in its own worktree; until the author answers, no outward act
(no merge, no post, no other forge write) except gaze's notes sync.
**A commit added after approval is gated by the tier of its own diff:**
`merge-gate.py tier --base origin/<base> --head HEAD --since <ruled_tip_sha>`.
Bookkeeping or unchanged: the APPROVED verdict stands, no review or gate
round is spent; on a gated base the record is re-run on the new head. Full:
re-gate.
## Before merging
- **Merge method drifts per repo.** This harness disables squash, so the
recipe passes `--merge`; a squash-only repo rejects that flag. Read the
repo's merge settings at merge time, and trust the merge attempt over the
flag.
- **Fix rounds after gaze:** one round, plus a second for fix-on-fix findings
that carry a reproduction, as `skills/raid/references/fix-and-regate.md` states.
- **After gaze, sync before closing the ticket.** Gaze makes no commits,
but a fix cycle or another session may have pushed:
`git fetch origin && git merge --ff-only origin/<branch>` first, or a stale
rebase drops those commits and the close commit lands on the wrong base.
- **Close the ticket on the branch before gating.** Close each claimed
ticket (step 1) before the round-1 verify-gate; step 1 at merge time
then finds nothing to do. A close commit pushed after the gate is a
bookkeeping delta: the approval stands. An unpushed local commit would
ride along, so push first.
- **Merge prerequisite, full tier: the gate's verdict is APPROVED and
what `origin/<branch>` adds to the gate's `ruled_tip_sha` (read after
`git fetch origin`) is bookkeeping, an empty delta included (§ Gating
tiers); otherwise re-gate, do not merge.** A bookkeeping-tier
request needs no verdict. A full-tier request with none yet is gated as
`verify-gate <pr> repo=<PR's worktree> session=<uuid>`, one UUID for round
1 and the one re-gate (`skills/verify-gate/SKILL.md` § Gate sessions). A
raid's Phase 6 verdict is that verdict: never gate it again here.
**Head checks, immediately before the merge:** `git fetch origin`, then
`git rev-parse HEAD` == `git rev-parse origin/<branch>` (a mismatch means
sync, never merge) and, full tier, `merge-gate.py tier --since <ruled_tip_sha>`
answers 0 (otherwise re-gate). The record on a gated base
belongs to that same head.
- **Run the gate record on padme when reachable**, over ssh from another
host; otherwise where you are.
## The recipe
`"$IDH_ROOT/scripts/raid_land.py"` executes steps 0 to 8 for one request in one call (the raid's Phase 7), step 8 included, and posts the duration comment; step 9 follows from its sync. This recipe stays the contract it follows.
`N` is the merge request, `<branch>` its head branch, `<base>` its base.
Start the step clock before step 0 and end it after step 8 (`skills/gaze/references/output.md`
§ Duration clock). The `duration:` line goes in the report and, always, in a comment
on the request (`gh pr comment N --body "merge <head>: duration: …"`). <!-- harness-extension-point -->
<!-- harness-extension-point -->
Reads below go through `forge.py` (`resolve`, `list`, `read-back`; for `list` and
`read-back` exit 3 means no forge and 2 could not look, `resolve` refuses with exit 1;
`forge.py` docstring). Any non-zero exit is a stop, never an empty answer. Exit 3 on
`N` means the unit is no forge request: it lands as `branch:<name> [base=<ref>]`
through `raid_land.py`, the local gated merge (`skills/raid/SKILL.md` § Phase 7, "No forge"). Writes with no `forge.py`
verb (comment, ready, disarm, merge) keep the current forge CLI's spelling behind a
marker; another forge needs the same writes in its own spelling.
0. **Read it, on its branch.** `git rev-parse --abbrev-ref HEAD` must print
`<branch>`; otherwise stop. Read the request once:
`python3 "$IDH_ROOT/scripts/forge.py" resolve N`
(its `state`, `draft`, `branch`, `base`, `head` and `body`). It must be open,
and read from the forge: an answer with `cached: true` (or `forge: unread …`) comes
from the offline cache, not a landing read, so stop and read again later. Parse the body's close claims (`references/claims.md`)
and run the attribution check there; its warning never refuses.
1. **Close.** For each claimed ticket not already in `tickets/closed/` with
a `Closed:` header:
```bash
"${ERG:-tickets/erg}" close <id> "autoclosed — PR #N"
"${ERG:-tickets/erg}" archive <id> || true # an erg whose close already archives answers "no ticket found"
git add -u tickets/ && git add tickets/closed/<id>-*.erg
```
then one commit for all of them, `git commit -m "ticket(<ids>): close and
archive — PR #N"` with the ids joined by `, `, and `git push origin HEAD`.
Do not reword that message. A claimed ticket absent from both
directories: stop, the branch or the claim is wrong. `-u` stages the
dependents whose `Blocked-by` the close removed, never a stray untracked
file; the explicit add of the `closed/` path stages the edited blob.
2. **Ready.** A draft request is marked ready: `gh pr ready N` <!-- harness-extension-point -->
3. **Same head.** `git fetch origin`, then the head checks of § Before
merging. Re-read the body and compare its close claims with the set the
gate ruled on: a body edited after approval is a stop and a re-gate.
Then recheck the human and Copilot reviews (ticket 1308): the gate may have
ruled with the forge unread, and reviews keep arriving. A CHANGES_REQUESTED
review (an author's latest deciding one) or an unresolved review thread
newer than the verdict's `forge_read` (every one when it reads `unread`) is
a stop: resolve it or re-gate. An unreadable recheck is a stop too; landing
reads keep their 120 s bound and never use the offline cache.
`raid_land.py` runs this right after step 0's claims parse (`recheck_reviews`).
4. **Gate.** `python3 "$IDH_ROOT/scripts/merge-gate.py" enabled --base origin/<base>`
answers 0 gated, 1 ungated, 3 could not read (stop; never remove the file
to get through). On a gated base:
```bash
python3 "$IDH_ROOT/scripts/merge-gate.py" check --base origin/<base> --head HEAD
```
0 pass: go on. 2 no record for this candidate (none yet, or the base
moved): write it with `merge-gate.py run --base origin/<base> --head HEAD`
from this checkout, then `check` again; re-recording spends no review
round. 1 fail or stale scope, 3 unreadable: do not merge.
5. **Disarm (gated base only).** Never arm auto-merge: an armed request
could land a later head than the record covers. Read request N by its number,
`python3 "$IDH_ROOT/scripts/forge.py" read-back N` (never a branch lookup: two open
requests may share a head branch); its third field is `queued` when armed;
on `queued`, run `gh pr merge N --disable-auto` and read again; still armed: <!-- harness-extension-point -->
do not merge. A non-zero exit or an empty read is not "not armed": do not merge.
5a. **Push the review evidence.** `python3 "$IDH_ROOT/scripts/review_notes.py" push-landing <branch>`
pushes `refs/notes/review` and the review-heads of the requests naming `<branch>`, never
forced. It prints the refs pushed and does nothing when the branch has no review notes
or the repository has no remote; a landing head missing locally is restored from the notes when its commit survives; a non-zero exit stops the merge. On a forge, then render
the attribution block of notes into the body, right before the merge:
`python3 "$IDH_ROOT/scripts/attribution_record.py" --render-pr N` (`references/claims.md`
§ Attribution block warning), with `--session-model <your verbatim model id>` so a review without a
writer records you as the writer; it exits 0 and prints one `not derivable: <fact>` line per lost fact
(a lost edit included): a warning, never a stop.
6. **Merge.** Gated base:
`gh pr merge N --merge --match-head-commit "$(git rev-parse HEAD)"`. <!-- harness-extension-point -->
Never `--auto`; never `--delete-branch`. Ungated base:
`gh pr merge N --merge --auto`, or without `--auto` where the repo has <!-- harness-extension-point -->
auto-merge off and every check is done.
7. **Read back.**
`python3 "$IDH_ROOT/scripts/forge.py" read-back N`
must read `MERGED <the head of step 3> -`. MERGED at another head is not a
gated merge: report it. `OPEN … queued` (ungated base): § Waiting for a
queued merge; `OPEN … -` is not queued. A read that fails or prints
nothing is unreadable: stop and report, never re-run the merge. The exit
code of the merge command proves nothing either way.
8. **Sync.** `"$IDH_ROOT/scripts/sync-local-main.sh" . <base>`. A "left
untouched" line goes in the report, never forced; never a hand-rolled
`merge --ff-only` on the primary checkout.
9. **After-merge run (gated base).** Nothing to start: step 8's sync moves
local main, and the main-update hook (`hooks/reference-transaction`,
§ after-merge start) starts the runner detached on that move. Read
`$(git rev-parse --git-common-dir)/idh/after-merge.log`, never wait on it
in the foreground. To hear its result, arm the wake line `raid_land.py`
prints after a gated landing (`after-merge: arm the wake …`, through
`runtime.py wake arm`): `merge-gate.py wait-after --tip <tip>` exits on
the tip's record (0 pass, 1 red, 5 environment, 2 none within 600 s; the
check set takes about a minute). A red also raises an author alert
(the `notify` alert file, plus a popup where notify-send exists); red stays the lander's to report,
never broadcast.
The runner runs the full set on the newest `<base>` tip and notes the record there
(a busy lock means a runner already covers this tip; `covered` means the
tip already carries a record; an `environment` record, a failure on locked
modules this host lacks, opens no ticket and is judged again at the next start). A sync that left main untouched starts
nothing; the next move of main does, and `main_sweep.py --after` flags a
tip left an hour without a record. A red never blocks
this merge: the log and the note carry it, and `main_sweep.py --after`
reports it. On red, the runner (the hook passes `--open-ticket`) opens the ticket itself: a ticket-only
request from branch `red-<tip12>`, landed by `raid_land.py`, none when an
open ticket or a `red-*` branch already carries the same failing checks.
## Gated base
A base whose tree carries `.merge-gate.json` with `"gate": "on"` is gated;
steps 4 to 7 and 9 apply. A `--no-push` trial record never admits a merge.
**Background merge.** The wait is the record run, so steps 4 to 8 can run as
one background command. A `check` that answers 2 again after one re-record
(the base keeps moving) goes in the report, not into a loop.
**Waiting for a queued merge.** The caller waits itself and finishes the
chain itself. Step 7's read-back is the single-read status command. The
caller arms exactly one wake,
`python3 "$IDH_ROOT/scripts/runtime.py" wake arm --after 0 --cmd "$poll"`, whose
`$poll` (below, read through a quoted heredoc so nothing in it expands early; write `N` and
`$IDH_ROOT` as their values before arming)
has a hard time bound of about 25 minutes,
polls this single-read status command at an interval inside the command
and exits as soon as the status is no longer pending; the runtime wakes the
caller on exit, and the caller continues from the status it reads (the
answers of `wake arm` are read as in `$IDH_ROOT/skills/raid/references/sitrep.md`
§ Wake sources). Never ask the author to wait or to re-run later; never a
fixed-delay timer (it waits past the event); never an unbounded or
foreground loop. A runtime where `wake arm` answers NOOP asks once at its
next step and reports the PR as pending.
```bash
poll=$(cat <<'POLL'
end=$((SECONDS + 1500)); while [ "$SECONDS" -lt "$end" ]; do s=$(python3 "$IDH_ROOT/scripts/forge.py" read-back N) || break; case "$s" in "OPEN "*" queued") sleep 60;; *) break;; esac; done
python3 "$IDH_ROOT/scripts/forge.py" read-back N # MERGED: sync (step 8); CLOSED: failed; OPEN: still queued at the bound (a failing check leaves auto-merge armed: read the checks) or not queued; exit 2 or 3: unreadable, stop
POLL
)
python3 "$IDH_ROOT/scripts/runtime.py" wake arm --after 0 --cmd "$poll"
```
## Merge conflict recovery
- **Multi-PR wave on one file: verify the union survived, don't trust a
clean exit.** Fetch before each sibling merge. A stale `origin/main` ref
auto-merges cleanly while dropping a sibling's non-conflicting addition:
no conflict, exit 0, wrong content. Grep the merged file for every
sibling's marker before committing. On a drop, don't hand-patch: restore
the known-good base by writing `git show origin/main:<file>` to the path
(never `git checkout <ref> -- <path>`, which overwrites the index),
re-layer only this PR's change, re-verify.
- **Conflict inside a *generated* file: regenerate, don't hand-merge.**
Hand-merging rows mixes one side's text with the other's measurements, so
resolve the *source*. The reverse trap: regenerating from a stale input
reverts the other branch's data fix behind a clean merge and a green
suite. Take `origin/main`'s copy as the base, regenerate to a scratch
path, and grep the one value the other branch changed. Reproduces →
commit. Reverts → your input is stale.
## When a step stops
- **Force-push denied, branch already pushed.** A rebase rewrote the branch,
local diverges from the remote, and the step-1 close commit sits on the
local rewrite with its push rejected. Check out the origin branch tip
detached, `git cherry-pick <close-commit>`, fast-forward push, re-gate that
head.
- **Detached HEAD after `merge --ff-only`.** `git checkout <branch>`, then
resume at step 0.
- **A merge that skipped step 1** (the web button, another session): verify
each `**Ticket:**` claim at once; the ticket must be in `tickets/closed/`
with a `Closed:` header. Repair on a separate branch and merge request
(`references/claims.md` § Repair). After a merge wave, run the sweep from
the updated base checkout:
`bash "$IDH_ROOT/skills/roar/check-close-claims.sh" --days 7 --limit 40`.