fix(server): stop merge button racing GitHub mergeability computation - #14
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
UNKNOWNwhile 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 hardmerge-blockedfailure.Fix
mergePullRequestnow: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.merge-blockedkind — genuine conflicts, permission problems, and protection rules still fail immediately.Tests
GitHubClitests pass, including two new ones: polling through anUNKNOWNstate before merging, and retrying a transientmerge-blockedfailure then succeeding.tsgo --noEmitclean.🤖 Generated with Claude Code