gh-stack icon indicating copy to clipboard operation
gh-stack copied to clipboard

Stacked-PR merge box doesn't offer repo admins the "bypass rules and merge" option that standalone PRs get

Open salpers opened this issue 4 months ago • 5 comments

Summary

On github.com, a repo admin trying to merge a blocked standalone PR (e.g. "Review required") is offered a "bypass rules and merge" control — "Merge without waiting for requirements to be met" — the admin escape hatch for branch-protection / ruleset requirements. Inside the Stacked PRs merge box that control is not surfaced: a blocked stacked PR only shows the stack flow ("Merging is blocked", "Unable to merge as a stack", disabled "Squash and merge stack"), with no per-PR admin bypass option. A repo admin therefore cannot bypass-merge a stacked PR from the web UI and has to fall back to the CLI: gh pr merge <n> --admin.

Filing here since gh stack is the interface to the Stacked PRs feature and SUPPORT.md routes bug reports to this repo. Extension version v0.0.8.

Reproduction

  1. On a repo whose main requires ≥1 approving review, create a stack: gh stack link --base main <A> <B> <C> (chain main ← A ← B ← C).
  2. With no approving review submitted, open a blocked member PR in the web UI as a repo admin.
  3. The merge box shows "Merging is blocked — At least 1 approving review is required" / "Unable to merge as a stack". There is no "bypass rules and merge" control — the affordance a normal blocked PR would show an admin is missing.

Observed on both an intact stack and a partially-merged one.

Expected

A repo admin should get the same "bypass rules and merge" escape hatch on a stacked PR that they get on a standalone PR — able to admin-override-merge the individual PR from the web UI, without dropping to gh pr merge --admin.

Why it's more than a nuisance

It becomes inescapable once the stack is partially merged: after squash-merging the lower PRs, the top PR stays open and stack-associated, but the stack can't be dissolved to free it — gh stack unstack refuses with Unstacking not allowed: Pull requests <A>, <B> cannot be removed from this stack (server-gated; merged members stay pinned). With no web bypass control and no way to unstack, the only route to merge the stranded PR is gh pr merge <C> --admin. The unstack / partial-merge limitation itself is already tracked in Discussions #230 and #310 — this issue is specifically about the missing admin bypass-merge affordance in the stacked-PR merge UI.

Minor client note: the unstack warning at cmd/unstack.go:228 hard-codes "queued for merge or have auto-merge enabled" as the reason for a dissolved=false result, which is misleading when the real cause is merged members — but that's secondary.

salpers avatar Jul 25 '26 09:07 salpers

Independent confirmation on public preview, on a public repo: uber/submitqueue.

Same symptom as the OP: the "bypass rules and merge" control is absent from the stacked-PR merge box, while the same PR unstacked offers it.

Verified the bypass is genuinely configured, so this isn't a misconfiguration on our end:

  • the trunk ruleset has a RepositoryRole bypass actor with bypass_mode: pull_request
  • the account hitting this has admin: true on the repo

Trunk main ruleset otherwise:

pull_request:           required_approving_review_count      1
                        require_code_owner_review            true
                        required_review_thread_resolution    true
                        require_last_push_approval           false
                        dismiss_stale_reviews_on_push        false
required_status_checks: strict, 1 required context
merge_queue:            ALLGREEN, SQUASH, max_entries_to_build 5,
                        min..max_entries_to_merge 1..5,
                        min_entries_to_merge_wait_minutes 5
also: deletion, non_fast_forward

So it reproduces on an ordinary review-required ruleset on the preview build — not scoped to an exotic config.

The impact matches the OP's "more than a nuisance" framing: admins lose the documented escape hatch exactly when a stack is wedged, and with gh stack unstack refusing to dissolve a partially-merged stack, there is no route out from the web UI at all.

behinddwalls avatar Jul 30 '26 20:07 behinddwalls

Same here — repo admin on an org with a ruleset bypass list — and the gap is a bit worse than just the merge box: the CLI fallback doesn't work either.

gh pr merge <n> --admin on a stacked PR is refused ("must be merged using the asynchronous merge REST API"), and merge-async itself has no admin/bypass parameter — it just returns "At least 1 approving review is required by reviewers with write access." So there is no web or CLI path for a bypass-eligible admin to land a stack whose base is protected, even though the same actor can --admin an ordinary PR to that same base without issue.

+1 on the request — and please extend it to merge-async / the REST API, not only the merge box: honour the ruleset bypass list for actors already on it. A partially-merged stack with a protected base is otherwise unlandable without pulling in a second reviewer.

davidkbuz avatar Aug 07 '26 08:08 davidkbuz

+1 on this request too. Not a huge blocker, but it's limiting when i have a major issue I need to merge and I can't (even though i'm the repo administrator).

1kevgriff avatar Aug 13 '26 13:08 1kevgriff

Hit this today on a partially-merged stack, and found a CLI sequence that does land it. Adding it since the thread so far concludes there is no path at all.

Situation: two-PR stack, main requires 1 approving review, I am a bypass-eligible repo admin. Squash-merged the bottom PR. The top PR then auto-retargeted to main and reported mergeable: MERGEABLE, mergeStateStatus: BLOCKED, but stayed stack-associated:

// GET /repos/{owner}/{repo}/pulls/{n}  →  .stack
{ "id": ..., "number": <stack>, "base": { "ref": "main", ... }, "size": 2, "position": 2 }

Everything reported here already reproduced exactly:

  • gh pr merge <n> --squash --admin → must be merged using the asynchronous merge REST API
  • PUT /pulls/<n>/merge → 403, Merging stacked PRs via this endpoint is not supported
  • PUT /pulls/<n>/merge-async → {"status":"pending"} with a uuid, then nothing. It enqueues and silently never lands. I tried bypass_rules=true, bypass=true, admin=true: all accepted as unknown params and ignored. merge_action only takes default, direct_merge, merge_queue, and direct_merge behaves the same
  • DELETE /pulls/<n>/merge-async → 404, so a queued request cannot be cancelled
  • gh stack unstack <stack> → Unstacking not allowed: Pull request <merged one> cannot be removed from this stack

What worked: running unstack and then merge on the stack number, despite both appearing to fail.

gh stack unstack <stack-number>   # ✗ "Pull request #<merged> cannot be removed from this stack"
gh stack merge   <stack-number>   # ✓ "This stack is already fully merged."
gh pr merge <n> --squash --admin  # succeeds

After those two, .stack on the open PR flipped from the object above to null, and the ordinary admin bypass worked immediately. So the blocker is not the stack but the stale .stack association left on the surviving PR; once it is cleared, existing tooling is fine.

Two things that look like bugs independent of the feature request:

  1. gh stack unstack prints only the refusal, but it is evidently part of what clears the association. Either it partially succeeded and under-reported, or gh stack merge's "already fully merged" is what reconciles it. Whichever it is, neither command's output suggests the PR is now merge-able, so there is no way to discover this except by re-checking .stack.
  2. merge-async accepting a request it can never fulfil, with no way to query or cancel it, is a poor failure mode on its own. A 4xx naming the unmet requirement would have saved most of this thread's debugging.

Not arguing against the original request. A bypass-eligible admin should get the affordance directly, in the merge box and in merge-async. But until then this is a working escape hatch rather than needing a second reviewer.

(Version note: gh stack v0.1.0, so newer than the v0.0.8 in the OP.)

magnusrodseth avatar Aug 31 '26 13:08 magnusrodseth

Follow-up with the mechanism, since my earlier comment guessed at it.

Reproduced on a throwaway repo (3-PR stack, bottom squash-merged via merge-async, then raw API calls):

  • first POST /stacks/{n}/unstack: 200, body is the remaining stack with open: false and pull_requests: [#1 (merged)]. .stack on #2 and #3 is now null.
  • second POST /stacks/{n}/unstack: 422 Pull request #1 cannot be removed from this stack.

So gh stack unstack freed the open PR on the first run. The client reported that 200 as "queued for merge or have auto-merge enabled, stack left in place", and the later 422 as "Unstacking not allowed". That is why it looked like nothing had worked until .stack was re-read. gh stack merge did nothing here; it only reads the stack.

Client fix with tests on my fork: https://github.com/magnusrodseth/gh-stack/compare/main...unstack-partially-merged. unstack now names the PRs it freed, says the merged ones stay, points at gh pr merge, and drops local tracking when nothing open is left. Same root cause as #372. Opening a pull request from a fork is rejected here (createPullRequest permission error, and none of the existing PRs come from a fork), so a maintainer would need to pull the branch in.

The server-side ask (bypass in the merge box and in merge-async) stands.

magnusrodseth avatar Aug 31 '26 14:08 magnusrodseth