Skip to content

fix(server): turning on auto-merge merges a pull request that is already ready - #495

Merged
incognitojam merged 1 commit into
mainfrom
fix/auto-merge-ready-pr
Sep 26, 2026
Merged

incognitojam merged 1 commit into
mainfrom
fix/auto-merge-ready-pr

Conversation

@incognitojam

Copy link
Copy Markdown
Owner

If the pull request panel went stale after the last required check passed, it still offered Auto-merge, and pressing it failed with "Could not turn on auto-merge — You need write access on this repository", even for a maintainer.

The refusal came from the server's own permission check, not from GitHub. The server asks GitHub for viewerCanEnableAutoMerge, which depends on the pull request's state as well as the viewer's access, and is false once nothing is left to wait on. The server treated that as missing access.

Fix

  • A viewer who may merge can now ask for auto-merge whatever the per-pull-request flag says. gh pr merge --auto already merges a pull request that GitHub reports as CLEAN, HAS_HOOKS or UNSTABLE immediately, with the requested strategy, and arms auto-merge otherwise (isImmediatelyMergeable in gh's pkg/cmd/pr/merge/merge.go). gh reads the pull request's current state, so the stale panel does not matter, and merge queues are still respected. GitLab and Azure DevOps already grant auto-merge together with merge, so only GitHub changes.
  • After auto-merge is turned on, the server reads the pull request back, as it does after a direct merge, and publishes the merge if it happened, so linked threads settle.

The panel's buttons are unchanged: on a pull request that is ready it still offers Merge, and its success toast for auto-merge already says it merges "sooner if it already is".

Validation

  • A new test in PullRequestService.test.ts gives the fake host a viewer who may merge but not arm auto-merge, and a pull request that reads back as merged. It checks that auto-merge is sent with the requested squash strategy and that the merge is published. Run against the service without this fix, it fails with the same "You need write access" refusal as in the bug. With the fix, all 111 tests in the file pass.
  • Not exercised against a real GitHub pull request, because that means merging one.

Written by an agent (Claude Code, claude-opus-5-5).

…ady ready

GitHub reports viewerCanEnableAutoMerge as false once a pull request has nothing left to wait on. The server read that as missing access and refused with "You need write access", which a panel that went stale after the last check passed would hit. A viewer who may merge is now let through, and `gh pr merge --auto` merges such a pull request immediately. The merge is confirmed and published afterwards, as it is for a direct merge, so threads settle.
@incognitojam
incognitojam enabled auto-merge (squash) September 26, 2026 14:54
@incognitojam
incognitojam merged commit 02dbe10 into main Sep 26, 2026
17 checks passed
@incognitojam
incognitojam deleted the fix/auto-merge-ready-pr branch September 26, 2026 14:57
incognitojam pushed a commit that referenced this pull request Sep 28, 2026
Fork adaptation: fork #194's stack ladder field on the pull request detail is renamed from stack to stackLadder, because upstream now uses stack for list-entry stack membership. Auto-merge authorization from fork #495 still applies to non-stack actions.

(cherry picked from commit de37964)
Upstream-PR: 10875
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant