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

sync/rebase replay a merged branch when the PR lookup fails (GraphQL unavailable)

Open kieranbenton opened this issue 2 weeks ago • 0 comments

In an environment where api.github.com/graphql returns 403 but REST works (for example, Claude Code cloud sessions), gh stack v0.3.0 logs each FindPRForBranch failure as a warning and continues as if the branch had no pull request.

After the bottom PR of a two-branch stack is squash-merged (GitHub deletes its branch and retargets the PR above), gh stack sync and gh stack rebase replay the merged branch's commits onto the new base. Here that conflicted: sync restored the branches and pushed nothing, and rebase stopped on the conflict. --accept-base-change behaves the same. Where the replay applies cleanly, sync would push the merged commits into the PR above without warning. submit also opens no PR, yet prints "Pushed and synced".

Requests:

  1. A REST fallback for the PR lookup (GET /repos/{o}/{r}/pulls?head={owner}:{branch}&state=all is enough to detect a merge), or
  2. At least fail hard when the lookup fails, rather than treat the branch as unmerged.

Steps (stack: base <- b1 <- b2, every command with GH_DEBUG=api, every GraphQL call is FindPRForBranch):

# Command Exit API calls Result
1 gh stack init --base base b1 0 GraphQL x1: 403 Stack created
2 gh stack add b2 0 none b2 created on b1
3 gh stack push 0 GraphQL x2: 403 Both branches pushed
4 gh stack submit --auto 0 REST GET /repos/{o}/{r}/stacks: 200, GraphQL x6: 403 No PR opened, but prints "Pushed and synced 2 branches"
5 (PRs opened by hand: b1 into base, b2 into b1)
6 New commit on b1, gh stack rebase, gh stack push 0, 0 GraphQL x4 / x2: 403 Correct: b2 on b1's new tip
7 b1's PR squash-merged in the web UI GitHub deletes b1 and retargets b2's PR to base
8 git fetch --prune, gh stack sync 3 GraphQL x2: 403 Trunk fast-forwarded; replaying b1 onto base conflicts; branches restored, nothing pushed
9 gh stack rebase 3 GraphQL x2: 403 Replays both b1 commits onto base; stops on add/add conflict
10 gh stack rebase --abort 0 none Restored
11 gh stack rebase --accept-base-change 3 GraphQL x2: 403 Same conflict
12 git log --oneline origin/base..b2 3 commits; expected 1 (b2's own)

kieranbenton avatar Nov 17 '26 22:11 kieranbenton