Skip to content

fix(source-control-github): merge stacked pull requests through the async merge API - #198

Merged
yordis merged 2 commits into
mainfrom
yordis/fix-github-merge-stacked-pull-requests
Nov 2, 2026
Merged

yordis merged 2 commits into
mainfrom
yordis/fix-github-merge-stacked-pull-requests

Conversation

@yordis

@yordis yordis commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Problem

Merging a pull request that is part of a stack failed with "This pull request is part of a stack and must be merged using the asynchronous merge REST API", because the GitHub provider only used the GraphQL mergePullRequest mutation.

Change

When GitHub refuses a merge action with that message, the provider retries through PUT /pulls/{n}/merge-async with the same head SHA, method, bypass, and commit message. It then follows the returned UUID for up to ten polls. Only a merged or enqueued result is success: a failed, still-pending, unreadable, or already-pending (409) result is reported as an error. enable-auto-merge keeps GitHub's own refusal, since the async route has no auto-merge. Like the old route, it merges every open pull request below the one clicked.

Scope and approval

Small fix of an obvious bug in one provider; no new setting or client change.

Verification

vp run check:changed passes. GitHubPullRequestApi.test.ts has two new cases, a stacked merge that goes through the async route and one that GitHub then fails in the background. Not run against a real stacked pull request.

…sync merge API

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@cursor

cursor Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes pull-request merge behavior for stacked PRs and adds polling/timeouts; mistakes could merge the wrong stack layer or misreport merge status.

Overview
When GraphQL mergePullRequest returns GitHub’s stacked-PR refusal (“asynchronous merge REST API”), runPullRequestAction for merge now retries via PUT …/pulls/{n}/merge-async, sending the same head SHA, merge method, bypass/direct merge action, and optional commit message.

The provider parses the async response, polls by UUID (up to ten times, one second apart) until the job is no longer pending, and surfaces failures, unreadable bodies, or a merge still running on GitHub. enable-auto-merge is unchanged—it does not use this path.

Tests mock the GraphQL refusal and cover a successful async merge plus immediate failure, polled failure, poll exhaustion, and bad poll payloads.

Reviewed by Cursor Bugbot for commit 2749fb0. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M labels Nov 2, 2026
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 3221511 and 2749fb0.

Files selected for processing: 2
  • packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
  • packages/source-control-github/src/server/GitHubPullRequestApi.ts
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 29c88f3 and 3221511.

Files selected for processing: 2
  • packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
  • packages/source-control-github/src/server/GitHubPullRequestApi.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The GitHub pull request API now falls back to GitHub’s asynchronous REST merge route for qualifying GraphQL merge refusals. It sends the selected merge settings and expected head SHA, handles accepted and conflicting responses, and polls responses that include a UUID. Tests cover the request and failed polling response.

Changes: Asynchronous merge fallback

Layer / File(s) Summary
Route and verify asynchronous merges
packages/source-control-github/src/server/GitHubPullRequestApi.ts, packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
The API detects GraphQL refusals that name the asynchronous merge REST route and sends the selected merge settings and expected head SHA. It treats HTTP 409 as success and polls responses with a UUID. Tests verify the REST request and that a failed poll surfaces GitHub’s failure message.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant GitHubPullRequestApi
  participant GitHubGraphQL
  participant GitHubAsyncMergeREST
  GitHubPullRequestApi->>GitHubGraphQL: Submit mergePullRequest mutation
  GitHubGraphQL-->>GitHubPullRequestApi: Return asynchronous-merge refusal
  GitHubPullRequestApi->>GitHubAsyncMergeREST: PUT merge settings and expected head SHA
  GitHubAsyncMergeREST-->>GitHubPullRequestApi: Return accepted response with UUID
  GitHubPullRequestApi->>GitHubAsyncMergeREST: Poll merge status by UUID
  GitHubAsyncMergeREST-->>GitHubPullRequestApi: Return merge status
Loading

Suggested labels: size:L

Suggested reviewers: juliusmarminge

Merge Risk: Moderate · previous review 32215

Stacked merges can report success while unfinished, failed, or pending with different settings. Correct these response-handling paths before merging.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Description check Inconclusive The description supplies a clear Problem, Change, Scope and approval, and Verification section, which covers the template's required parts. The Problem section states the stacked-PR merge failure and … Add a link to the triaged bug issue or the discussion with explicit maintainer approval, including the approval comment. If no prior issue exists, expand the Scope and approval section to explain why this is a very small, focused fix of an …
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately describes the main change: using GitHub's asynchronous merge API for stacked pull requests.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description supplies a clear Problem, Change, Scope and approval, and Verification section, which covers the template's required parts. The Problem section states the stacked-PR merge failure and its cause. The Change section explains the async REST fallback, the UUID polling, the result handling, and the auto-merge exclusion. The Scope section argues the change is a small fix of an obvious bug in one provider, with no new setting or client change. The Verification section reports that check:changed passes, names the two new test cases, and states the change was not run against a real stacked pull request. Gaps: the Scope section does not link a triaged issue or maintainer approval, and it does not explain why the fix qualifies without one beyond calling it small and obvious. The template also asks for an agent/model line only if an agent was used, so its absence is not a gap. Because the Scope section is thin on the approval rationale the template asks for, the description is mostly complete but not fully complete.

Resolution

Add a link to the triaged bug issue or the discussion with explicit maintainer approval, including the approval comment. If no prior issue exists, expand the Scope and approval section to explain why this is a very small, focused fix of an obvious bug that qualifies without prior approval. Keep the existing Problem, Change, and Verification content as written.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

…r are already pending

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis merged commit f9d37df into main Nov 2, 2026
10 checks passed
@yordis
yordis deleted the yordis/fix-github-merge-stacked-pull-requests branch November 2, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant