Skip to content
Corentin GS

Control Review and CI Costs When Adopting Stacked PRs

№59 · · ·2657 words ·13 min read
In this piece

A bottom-layer update in a four-layer stack can move four branches, update four pull requests, start four workflow runs, and notify every reviewer watching the chain. The feature works as designed; the adoption policy determines whether that fan-out is useful. The previous article explains why rewrites affect Git branches and Jujutsu changes differently.

The bill arrives per published layer

Stacked pull requests promise smaller reviews. Split a large change into ordered layers and each layer gets a focused diff, discussion, and merge decision.

Every published layer is also a pull request, check run, notification stream, and branch to maintain. A lower-layer change can replay that cost across the whole stack through rebases, checks, and notifications.

The answer is not to abandon stacks. A foundation can merge while dependent design remains open, and reviewers can approve it without reading the whole feature. The useful constraint is to publish only layers that carry a separate decision.

Locally, a stack of changes costs little. As the Jujutsu article shows, you can reshape several local changes before they create branches, pull requests, checks, or review work. Publication starts the shared cost.

Four thresholds, four prices

Before scoping anything, name what each layer must be. These four words get used interchangeably, and they are not synonyms:

  • Reviewable: a reviewer can understand the diff and make a decision without opening another layer.
  • Testable: the layer’s own tests run and pass on its own code.
  • Mergeable: the layer can land on the stack’s base without breaking the build or the layers above it.
  • Independently deployable: the layer can run in production without the layers above it.

Every layer should be reviewable and pass its configured required checks. The current merge candidate must also be safe to land on the stack’s base. Independently deployable is a higher bar that most upper layers do not need to clear before review.

CI cost follows the threshold assigned to each layer. If every layer receives the deployment pipeline, every layer pays the full price. The expensive gate can instead run for the current merge candidate and the merge queue, while every layer keeps the checks required for focused review.

Publish decisions, not layers

Start with a publishing rule: publish a change when a reviewer can understand its diff, test its claim, and make a useful decision without reading the layers above it. Add a conservative pilot budget of three published layers.

Three is a policy limit, not a property of GitHub. Deeper work can keep upper changes local until they earn an audience. A team using plain Git can do the same by leaving upper branches unpushed.

The cap also rejects false stacks. Two changes that can both target main are independent pull requests; ordering them adds rebase cost without representing a dependency.

Tier the CI with stack metadata

GitHub evaluates every pull request in a stack against the stack’s base branch. A workflow triggered by pull_request events to main runs for every layer. Existing required checks therefore cover the stack without configuration, but full pipelines can multiply with stack depth.

GitHub exposes stack metadata in workflow expressions under github.event.pull_request.stack: the stack’s number, its size, this pull request’s position, and the base branch. The field exists only when the pull request belongs to a stack. Two conditions do most of the work:

  • stack.base.ref == pull_request.base.ref is true for the lowest unmerged layer, the one currently able to land.
  • stack.position == stack.size is true for the top layer, the one containing the full set of changes.

Gate the expensive jobs on the first:

yaml
# Every layer runs this workflow; jobs decide what each layer pays for.
name: checks
on:
  pull_request:
    branches: [main]
  merge_group:

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v5
        with: { go-version-file: go.mod }

      # Repository-wide short checks run for every layer.
      - run: go build ./...
      - run: go test ./... -short

      # Run the expensive suite for merge queues, standalone pull requests,
      # and the lowest unmerged stack layer.
      - name: Integration tests
        if: github.event_name == 'merge_group' || github.event.pull_request.stack == null || github.event.pull_request.stack.base.ref == github.event.pull_request.base.ref
        run: go test ./... -tags=integration

The explicit merge_group branch keeps the full gate on the exact code entering a merge queue. The stack == null branch preserves integration tests for standalone pull requests. As lower layers merge, GitHub rebases the next layer onto the stack’s base, so the lowest-unmerged condition moves with it. Path filters can further avoid unrelated monorepo jobs.

  1. cascading rebase updates every layerPush to the bottom layer
    1. stack.base.ref == base.ref, full gate
    2. cheap checks onlyto Layer 2
    3. cheap checks onlyto Layer 3: top
  2. build + unit + integrationLayer 1: lowest unmerged
  3. build + unitLayer 2
  4. build + unitLayer 3: top
One push, two check tiers

Every layer of the stack runs the cheap verify jobs. The full integration gate runs only for a standalone pull request or the lowest unmerged layer, the one place a merge can happen.

A bottom-layer push in a three-layer stack now starts one full run and two short runs instead of three full runs. Expensive integration-test minutes stop scaling with stack depth, although the short checks still do.

Review the stack, not the notifications

Review a stack as one appointment. One reviewer, or one pair, reads the chain bottom to top in a single sitting. The stack map supplies order and status; per-layer diffs keep each decision narrow. Required approval still happens per layer, but reviewers load the shared context once.

Two habits support that workflow:

  • Assign the stack, not the layer. One owner for the chain avoids three reviewers waiting for one another. Where CODEOWNERS splits layers across teams, the lowest layer’s owner coordinates the next owners.
  • Review from the bottom. Reviewing an upper layer while its foundation remains disputed spends effort on code likely to be rewritten.

Measure whether this policy improves time to first review comment. Do not assume smaller diffs automatically produce lower latency.

Merge the foundation early

Long-lived stacks compound cost as main moves and lower-layer rebases replay checks above them.

Partial merges reduce that surface. Merge the bottom layer as soon as it is approved and safe to land. GitHub rebases and retargets the next pull request, removing one layer from the open stack.

  1. approved, merges firstRequest-ID type
    1. partial merge, retarget to main
  2. becomes the lowest unmerged layerMiddleware
    1. drains one layer at a time
  3. stays open while the design settlesLogging
The stack drains from the bottom

Merging the lowest layer shrinks the stack. GitHub rebases the next layer onto the base branch, where it becomes the new merge candidate and picks up the full gate.

Treat the stack as a queue that drains from the bottom, not a batch that lands all at once. A bottom layer that stays open for weeks deserves a new decision: shrink it, reassign it, or close the stack.

Verify the preview before making policy

Treat public-preview behavior as a deployment dependency. The stack design may be sound while the repository configuration, merge queue, or current extension version prevents the workflow you planned.

I exercised the three-layer request-ID example in a public evidence repository using GitHub CLI 2.97.0 and gh stack 0.1.0. The extension created three pull requests and linked them as one GitHub stack. I changed the bottom layer, ran gh stack rebase --upstack --no-trunk, then ran gh stack push. It rebased and pushed the two dependent branches. That is the behavior a policy needs: a lower correction can update every published layer.

I then squash-merged the bottom pull request and ran gh stack sync. The extension fetched main, skipped the merged branch, rebased the middleware pull request onto main, rebased logging onto middleware, pushed two branches, and reported the original pull request as merged while the higher pull requests remained open. The remaining layers became a smaller stack with a new foundation.

That confirms a partial merge and a cascading local rebase in the current preview. It does not confirm every repository’s protections, merge queue, or CI configuration. Those are evaluated by GitHub when the merge runs.

Use a release-safe preflight:

  1. Create a disposable same-repository stack with the repository’s real required checks.
  2. Confirm that each pull request receives the short checks you expect.
  3. Confirm that the lowest unmerged layer receives the expensive gate.
  4. Change the bottom layer and inspect every rewritten pull request diff.
  5. Merge the lowest layer, run gh stack sync, and inspect the new base and checks for the next layer.
  6. If the repository uses a merge queue, repeat the partial-merge path with queue settings enabled.

The final step matters because a merge queue is a separate runtime. GitHub can enqueue the selected contiguous part of a stack, and queue capacity can split a large stack across merge groups. That behavior changes the timing and the ref a workflow tests. A local rebase or a green pull-request check does not stand in for the queue’s merge-group run.

Record the result in the repository’s engineering handbook: GitHub CLI version, extension version, required checks, merge method, queue settings, and the exact commands that worked. A preview rollout will change. The record turns a surprise after an upgrade into a reproducible test.

Protect the cheap path

The CI condition should be conservative. Skipping an expensive job is safe only when another place runs that job against the code that can actually merge. The lowest unmerged layer and the merge queue satisfy that condition. The top layer does not merely because it contains the whole feature: its base may still be a branch that cannot land.

Keep a visible job name for skipped work. A reviewer should be able to distinguish “integration tests did not apply to this layer” from “the workflow failed to start.” If a required check is conditionally skipped, use a lightweight job with the same decision logic or make the required check the short, universal gate. Otherwise a branch-protection rule can accidentally block every upper layer.

Path filters need the same caution. They save time only when the omitted jobs cannot protect a changed boundary. A request-ID type may live in a small package, but its generated header can still affect request middleware and logging. Start with the universal short suite. Add path-based exclusions only after CI history shows that the expensive work is redundant and the affected ownership boundaries are clear.

Avoid an optimization that depends on authors remembering a label, a branch prefix, or a manual workflow dispatch. Stack metadata comes from the pull request relationship GitHub already evaluates. That makes the policy visible to automation and survives a rebase. Manual escape hatches are useful for diagnosis, not as the normal route to required verification.

Make review order explicit

The stack map gives GitHub an order. It does not give the team a review appointment. Put the intended order in the pull-request descriptions: name the lower-layer claim, state which higher layers depend on it, and say whether it can merge without them. Assign the whole chain before assigning individual pull requests.

That prevents a common stall. A reviewer opens the logging pull request first, finds a concern about request-ID validation, and leaves a comment high in the stack. The author now has to move the discussion down, revise the type, rebase every descendant, and ask the same reviewer to reconstruct context. Review the type first. If the type changes, pause the layers above it until the lower decision is clear.

Treat an approval on an upper layer as conditional when its base remains under review. GitHub can preserve approval state according to repository policy, but people still need to decide whether a rewritten lower layer changed the meaning of the code they approved. Automation keeps refs aligned; it does not preserve human understanding.

The policy should make that pause normal. It is cheaper than treating every rebase as a request for reviewers to rediscover the feature.

When a stack breaks

Three failure modes deserve explicit recovery policies:

The conflict cascade. Resolve from the bottom. Make the lowest layer green and mergeable, then rebase the next layer onto the resolved code. If the base changed an assumption behind the stack, revise the layer boundary instead of repeating the same conflict above it.

The stale stack. Give inactive stacks a shelf life. Merge the bottom layer, hand ownership to someone else, or close the pull requests while keeping useful local changes.

The wrong order. Use gh stack modify to reorder local branches, then synchronize the revised stack. Teams that avoid the CLI should treat a wrong order as a reason to rebuild a small stack, not preserve a false dependency.

Do not stack

Open a normal pull request when any of these is true:

  • The change is already one coherent review unit: a bug fix, a revert, a dependency bump, a focused patch.
  • The pieces can each target main directly. Independent work stacked is a false dependency with real rebase costs.
  • A layer cannot be understood without reading the layers above it. That is one review unit wearing several URLs.
  • The split is by file count or line count rather than by decision. Size is a symptom, not a boundary.
  • The contribution comes from a fork. Stacks require same-repository branches; there are no cross-fork stacks in the preview.
  • Nobody owns the whole chain. An unowned stack rots.

The last two are policy, the rest are judgment. When in doubt, one pull request is the cheaper mistake.

Update the tooling around the pull request

Two adoption details live outside the team’s review habits.

First, programmatic merges. API clients that merge stacked pull requests must use GitHub’s asynchronous stack merge endpoint. Pull request webhook and REST payloads expose a stack object for stack members and null otherwise, so integrations should handle both shapes before stacks reach critical paths.

Second, AI-generated changes. GitHub’s agent skill supplies stacking commands; it does not choose sound review boundaries. Apply the same publishing rule to machine-cut stacks: every published layer needs a review question a human can answer.

Roll it out as a pilot, with exit criteria

Adoption is a policy change as much as a tooling change. Run a pilot in one repository with five written rules:

  1. When to stack. Only changes with a real dependency order and separately reviewable layers.
  2. Depth cap. Start with three published layers; keep deeper upper work local.
  3. CI tiers. Run required short checks on every layer and expensive jobs on the merge candidate and merge queue.
  4. Review ownership. One reviewer owns the stack and reads bottom to top.
  5. Merge timing. Land the bottom layer as soon as it passes; give idle stacks a deadline.

Measure CI minutes per merged change and time from push to first review comment before and during the pilot. Set exit criteria before starting: CI cost near the single-PR baseline, faster first review, and no release blocked by a stack failure beyond the team’s recovery target.

After a month, keep the policy only if the measurements justify it. The fallback is ordinary pull requests plus the same publishing rule.

Try it on the next feature

Pick a feature that naturally separates into a foundation and one consumer. Cap the published stack at three layers and keep higher work local. Before opening pull requests, test the CI condition against a stack, a standalone pull request, and a merge queue. Assign one reviewer to the chain and merge the foundation when it is approved.

Then compare CI minutes per merged change and time to first review with the baseline. If either regresses, inspect the number of published layers and the jobs each layer runs before blaming the stack itself.

The stack is a budget, not a branch strategy

Shared cost begins when a local change becomes a pull request, check run, notification, and review decision. Publish layers that carry a decision, scope checks to what each layer must prove, and land the foundation as soon as it is safe. Keep the rest of the graph local until it earns an audience.

Sources

Explore this subject

More on Systems & tooling