[Bug]: Stack merge via merge-async lands the trunk merge commit, then fails with "Could not create merge commit" and leaves upper PRs open
Describe the bug
Merging a native stack through the asynchronous merge API landed the code on the trunk, then failed partway through. GitHub created one merge commit on the trunk that merges the top PR's head, so every commit in the stack reached the trunk. Then it marked only the two lowest PRs as merged and finished with failed: Could not create merge commit. The other six PRs stayed open even though all their commits were already on the trunk, and there was no supported way to mark them merged afterwards.
Affected command
None. The merge was a direct REST call: PUT /repos/{owner}/{repo}/pulls/{top}/merge-async with merge_method: merge and merge_action: direct_merge. Before that, gh pr merge on the bottom PR was refused with "This pull request is part of a stack and must be merged using the asynchronous merge REST API".
gh-stack version
v0.1.0 installed, but it was not used for the merge.
GitHub CLI version
gh version 2.97.0 (2026-07-31)
Operating system
macOS 26
Shell
zsh
Steps to reproduce
Private organization repository, no merge queue on the trunk, no required reviews, merge commits allowed, "Automatically delete head branches" on.
- Have an 8-PR native stack,
trunk <- #1 <- #2 <- ... <- #8. Each PR was clean and mergeable, its required checks passed on its current head, and every branch contained the branch below it.- Before merging, each branch had been rebased and force-pushed several times, including one rebase of the whole stack onto the latest trunk. Each push used
--force-with-lease.
- Before merging, each branch had been rebased and force-pushed several times, including one rebase of the whole stack onto the latest trunk. Each push used
- Call
PUT /pulls/{#8}/merge-asyncwithshaset to #8's head,merge_method: mergeandmerge_action: direct_merge. Response:202,status: pending. - Poll
GET /pulls/{#8}/merge-async/{uuid}.
Expected behavior
Either every PR in the stack is merged and marked merged, or nothing changes, since stack merges are described as atomic.
Actual behavior
- The trunk got one merge commit, "Merge pull request #8 from …". Its parents are the previous trunk head and #8's head, so all eight PRs' commits are on the trunk, and the trunk's tree is identical to #8's head.
- #1 and #2 were marked merged, with that same merge commit.
- The async request then ended as
failed: Could not create merge commit. #3–#8 stayed open, still based on #2–#7's branches. GitHub kept test merges (refs/pull/N/merge) for each of them and reported themMERGEABLE/clean. - Retrying
merge-asyncon #8, and then on #3 alone, with the matchingshaeach time:202, then the samefailed: Could not create merge commit. Nothing changed. gh pr edit {#3} --base trunkis refused: "Cannot change the base branch because the pull request is part of a stack."- Deleting the head branches of the merged #1 and #2 did not retarget #3 to the trunk. GitHub closed #3 without merging it. Restoring the branch allowed #3 to be reopened.
- The only way left was to close #3–#8 by hand, so they show "Closed" instead of "Merged" and integrations that react to "merged" (for example, issue trackers that close on merge) don't fire.
Possibly related: #457 (open stack PRs when the trunk already has the merge commit), #485 (stale stack base after a partial merge) and #581 (dependent PR left on a merged branch and not retargeted). Here GitHub's own stack merge created the trunk commit and then failed to finish.
Terminal output
$ gh pr merge {#1} --merge --match-head-commit <sha>
GraphQL: This pull request is part of a stack and must be merged using the asynchronous merge REST API. (mergePullRequest)
$ gh api -X PUT repos/{owner}/{repo}/pulls/{#8}/merge-async -f sha=<head sha> -f merge_method=merge -f merge_action=direct_merge
HTTP/2.0 202 Accepted
{"status":"pending","details":{"message":"Merge request enqueued.","merge_method":"merge","merge_action":"direct_merge", ...}}
$ gh api repos/{owner}/{repo}/pulls/{#8}/merge-async/<uuid>
{"status":"failed","details":{"message":"Could not create merge commit", ...}}
$ gh pr edit {#3} --base <trunk>
GraphQL: Cannot change the base branch because the pull request is part of a stack. (updatePullRequest)
The merge request UUIDs and the repository are available to GitHub staff privately on request.
Preflight checks
- [x] I searched the existing issues for duplicates.
- [ ] I ran
gh extension upgrade stackand reproduced this issue on the latest stable release. (Not applicable: the merge ran server-side through the REST API, not through the extension.)
We hit the same bug on a public repository, with a 2-PR native stack. In our case neither PR was marked merged.
- Repo and stack: aleo-labs-protocol/snarkVM, stack #3880: aleo-labs-protocol/snarkVM#3866 (position 1, base
staging) and aleo-labs-protocol/snarkVM#3879 (position 2). Both were approved,MERGEABLE, and had green checks. Just before merging, each branch got a plain merge of the trunk (a fast-forward push, no force-push). - Web UI: the merge button repeatedly showed "Could not create merge commit".
- API:
PUT /repos/aleo-labs-protocol/snarkVM/pulls/3879/merge-asyncwithmerge_method=merge,merge_action=direct_mergeandshaset to #3879's headdd255664ereturnedpending(uuidf4b539e7-3a88-4b06-9988-399bf3f02a9e). It then ended asfailed: Could not create merge commit. - The trunk moved anyway:
stagingadvanced to8691ef268, "Merge pull request #3879 from …", at 2026-11-23T20:41:09Z. Its parents are the previous trunk head1aea93d83and #3879's headdd255664e, so the whole stack is on the trunk. - The PRs stayed open: unlike the report above, neither #3866 nor #3879 was marked merged. Both stayed OPEN with
mergeable_state: dirtyfor several minutes, so we closed them by hand.
The same merge-async call worked on earlier stacks in this repository, for example on 2026-11-11 and 2026-11-20.
We hit this too, on a public repository, merging only the bottom PR of a 5-PR native stack. GitHub marked no PR as merged. Afterwards, the stack's PRs stopped getting CI runs and their mergeability stayed UNKNOWN. Rebase stack in the web UI reported success but changed nothing.
Repo and stack. mysticcoders/reviewbot, stack #15: mysticcoders/reviewbot#12 (bottom, base main) <- #11 <- #13 <- #14 <- #10. All five were approved, MERGEABLE/CLEAN, and had green required checks. Each branch contained the one below it. main had no branch protection and no merge queue, and merge, squash and rebase were all allowed.
What we did, and what happened (times UTC, 2026-11-30):
gh pr merge 12 --mergewas refused: "This pull request is part of a stack and must be merged using the asynchronous merge REST API."- ~19:55:
PUT /repos/mysticcoders/reviewbot/pulls/12/merge-asyncwithmerge_method: mergereturnedpending(uuid6037753d-11ae-4eb0-bba1-12fe63bf3b15,merge_action: default,expected_head_sha1b88cdf). Polling returnedfailedwithin ~10 s, with "This merge could not be completed. Please try again."- But
maindid move: GitHub created merge commit ae8cb78 ("Merge pull request #12 from mysticcoders/ci/8/checks", committed 19:55:57Z), whose second parent is #12's head 1b88cdf.
- But
- Retrying with
merge_method: mergefailed with "Could not create merge commit". So didmerge_method: rebase(uuidea7a5e5b-c33c-4cf6-ac13-80e3dff8acbb). By thenmergeable_statewasdirtyandrebaseablefalse. - #12 stayed open.
GET /pulls/12/mergereturned 404, even thoughmain's tree was identical to #12's head tree. #11 stayed based onci/8/checks; there was no auto-rebase or retarget. - Rebase stack in the web UI appeared to succeed, but no branch moved and no push happened.
- No CI ran anymore for anything in the stack. The
pushworkflow onmainnever ran for ae8cb78, and later force-pushes to the stack branches (fromgh stack rebase+gh stack push, v0.3.0) triggered nopull_requestruns.mergeStateStatusstayedUNKNOWNon all four open PRs. Actions was enabled, the workflow was active, and githubstatus.com was all green. A normal, unstacked PR opened afterwards in the same repo got CI and merged without trouble. gh pr edit 11 --base mainwas refused: "Cannot change the base branch because the pull request is part of a stack."
How we got out. We closed #12 by hand. We rebased the remaining four branches onto main with gh stack rebase and pushed them with gh stack push; each new head's tree was identical to the CI-tested head before the rebase. Then we fast-forwarded main to the top of the stack with a plain git push, closed #11, #13, #14 and #10 by hand, and ran gh stack unstack 15.
Expected. Either the merge fails before writing to the trunk, or, once the trunk merge commit exists, GitHub records #12 as merged and continues the stack: it retargets #11 to main, rebases the rest, and keeps triggering workflows. Also, when the trunk already contains a PR's head (as in #457), GitHub could recognize the PR as merged.
Versions. gh 2.102.1, gh-stack v0.3.0 (installed after the merge attempt, used only for rebase, push, view and unstack), macOS 27.0.1, zsh. The merge itself was a direct REST call through gh api.