: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(agents): add stacking-prs skill for native stacked PRs (#75452)
Raúl Negrón-Otero743311540c9d
diff --git a/.agents/skills/merging-prs/SKILL.md b/.agents/skills/merging-prs/SKILL.mdindex 6f11edc12a9e..daacc2dacce2 100644--- a/.agents/skills/merging-prs/SKILL.md+++ b/.agents/skills/merging-prs/SKILL.md@@ -22,13 +22,14 @@ Resolve the repo slug once if you need it: `REPO=$(gh repo view --json nameWithO## 1. Preflight```bash-gh pr view <n> --json state,isDraft,mergeable,reviewDecision,statusCheckRollup+gh pr view <n> --json state,isDraft,mergeable,reviewDecision,statusCheckRollup,baseRefName```- **Not open** (already merged/closed) → report and stop.- **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.## 2. Enqueuediff --git a/.agents/skills/stacking-prs/SKILL.md b/.agents/skills/stacking-prs/SKILL.mdnew file mode 100644index 000000000000..4ce34ba0b6f4--- /dev/null+++ b/.agents/skills/stacking-prs/SKILL.md@@ -0,0 +1,100 @@+---+name: stacking-prs+description: >+ Create and manage GitHub native Stacked PRs in this repo with the `gh stack` CLI.+ 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`.+---++# Stacked PRs with `gh stack`++GitHub's native stacked PRs are enabled on this repo.+A stack is an ordered chain of PRs where each one targets the branch of the PR below it; the bottom PR targets `master`.+GitHub tracks the chain as a first-class object: the PR UI shows a stack map, branch protections (code owner approval, required checks) apply to **every** layer including mid-stack ones, and CI that runs on `master` PRs runs on every layer.++Setup (this skill is written against `gh-stack` v0.1.0):++```bash+gh extension install github/gh-stack # or: gh extension upgrade stack+```++Upstream docs: [about stacked PRs](https://docs.github.com/en/pull-requests/get-started/about-stacked-prs), [CLI commands](https://docs.github.com/en/pull-requests/reference/stacked-prs-cli-commands).++## Create a stack++```bash+gh stack init my-feature-db # bottom branch, based on master+# ...commit...+gh stack add my-feature-api # next layer, based on the previous branch+# ...commit...+gh stack add -Am "add UI" my-feature-ui # stage all + commit in one step+```++- Adopt existing local branches (bottom to top): `gh stack init branch1 branch2 branch3`.+- Link PRs that already exist on GitHub, without local tracking: `gh stack link <pr> <pr> <pr>`, bottom to top (branch names and PR URLs work too). Pass a stack number first to append to an existing stack: `gh stack link <stack> <pr>`.+- Slice by reviewable unit: migration / backend / frontend, or mechanical-rename / behavior-change. Each PR must make sense to review and merge alone.+- Keep stacks shallow (2–4 layers). Every layer multiplies CI cost and rebase churn, and deep-stack pushes can trip GitHub's dispatch cap (see AGENTS.md, "Stacked PRs").++## Publish++```bash+gh stack submit --auto+```++Pushes all branches, creates each PR with the correct base, and links the stack on GitHub.+`--auto` creates new PRs **as drafts**, the right default here, since drafts run the narrowed CI matrix.+Mark layers ready individually with `gh pr ready <n>`, or pass `--open` to mark everything ready.+Running `gh stack submit` with no flags opens an interactive editor for titles and descriptions instead.+New PRs default to ready-for-review in that editor, so flip its "CREATE AS" toggle if you want drafts.++Each layer is a normal PR: it needs a conventional-commit title and a description filled from `.github/pull_request_template.md`.++## Iterate and keep in sync++```bash+gh stack sync # fetch, cascade-rebase onto master and each parent, force-with-lease push, sync PR state+gh stack sync --prune # also delete local branches for merged PRs+```++- To fix a mid-stack layer: check out that branch (`gh stack down` / `gh stack switch`), commit, then `gh stack sync` (or `gh stack rebase --upstack` to rebase only the layers above you, `--no-trunk` to skip pulling master).+- On rebase conflict, sync restores all branches untouched; run `gh stack rebase`, resolve, then `gh stack rebase --continue` (or `--abort`).+- `gh stack view --short` shows status (`--json` for scripting); a `⚠` means that layer needs a rebase, which blocks merging. `gh stack checkout <stack-number|PR|URL>` pulls down and tracks a stack you don't have locally, including a teammate's.+- `gh stack modify` interactively reorders, folds, drops, or renames layers. `gh stack unstack` removes the stack on GitHub (`--local` to only drop local tracking).+- Batch work before syncing. Each sync force-pushes and re-runs a full CI matrix for every rebased layer, so sync when you need the rebase, not to track master.+- The `ci:preflight` pre-push hook runs on these pushes like any other; never bypass it.++## 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:++```bash+gh stack sync --prune # replay the remaining layers onto the squashed commit, drop the merged branch+```++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.++Every layer is gated on its own approving review, code owner review, required checks, and signed commits.+Rule bypass and auto-merge are both unsupported for stacks, so `--auto` won't help you here.++Never `gh stack sync`, `rebase`, or `push` while a layer sits in the merge queue; the force-push kicks it out.+`gh stack push` knows to skip branches queued in _GitHub's_ merge queue, but it can't see Trunk's.++## Scripting++- List stacks: `gh api repos/{owner}/{repo}/stacks`; one stack: `.../stacks/<stack-number>`. Stack numbers come from the same sequence as PR numbers, so they never collide.+- Local stack state: `gh stack view --json`.++## Limits++All branches must live in the same repository (no cross-fork stacks), and the chain must be strictly linear: no branching structures, and every layer needs a rebase before it can merge.+GitHub Desktop doesn't support stacks at all.+These are preview-era constraints, so check the [upstream docs](https://docs.github.com/en/pull-requests/reference/stacked-prs-cli-commands) before concluding something is impossible.diff --git a/.github/pull_request_template.md b/.github/pull_request_template.mdindex 55cda75de4c3..25181b21c7b6 100644--- a/.github/pull_request_template.md+++ b/.github/pull_request_template.md@@ -62,6 +62,7 @@- Description: high-level rationale, not a step-by-step replay.- Body: pass it straight to the creation tool's `body` arg (GitHub MCP `create_pull_request` body, or `gh pr create --body-file -` via stdin) — don't write it to a temp file first; the arg preserves markdown and newlines verbatim.- Public OSS repo: no internal customers, incidents, or operational metrics.+- Stack instead of stuffing: if the diff holds two or more separable steps (migration then behavior, rename then rewrite), open a stack rather than one big PR. See AGENTS.md, "Stacked PRs" and /stacking-prs.- Draft by default: open new PRs as drafts (`gh pr create --draft`) — drafts run only a narrow CI subset and save runner credits. Fix CI and run affected tests locally before marking ready for review.- Labels: apply `skip-agent-review` for trivial/chore PRs that don't need Copilot or Greptile review.- When a human directed the work, the PR must be attributable to that person, even if agent-assisted.diff --git a/AGENTS.md b/AGENTS.mdindex 091620cd0f78..5b645c3357a8 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -97,6 +97,10 @@ 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.+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.Pushing a deep stack at once can exceed GitHub's per-repo dispatch cap (500 workflow runs / 10s).@@ -234,6 +238,7 @@ ALWAYS invoke the matching skill **before** writing or reviewing code in these a**Invoke when in the area:**- `/merging-prs` — merging a PR, or babysitting one through the Trunk merge queue+- `/stacking-prs` — creating, restacking, adopting, or landing a stack of PRs (`gh stack`)- `/implementing-mcp-tools` — adding/modifying endpoints or `tools.yaml`- `/modifying-taxonomic-filter` — any TaxonomicFilter change- `/sending-notifications` — adding notification support