Skip to content

gh pr merge without --admin silently bypasses rulesets when mergeStateStatus is UNKNOWN #14930

Open

Description

@benbuckman

Describe the bug

gh pr merge <n> (no --admin) sends the merge when the pull request's mergeStateStatus is UNKNOWN. For a user who is a ruleset bypass actor, such as a repository admin with bypass_mode: always, GitHub then applies the bypass, so an unapproved pull request merges with no explicit opt-in. --admin exists so that a bypass happens only when it is asked for. On UNKNOWN, it happens without being asked for.

The cause is in the preflight. blockedReason in pkg/cmd/pr/merge/merge.go (v2.103.3) returns a reason only for BLOCKED, BEHIND and DIRTY, so canMerge passes for UNKNOWN. UNKNOWN is common: GitHub computes the state lazily, and the REST docs say a null mergeable means "GitHub has started a background job to compute the mergeability." In our repository, a single-PR read returned UNKNOWN for 8 of 8 open, unapproved pull requests that nobody had read recently. Three of them were still UNKNOWN after three minutes of re-reading.

In #13388 a maintainer wrote that refusing on BLOCKED by default is correct, because "bypassing ruleset protections requires an explicit action", and that the CLI shouldn't "silently bypass". Treating UNKNOWN as mergeable is a silent bypass for the same users.

Steps to reproduce the behavior

  1. On a repository with a ruleset that requires 1 approving review, add bypass_actors: [{actor_type: RepositoryRole, actor_id: 5, bypass_mode: always}] (the admin role).
  2. As a repository admin, open a pull request with required checks passing and no reviews.
  3. Don't read the pull request for about 15 minutes, so its merge state is not computed.
  4. Run gh pr merge <n> --squash, with no --admin.

Expected vs actual behavior

  • Expected: gh refuses, as it does for BLOCKED: "Pull request #n is not mergeable…", with the --admin and --auto hints.
  • Actual: gh exits 0 and the pull request merges with reviewDecision: REVIEW_REQUIRED. Read right after the merge, mergeStateStatus is still UNKNOWN.

Suggested fix

When the preflight reads UNKNOWN, re-fetch for a bounded time. If the state is still UNKNOWN after that, refuse unless --admin (or --auto) is passed. That makes a bypass require the same explicit flag in every state.

Version

gh version 2.103.3 (2026-10-26), Linux.

Activity

  1. added
    needs-triage
    on Nov 3, 2026
  2. cli-triage commented on Nov 9, 2026

    @cli-triage

    Reproducible on 2.103.3.

    Using test data with a pull request whose mergeStateStatus was UNKNOWN:

    $ gh pr merge 123 --squash -R example.invalid/hello

    Output: none. The command exited successfully and submitted the PullRequestMerge mutation without --admin.

    Exit status: 0 (success). Expected: a refusal until the state resolves or an explicit bypass mode is selected.

    The latest release build, also 2.103.3, and source snapshot behaved the same. The test covers the CLI decision and request; it does not emulate GitHub's live ruleset enforcement.

    Supporting reports

    Generated by issue triage.

  3. deleted a comment from cli-triage on Nov 9, 2026
  4. added
    bug
    gh-pr
    priority-2
    on Nov 9, 2026
  5. removed
    needs-triage
    on Nov 9, 2026
  6. souvik-biswas-dev commented on Nov 10, 2026

    @souvik-biswas-dev

    Hi, I'd like to work on this. My understanding is that blockedReason should handle UNKNOWN by re-fetching for a short bounded period and, if it's still UNKNOWN, refusing unless --admin or --auto is passed. Is that the direction you'd prefer, and is there a preferred retry duration? Happy to add unit tests for the merge command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggh-prpriority-2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions