Skip to content

fix(server): stop merge button racing GitHub mergeability computation - #14

Merged
enisze merged 1 commit into
mainfrom
t3code/fix-merge-button-transient-state
Aug 1, 2026
Merged

fix(server): stop merge button racing GitHub mergeability computation#14
enisze merged 1 commit into
mainfrom
t3code/fix-merge-button-transient-state

Conversation

@enisze

@enisze enisze commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Problem

The Merge PR button intermittently failed with "GitHub wouldn't merge this pull request… the repository may not allow the merge-commit method." — even on repos where every merge method is allowed and there's no branch protection.

Root cause: when a merge is fired right after a PR is opened/pushed, GitHub still reports the PR's mergeable state as UNKNOWN while it recomputes in the background. A merge attempted in that window is rejected with a transient "not mergeable" / "base branch was modified" error, which the classifier can only see as a hard merge-blocked failure.

Fix

mergePullRequest now:

  1. Waits for mergeability to settle — polls gh pr view --json mergeable,mergeStateStatus (bounded, 6× / 1s) until GitHub reports a computed state. The read itself forces GitHub to compute it. A failed/undecodable read never aborts the merge.
  2. Retries the merge up to 3× (1s backoff), but only on the merge-blocked kind — genuine conflicts, permission problems, and protection rules still fail immediately.
  3. Corrects the error message — dropped the false "merge-commit method" blame since we now always pick an allowed method.

Tests

  • All 18 GitHubCli tests pass, including two new ones: polling through an UNKNOWN state before merging, and retrying a transient merge-blocked failure then succeeding.
  • tsgo --noEmit clean.

🤖 Generated with Claude Code

A merge fired right after a PR is opened/pushed loses a race: GitHub still
reports the mergeable state as UNKNOWN and rejects the merge with a transient
"not mergeable" / "base branch was modified" error, which the classifier can
only surface as a hard merge-blocked failure.

mergePullRequest now polls `gh pr view --json mergeable,mergeStateStatus`
(bounded) until GitHub finishes computing mergeability before attempting the
merge, and retries the merge itself a few times on the transient merge-blocked
kind. Genuine conflicts, permission problems, and protection rules still fail
immediately. Also corrected the merge-blocked message, which wrongly blamed the
merge-commit method even though we now always pick an allowed method.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@enisze
enisze merged commit ea422c2 into main Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant