gh-stack icon indicating copy to clipboard operation
gh-stack copied to clipboard

Can't merge a stacked PR with no clear reason (all PRs show mergeable)

Open mr04vv opened this issue 4 months ago • 44 comments

Environment

  • develop branch are protected by a repository ruleset with:
    • require_last_push_approval: true
    • dismiss_stale_reviews_on_push: true
    • required status checks
    • No merge queue.

Reproduction

  1. Create a 3-level stack: develop <- A <- B <- C.
  2. Approve every PR after its latest push. All three show MERGEABLE / CLEAN / APPROVED, all checks green.
  3. On the top PR (C), the native GitHub "Merge stack (3)" box shows "Able to merge as a stack". Click it (merge method: Create a merge commit) and confirm.

Expected

All three PRs merge into develop, or the operation stops before anything merges.

Actual

  • UI shows "Merging stack… / 3 pull requests are being merged" briefly, then rolls back to "Able to merge as a stack". Nothing merges.
  • The PR event log records repeated auto-merge was automatically disabled — "Pull Request is not mergeable".

(In the image, the bottom PR has been merged, but the behavior remains the same even if it is not merged.) Image Image Image

Notes

  • Root cause not confirmed — the above are observed events only. One hypothesis is that merging the bottom PR moves the merge-base of the PR above it, invalidating its latest-push approval, but this has not been verified.
  • Reproduces without a merge queue, which differs from #174 (scoped to merge-queue branches, describes a hang rather than a rollback). Filing separately because the trigger and symptom differ; feel free to consolidate into #174 if preferred.

mr04vv avatar Jul 27 '26 06:07 mr04vv

Same class of failure on a 3-PR stack without a merge queue (repo: private product stack, trunk master).

Setup

  • Stack: master <- #A <- #B <- #C (all open, squash intended)
  • Every PR: mergeStateStatus=CLEAN, mergeable=MERGEABLE, reviewDecision=APPROVED, required checks green
  • No merge queue on the repo
  • Clicked Merge stack from the tip (#C)

Actual

  • UI stuck on “Merging stack… / 3 pull requests are being merged” with all three rows showing Merging
  • API after several minutes:
    • #C (tip): autoMergeRequest enabled (squash), baseRefName still the middle branch (not trunk)
    • #A and #B: still OPEN, autoMergeRequest: null, bases unchanged
    • Trunk tip unchanged — nothing merged
  • So the stack job appears to arm auto-merge only on the tip. Tip cannot merge until lower PRs land and bases retarget; lower PRs were never started → deadlock (infinite “Merging…” rather than a clean rollback)

Contrast with this issue’s “rollback” path

In your report the UI returns to “Able to merge as a stack” and logs auto-merge disabled / not mergeable. We stayed in the merging state with only tip AM on. Same broken bottom-up orchestration; different UI terminal state.

Workarounds that work

  • Cancel stack merge → merge bottom-up (or enable auto-merge on #A first), accepting per-layer CI after each squash
  • Or retarget tip to trunk and merge tip only (full stack in one squash), close lower PRs as superseded

Happy to pull more GraphQL/API snapshots if useful.

shanegrouber avatar Jul 27 '26 19:07 shanegrouber

same problem,it is really a big blocker

Molly-Guan avatar Jul 29 '26 05:07 Molly-Guan

There's now a stack merge command and when running that I see the following error.

✗ merge failed: protected branch 'main' check failed:
  At least 1 approving review is required by reviewers with write access.
Stack merges are atomic, so nothing was merged.

All PRs in the stack have a relevant review.

leettaylor avatar Jul 30 '26 15:07 leettaylor

There's now a stack merge command and when running that I see the following error.

✗ merge failed: protected branch 'main' check failed:
  At least 1 approving review is required by reviewers with write access.
Stack merges are atomic, so nothing was merged.

All PRs in the stack have a relevant review.

The error I see is slightly different

Merging #55023, #55024, #55025 into master via squash...
✗ merge failed: Repository rule violations found

Waiting on 1 reapproval from someone other than the last pusher. Reviews from ***** and ***** are stale because they were submitted before the merge base changed.


Stack merges are atomic, so nothing was merged.

mobot11 avatar Jul 30 '26 18:07 mobot11

There's now a stack merge command and when running that I see the following error.

✗ merge failed: protected branch 'main' check failed:
  At least 1 approving review is required by reviewers with write access.
Stack merges are atomic, so nothing was merged.

All PRs in the stack have a relevant review.

The error I see is slightly different

Merging #55023, #55024, #55025 into master via squash...
✗ merge failed: Repository rule violations found

Waiting on 1 reapproval from someone other than the last pusher. Reviews from ***** and ***** are stale because they were submitted before the merge base changed.


Stack merges are atomic, so nothing was merged.

The error I see is slightly different

❯ gh stack merge
✗ merge failed: Repository rule violations found

Waiting on code owner review from xxx.

Stack merges are atomic, so nothing was merged.

BUT!!!,oddly,i can merge one by one from the first branch,no error occured,so i guess something must be wrong but not me

Molly-Guan avatar Jul 31 '26 05:07 Molly-Guan

Also encountering this. UI button is green, but fails without any obvious errors. CLI fails like this even though the entire stack is approved:

Merging #XXX, #XXX, #XXX, #XXX into main via rebase...
✗ merge failed: Repository rule violations found
Waiting on code owner review from org/reviewer-group.

Stack merges are atomic, so nothing was merged.

Merging the stack from the bottom changes the base of the rest of the stack, which re-triggers checks and also dismisses reviews depending on your repo's settings. So in the best case you might be able to merge without getting a new approval, but it will be a slow process depending on how many PRs are stacked.

It's kinda strange for a problem like this to even reach public preview. It looks exactly like the same class of problem other stack tools which don't use a merge bot (spr, ghstack, etc) have been hamstrung by for years. Many basic review hardening settings (like "dismiss stale reviews on push", "require last push approval", etc) completely break the core functionality, so it's a very common complaint. Surely prior art was looked at when creating this tool?

Happycoil avatar Jul 31 '26 13:07 Happycoil

Surely prior art was looked at when creating this tool?

You'd think. I'm facing the same issue, I used to use graphite and switched to gh stack and the fact the API for those were similar was cherry on top. However gh stack doesn't solve anything that graphite didn't except gh stack is free to use.

cyberhck avatar Aug 05 '26 07:08 cyberhck

Reproduced with gh stack v0.1.0 and Dismiss stale pull request approvals when new commits are pushed enabled.

All involved PRs display Changes approved in the GitHub UI.

Observed behaviour

Merging one PR at a time succeeds

Sequentially merging each PR works through both interfaces:

  • Merging one PR at a time through the GitHub web UI succeeds.
  • Merging one PR at a time through GitHub CLI succeeds:
gh stack merge PR-A
✓ Merged PR-A into the base branch

gh stack merge PR-B
✓ Merged PR-B into the base branch

gh stack merge PR-C
✓ Merged PR-C into the base branch

Merging multiple PRs at once fails

Attempting to merge multiple approved PRs as one stack operation fails through both interfaces:

  • The web UI shows Changes approved, Able to merge as a stack, and an enabled Merge stack 2 button, but the multi-PR merge does not complete.
  • The equivalent CLI operation fails:
gh stack merge TOP-PR
Merging LOWER-PR, TOP-PR into the base branch via merge...
✗ merge failed: Repository rule violations found

Waiting on required approvals from REQUIRED-REVIEWER-TEAM.

Stack merges are atomic, so nothing was merged.

The same PRs therefore satisfy the repository rules when merged sequentially but fail approval validation when included in a multi-PR stack merge.

Possible relationship to stale-review dismissal

When a lower PR merges, GitHub Stack rebases and force-pushes the branches above it, creating new commit identifiers and changing their merge bases. With stale-review dismissal enabled, those rewritten upper PRs may require reapproval.

The multi-PR merge validator may be evaluating approvals against the internally rewritten upper branches and treating them as stale. However:

  • The UI continues to show all included PRs as approved and advertises the multi-PR operation as ready.
  • Sequential merges continue to accept the approvals through both the UI and CLI.

This indicates inconsistent approval handling between:

  1. Sequential single-PR merges through the web UI
  2. Sequential single-PR gh stack merge commands
  3. Multi-PR merges through the web UI
  4. Multi-PR gh stack merge commands

Expected behaviour

Approval validation should be consistent between sequential and multi-PR stack merges.

If stale-review dismissal makes the multi-PR operation invalid, the UI must not display Able to merge as a stack or enable the multi-PR merge button. It should identify which PRs require reapproval before offering the operation.

SpyrosBou avatar Aug 06 '26 14:08 SpyrosBou

Ran into the same issue with Dismiss stale pull request approvals when new commits are pushed enabled. I understand why it breaks, but it was surprising and I'd expect GitHub to special case those ruleset options so you don't have to continuously re-request reviews.

GH really should provide a better error message here too, at least.

rsimpsonap avatar Aug 06 '26 17:08 rsimpsonap

Ran into this issue today as well

  • Private repo
  • Stack of 3 PRs
  • "Dismiss stale reviews" setting enabled on the repo

Auto merging from the final PR hangs forever, but canceling it and merging one at a time works as a clunky and slow workaround as then every step has to rerun the PR checks.

voidlily avatar Aug 11 '26 21:08 voidlily

Also had this issue.

  • Organisation Repo
  • 3 PR stack
  • Dismiss Stale Reviews enabled
  • Commit message requirements (We put our JIRA ticket code in our message)

But because of point 3 I have not been able to validate point 4. In the CLI I get the warning about approvals being required.

But I shouldn't have to get the error message via the CLI if the UI is there on the website, nor should I have to manually merge each PR to work around my requirements as it otherwise defeats the point of the stacked PRs.

dman64w avatar Aug 13 '26 10:08 dman64w

We're seeing the exact same thing you described — spinner shows "Merging stack…" then rolls back, event log says "Pull Request is not mergeable" despite every PR showing mergeable/approved. Also confirmed your hypothesis: our target branch has classic branch protection with require_last_push_approval: true and a separate ruleset on the same branch with dismiss_stale_reviews_on_push: true.

GitHub enforces the stricter of the two wherever they overlap, so in effect every push (including the synthetic ones from cascading rebases after a lower PR merges) dismisses stale approvals and requires a fresh last-push approval — which lines up with approvals silently going stale right before the stack-merge check. No merge queue involved on our end either, so that's consistent with your report.

mateo-di avatar Aug 14 '26 14:08 mateo-di

Same failure, but with a path-scoped team requirement rather than an approval count:

✗ merge failed: Repository rule violations found

Waiting on required approvals from <org>/<gatedfolder-team>.

2-PR stack. Only the upper PR touches .gatedfolder/, matching a required_reviewers rule scoped to [".gatedfolder/**"]. That approval exists - on behalf of the team, on the current head SHA:

{
	"state": "APPROVED",
	"onBehalfOf": [
		{
			"slug": "<gatedfolder-team>"
		}
	],
	"commit": "<head-sha>"
}

Both PRs CLEAN / APPROVED, checks green. Not stale, unlike @mobot11's case.

Versions: gh 2.97.0, gh-stack v0.1.0.

Should onBehalfOf team approval satisfy a path-scoped required_reviewers rule during a stack merge?

BrendanDriveCentric avatar Aug 18 '26 15:08 BrendanDriveCentric

Merging one at a time from the bottom up seems to be the workaround. I've written https://github.com/tekumara/gh-stack-merge to automate this whilst waiting for checks to settle on each PR.

tekumara avatar Aug 19 '26 23:08 tekumara

I can reproduce what looks like an inconsistency in the stack merge approval evaluation.

We have a stack of 4 PRs. For the top PR, GitHub shows:

  • Changes approved
  • 1 approving review from a reviewer with write access
  • org-ci still listed as a pending code owner review
  • all checks passed
  • Able to merge as a stack
  • all 4 PRs in the stack are shown as Ready

So at this point GitHub considers the stack mergeable even though org-ci has not reviewed.

When clicking Merge stack, however, the merge fails with:

Final merge failed: Waiting on code owner review from org/team and/or org-ci.

The ruleset itself is shown as passed (codeowners-ruleset / “Require a pull request before merging”), so the failure only happens during the final stack merge.

This seems inconsistent with both the pre-merge state and normal PR behavior: the approval from a member of team is sufficient to satisfy the code owner requirement, and a normal PR can be merged while the org-ci review is still pending.

Expected behavior:

If the PRs are shown as Ready and GitHub says Able to merge as a stack, the stack merge should not fail because of the same pending code owner review.

As an additional data point: I can merge the PRs individually, one by one, without any additional approval. The failure only occurs when using Merge stack.

itdhsc avatar Aug 21 '26 10:08 itdhsc

Adjacent data point rather than another repro — we haven't hit the atomic-merge failure itself, but we did measure the dismissal behaviour that makes the "just merge bottom-up" workaround expensive, and it's worse than it looks.

Setup: private monorepo, protected trunk, Dismiss stale pull request approvals when new commits are pushed and Require branches to be up to date before merging both on, merge commits (not squash), no merge queue.

Every layer you merge costs an approval above it

  • Merging a parent dismisses the child's approval even when the child's head SHA never changes. Confirmed on the child's review_dismissed timeline events: head was identical before and after, so the base-ref change alone was enough to dismiss. Bottom-up isn't merely "slow because checks re-run" — every layer above loses its approval the moment the layer below lands.
  • Once the parent lands, the child goes BEHIND and can't merge until it's updated, and the update commit is itself a new commit that dismisses whatever approval you just collected. update → approve → merge is the only ordering that survives; approve → update burns the approval every time.
  • Dismissed reviews can't be reinstated. Force-pushing back to the exact SHA that was approved does not restore them — only a fresh review does. Each layer costs a real human round-trip, N of them for an N-deep stack.
  • A single gh stack sync (cascade rebase + force push) dismisses every approval above trunk at once, before anything is merged at all. On a 6-deep stack, three approvals went DISMISSED in one sync with zero merges. In practice the only approval worth anything while a stack is still moving is the one whose base is trunk.

Related: mergeability can go stale in the opposite direction

Worth flagging since this issue turns on "all PRs show mergeable" — we saw the inverse mismatch. After force-pushing the branches one at a time (rather than letting gh stack sync do its atomic push), the API-reported mergeability froze at UNKNOWN (CONFLICTING on some branches) and checks were never dispatched, while the UI kept showing the stack as fine.

Caveat: there was a GitHub incident in flight at the same time, so we can't fully isolate causality. What we can say is that the per-branch push path showed it and the atomic path never did. If the stack object's mergeability can sit stale in one direction, it seems worth checking whether the merge-time rule evaluation reads the same possibly-stale state.

Why this matters day to day

This is an operational blocker, not an edge case. Stacking is how we ship anything that has to land in a specific order, so every stack we open pays this tax, and the cost lands on reviewers asked to re-approve code they already approved and that hasn't changed a byte. Landing a stack is currently the slowest part of our review cycle, entirely because of this.

The atomic path is the only one that could evaluate all the approvals in a single shot, and it's the one that fails; the fallback costs O(N) human re-approvals per stack. That's why "merge them one at a time" stops being a workaround past 2–3 PRs.

Two things that would help even without a full fix

  1. Have stack merge report which PR in the chain tripped the rule — the current message names the rule but not the layer.
  2. Evaluate the rules against the post-merge state the stack is going to create, rather than against each PR's current base.

camipozas avatar Aug 24 '26 20:08 camipozas

Positive control for the dismiss_stale_reviews_on_push hypothesis: turning it off makes the atomic multi-PR stack merge work.

Setup: 3-PR stack, squash-only, ruleset on main with dismiss_stale_reviews_on_push: true, require_code_owner_review: true, required_approving_review_count: 1, no merge queue (Team plan). Four "Squash and merge stack" attempts rolled back with auto_merge_disabled / "Pull Request is not mergeable" — the symptom in this thread.

Disabled dismiss_stale_reviews_on_push, clicked the same button, re-enabled it:

  • All 3 PRs merged at 19:16:17, :18, :19 — one second apart
  • No branches rebased, no CI re-ran, no re-approvals
  • 3 separate squash commits on main, history intact

The one-second spacing is the interesting part: the atomic path computes each squash directly rather than rebasing the branches above it, so when it works it costs none of the O(N) CI-and-re-approval tax that merging one at a time does (@camipozas quantified that well above).

Most reports here are correlational — "we have the setting on and it fails." This is the interventional version: same stack, same button, one variable flipped, and it succeeds. That suggests a narrow fix — suppress stale-dismissal evaluation inside the atomic transaction, since sequential merges already accept the same approvals.

Caveat for anyone using this as a workaround: it's a repo-wide protection hole while it's off, and auto-merge fires the moment a PR becomes mergeable, so anything armed elsewhere can land on a stale approval. Hand-operated stopgap only.

Separately: this doesn't explain the code-owner failures (@itdhsc, @BrendanDriveCentric). require_code_owner_review was on throughout for us; our stack just touched no CODEOWNERS paths. Likely a sibling bug.

raspy8766 avatar Aug 24 '26 20:08 raspy8766

Currently we have pretty strict restrictions in our company's main branch, and stacks are so useful for organizing our commit/branch structure.

Trying to merge as a whole, and/or individually, is incredibly painful right now. I would hope that this will be improved, or have some exception in the future.

Because right now....

I cannot merge the entire stack, we have

  1. Dismiss stale pull request removal on new commits
  2. Require approval from a different pusher
  3. CI checks that are required to run as a requirement before merge is allowed

Our current flow now, without turning the settings off...

  • Merging a stack 1 by 1 bottom up... which retriggers full CI for all the other stacks... and requires us to wait for every single stack
  • Have a different person approving/merging because of above (2) setting, so we need more than 1 person involved in approval/merge

I would rather not have to disable protections for this 😅

Auranapse avatar Aug 25 '26 04:08 Auranapse

Reproduced today (2026-08-26). The CLI gives the reason the web UI never shows.

Setup: a stack of 6 PRs, bottom two already squash-merged. The two lowest remaining ones — A (base = trunk) and B (base = A) — both approved, checks green. Target branch: squash-only, linear history, required_approving_review_count: 1, require_last_push_approval: false, dismiss_stale_reviews_on_push: true, require_extra_approval_for_unattributed_changes: true, no merge queue.

The click. On B's page: Changes approved, All checks have passed, Able to merge as a stack, button Squash and merge stack (2). Clicking it flipped A to the purple Merging spinner, then nothing.

No server-side trace. While the UI showed "Merging":

gh api repos/OWNER/REPO/pulls/A
  state: open, merged: false, mergeable: true, mergeable_state: clean, auto_merge: null

gh api repos/OWNER/REPO/issues/A/timeline
  zero merge events — no "merged", no "auto_merge_enabled", no "enqueued".
  Last event: the reviewer's approval.

Unlike the report above and #256, there is no "auto-merge was automatically disabled" event. Reload clears it. After a refresh, A was back to Ready and the button offered (2) again, as if nothing had been clicked.

What the CLI says. gh stack merge <B>:

X merge failed: Repository rule violations found

At least 1 approving review is required by reviewers with write access.

Stack merges are atomic, so nothing was merged.

But both PRs are approved, reviewDecision=APPROVED, mergeStateStatus=CLEAN

And require_last_push_approval: false so nothing could have staled them. The group evaluation still says an approval is missing, which looks like @skarim's bug from #256 ("approvals are not being appropriately evaluated when merging a stack of multiple PRs").

Note the two bottom PRs of this same stack merged individually, same ruleset, same reviewer, only the multi-PR group fails. And the atomic pre-flight refusal explains the missing trace: nothing is ever queued, so auto_merge stays untouched and the timeline stays empty, while the UI shows an optimistic spinner it cannot walk back.

acromarcopolo avatar Aug 26 '26 10:08 acromarcopolo

Hit this too, on a 2-level stack with no merge queue. I dug into the API/timeline data and can narrow down the trigger a bit more precisely than "merging the bottom PR moves the merge-base":

In our case the stack was created from two already-existing branches/PRs via gh stack link rather than init, and that link step retargeted the top PR's base onto the bottom PR's branch. That alone didn't invalidate anything, since it happened before the top PR got approved. But the retarget made GitHub's UI flag the top PR as "out of date with base branch," and clicking Update branch rebased it onto the new base, same content but a new commit SHA (I could see the commit's committer field had been rewritten to GitHub <[email protected]>, confirming it was a server-side rebase rather than something we pushed ourselves). That rebase is what actually invalidated the approval under our repo's require_last_push_approval rule.

We then got two fresh approvals after that rebase, with the branches not moving at all afterward. gh stack merge still refused, with the same message this issue describes: reviews are stale because they were submitted before the merge base changed, even though both approvals postdated every relevant event. And at the moment it failed, the GitHub API itself reported the PR as cleanly mergeable and fully approved, so the stack-merge check disagreed with GitHub's own merge-readiness fields.

What actually got us unblocked: we gave up on gh stack merge and just merged the two PRs individually through the normal per-PR merge path. The same base retarget happened there too, but it didn't invalidate the approvals that time. So whatever's going stale seems specific to the atomic stack-merge rule check, not the retarget/rebase itself — the regular single-PR merge handles it fine.

danbarr avatar Aug 26 '26 16:08 danbarr