Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(agents): document whole-stack trunk merges and stamphog re-apply (#84374)

Georges-Antoine Assi04e5b138d6c2
diff --git a/.agents/skills/merging-prs/SKILL.md b/.agents/skills/merging-prs/SKILL.md
index daacc2dacce2..e1c41f518a7f 100644
--- a/.agents/skills/merging-prs/SKILL.md
+++ b/.agents/skills/merging-prs/SKILL.md
@@ -5,7 +5,9 @@ description: >
lands. Enqueue with a `/trunk merge` comment, then watch the `Trunk Merge Queue
(master)` check run and the PR state until it is MERGED or the queue kicks it
out, reporting the Trunk bot's failure reason. Use when asked to merge a PR,
- "merge when ready", "land it", "ship it", or to babysit/watch a PR through the
+ "merge when ready", "land it", "ship it", to merge a whole stack (comment on
+ the top PR — the queue merges it and every layer below atomically), to get a
+ PR approved via the `stamphog` label, or to babysit/watch a PR through the
queue. Never use `gh pr merge` in this repo — the queue is the only path into
master.
---
@@ -29,7 +31,8 @@ gh pr view <n> --json state,isDraft,mergeable,reviewDecision,statusCheckRollup,b
- **Draft** → it can't be merged. Ask the developer to confirm, then `gh pr ready <n>` before continuing. Don't un-draft silently.
- **Failing required checks** (`statusCheckRollup`) → the queue will just reject it. Report which checks are red and stop; fix them first. **Pending** checks are fine — the queue waits for them. To work out _why_ a check is red, use `/debugging-ci-failures`.
- **Merge conflicts** (`mergeable == "CONFLICTING"`) → report and stop; merge `master` in first.
-- **Part of a stack** (`baseRefName != "master"`, or the PR appears in `gh api repos/$REPO/stacks`) → merging it also merges every unmerged layer below it, and the queue only guards merges into `master`. Use `/stacking-prs`, which lands the bottom layer through the queue first.
+- **Missing approval** (`reviewDecision == "REVIEW_REQUIRED"`, or a stamphog approval was dismissed) → apply the `stamphog` label yourself: `gh pr edit <n> --add-label stamphog`. That triggers the automated review-and-approve flow ([tools/pr-approval-agent/README.md](../../../tools/pr-approval-agent/README.md)); on an `APPROVED` verdict the Stamphog app posts the approval that satisfies the required review. Re-applying the label is always safe and is the intended retry path — it gets stripped on a `REFUSED`/`ESCALATE` verdict, and after addressing that feedback you re-apply it to request a fresh review. It stays sticky across ordinary pushes (non-trivial deltas re-review automatically), and it never works on bot-authored PRs.
+- **Part of a stack** (`baseRefName != "master"`, or the PR appears in `gh api repos/$REPO/stacks`) → the queue handles stacks natively: enqueueing a PR enqueues it **and every unmerged layer below it**, tests them together, and merges them atomically. So comment `/trunk merge` on the **top** PR to merge the whole stack, or on the highest layer you want landed to merge just the bottom part. Run this preflight on every layer being merged, not only the one you comment on. `/stacking-prs` covers restack mechanics and the post-merge `gh stack sync --prune`.
## 2. Enqueue
@@ -37,6 +40,9 @@ gh pr view <n> --json state,isDraft,mergeable,reviewDecision,statusCheckRollup,b
gh pr comment <n> --body "/trunk merge"
```
+For a stack, `<n>` is the highest layer you want merged — it and everything below it enqueue together (see the stack preflight bullet above).
+Append `--no-batch` to the comment to have the queue test the PR (or stack) alone instead of batched with other queued PRs.
+
Within ~2 minutes, confirm Trunk picked it up — a check run whose name starts with `Trunk Merge Queue` should appear on the head commit:
```bash
diff --git a/.agents/skills/stacking-prs/SKILL.md b/.agents/skills/stacking-prs/SKILL.md
index 3a12809a9d96..4f9d8b6a6878 100644
--- a/.agents/skills/stacking-prs/SKILL.md
+++ b/.agents/skills/stacking-prs/SKILL.md
@@ -5,8 +5,9 @@ description: >
Use when asked to stack PRs, split a large change into a stack, add a layer to a stack,
restack or rebase a stack, adopt existing branches or PRs into a stack, check out
someone else's stack, or land a stack. Covers creating and submitting stacks
- (draft-first), cascade rebases with `gh stack sync`, and landing one bottom-first
- via `/merging-prs` rather than `gh stack merge`.
+ (draft-first), cascade rebases with `gh stack sync`, and landing one through the
+ Trunk merge queue via `/merging-prs` — whole-stack via `/trunk merge` on the top
+ layer, or bottom-first — never `gh stack merge`.
---
# Stacked PRs with `gh stack`
@@ -69,16 +70,23 @@ gh stack sync --prune # also delete local branches for merged PRs
## Merging
-A stack lands bottom-first, one layer at a time.
-Merge the layer based on `master` via `/merging-prs`, exactly as you would an unstacked PR; being in a stack changes nothing about how it reaches `master`.
-GitHub then retargets the next layer onto `master` and updates the stack:
+Both paths go through the Trunk merge queue via `/merging-prs`; never `gh stack merge`, which merges the chain through GitHub's API and bypasses the queue.
+
+**Whole stack at once (default).**
+The queue handles stacks natively: enqueueing a PR enqueues it and every unmerged layer below it, tests them together, and merges them atomically.
+Comment `/trunk merge` on the **top** PR to land the whole stack, or on the highest layer that's ready to land just the bottom part.
+Every layer being merged must individually pass `/merging-prs` preflight (ready, approved, no failing checks — pending ones are fine, the queue waits for them) — a mid-stack draft or missing approval blocks the layers above it.
+
+**Bottom-first, one layer at a time.**
+Merge the layer based on `master` via `/merging-prs`, exactly as you would an unstacked PR.
+GitHub then retargets the next layer onto `master` and updates the stack.
+
+After either path:
```bash
-gh stack sync --prune # replay the remaining layers onto the squashed commit, drop the merged branch
+gh stack sync --prune # replay the remaining layers onto the squashed commit(s), drop merged branches
```
-Repeat for the new bottom layer.
-
Do **not** use `gh stack merge`.
It merges the whole chain straight through GitHub's API, so the bottom layer reaches `master` outside the path AGENTS.md requires ("Merging PRs").
Merging any layer also merges every unmerged layer below it, so a mid-stack merge is only safe once those layers are reviewed and green.
diff --git a/AGENTS.md b/AGENTS.md
index 2bbe8af42ac0..feb00922e806 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -105,8 +105,8 @@ Guarding it inside the workflow is worse: skipping the gate job cascades to the
#### Stacked PRs
GitHub's native stacked PRs are enabled on this repo — use the `gh stack` CLI and the `/stacking-prs` skill instead of hand-managing branch chains.
-A stack lands bottom-first: merge the layer based on `master` the usual way (see "Merging PRs" below), then `gh stack sync --prune` and repeat.
-Never `gh stack merge` — it merges the whole chain straight through GitHub's API, so the bottom layer reaches `master` outside that path.
+A stack lands through the merge queue: comment `/trunk merge` on the top layer to enqueue the whole stack (the queue tests and merges it and every unmerged layer below it atomically), or land bottom-first one layer at a time; either way, `gh stack sync --prune` afterwards.
+Never `gh stack merge` — it merges the whole chain straight through GitHub's API, so the stack reaches `master` outside the queue.
Restacking force-pushes every branch, and each push triggers a full CI fan-out.
Never restack while any branch in the stack is sitting in the merge queue — the force-push removes it from the queue.
@@ -136,8 +136,9 @@ In environments without hooks (no `node_modules`), run `hogli ci:preflight --fix
All merges into `master` go through the Trunk merge queue.
Never run `gh pr merge` or click the GitHub merge button — both are blocked by branch ruleset.
-- Enqueue: `gh pr comment <number> --body "/trunk merge"`. Cancel: `gh pr comment <number> --body "/trunk cancel"`.
+- Enqueue: `gh pr comment <number> --body "/trunk merge"`. Cancel: `gh pr comment <number> --body "/trunk cancel"`. Enqueueing a stacked PR also enqueues every unmerged layer below it — comment on the top PR to merge the whole stack. `--no-batch` opts the PR (or stack) out of batching.
- The Trunk CLI is an alternative to the comments: `trunk merge <number>` enqueues, `trunk merge status <number>` inspects, `trunk merge cancel <number>` dequeues. It ships in the flox environment but needs a one-time interactive `trunk login`, so agents and headless environments should keep using the comments.
+- Missing required approval: apply the `stamphog` label (`gh pr edit <number> --add-label stamphog`) to trigger the automated review-and-approve flow, and re-apply it whenever it was stripped (`REFUSED`/`ESCALATE` verdict) once the feedback is addressed — re-applying is always safe.
- After enqueueing, babysit the PR until it merges or fails — follow [`.agents/skills/merging-prs/SKILL.md`](./.agents/skills/merging-prs/SKILL.md) for the preflight, watch, and failure-handling loop.
- Queue progress is the `Trunk Merge Queue (master)` check run on the PR's head commit. The PR's own checks don't reflect the queue's testing — it runs CI on a `trunk-merge/**` branch.
- On failure the Trunk bot comments with links to the failing workflows; fix, push, and re-enqueue.