Skip to content

fix(github): Check for a stack before merging the base on conflicts - #2598

Merged
BYK merged 1 commit into
mainfrom
feat/github-restack-after-merge
Nov 3, 2026
Merged

BYK merged 1 commit into
mainfrom
feat/github-restack-after-merge

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

This is a follow-up to #2597 that fixes a Bugbot finding. That PR merged before the fix landed.

In the post-push check in workflow.md, the CONFLICTING step said to merge the base without exceptions. The stacked-PR exception came after it as a separate step. An agent could follow the first step and add a merge commit to a stacked PR. A stack can't merge with that commit in its history. Now the step checks for a stack first, so stacked PRs restack and other PRs still merge the base.

--

View Session in Sentry

@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 3, 2026 10:51am UTC

Request Review

@BYK
BYK merged commit 1ae04ed into main Nov 3, 2026
45 checks passed
@BYK
BYK deleted the feat/github-restack-after-merge branch November 3, 2026 21:20
BYK added a commit that referenced this pull request Nov 3, 2026
When Junior opens a PR on top of another PR's branch, the PRs form a
plain base-branch chain. GitHub does not know they are a stack, so it
cannot rebase them or merge them as one group. #2597 and #2598 taught
the merge and conflict steps to use `gh stack` when a stack exists, but
Junior never created one.

`github_createPullRequest` now links the new PR into a native GitHub
stack
([docs](https://docs.github.com/en/pull-requests/reference/stacked-pull-requests)).

- Skip when the base is the repo's default branch or the head repo is a
fork. Normal PRs get no extra calls.
- Walk down the base branches through open PRs (up to 10 levels) to find
the chain.
- If the parent PR is the top of a stack, add the new PR to that stack
(`POST /stacks/{n}/add`). If the parent is in the middle of a stack,
skip. Otherwise create a stack from the bottom PR to the top (`POST
/stacks`).
- The tool result returns `stack: { number, pullRequests }` when the
link succeeds.

Stacking is optional, like requester assignment. A rejected call logs
`github.pull_request.stack_after_create.rejected`, and an exception logs
`github.pull_request.stack_after_create.failed`. PR creation never fails
because of stacking.

Known gaps:
- A replayed create call (the PR already exists) does not stack.
- Junior watches only the PRs it opens. If a person owns the bottom PR,
Junior does not get its merge event.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3Ae089395b988fbf2d85490e6b -->

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3Ae089395b988fbf2d85490e6b/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <126780+BYK@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — a0d0d534 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant