Skip to content

Handle partial unstacking in sync and checkout - #576

Merged
skarim merged 1 commit into
skarim/fix-modify-partial-mergefrom
skarim/fix-keep-local-partial-merge
Oct 21, 2026
Merged

skarim merged 1 commit into
skarim/fix-modify-partial-mergefrom
skarim/fix-keep-local-partial-merge

Conversation

@skarim

@skarim skarim commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Updates the "unstack on GitHub and keep local" choices in gh stack sync and gh stack checkout to handle merged PRs remaining in the old remote stack. Both paths preserve the local branch layout and only detach the remote association when recreation is safe.

Functionality and user impact

  • Use the same unstack-and-keep-local handling in both commands. Accept merged-only remnants and report retained history rather than claiming the remote stack was deleted.
  • Keep the local association when unmerged PRs still prevent recreation or the API fails. A failed stack lookup no longer masquerades as an already-deleted stack.
  • Preserve local branches and stack order. Sync stops before pushing or recreating anything and directs users to submit; prompts now describe unstacking rather than guaranteed deletion.

Key areas to review

  • cmd/utils.go:2160-2188: unstackAndKeepLocal centralizes the outcome handling. Check the merged-only versus blocked-remnant distinction, the 404/API-error paths, and that remote ID/number clearing and the catalog save happen only after a safe outcome.
  • cmd/utils.go:2141-2158: resolveDivergenceDeleteRemote distinguishes lookup failure from a missing stack and delegates to the shared helper. It keeps sync stopped and only offers recreation guidance after the local association is safely cleared.
  • cmd/checkout.go:627-631: handleCompositionConflict uses the same helper for its keep-local choice, returning the existing local stack rather than importing or replacing its branches.

Related issues


Stack created with GitHub Stacks CLI • Give Feedback 💬

@skarim
skarim added this pull request to stack #577 October 21, 2026 18:59
Copilot AI balanced review requested due to automatic review settings October 21, 2026 18:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Static review identified no blocking issues in the shared handling, command integration, or regression coverage; tests were not executed.

No open issues 🎉

What changed in this PR

Updates sync and checkout to handle partial unstacking safely while preserving local branch layout.

Changes:

  • Shares keep-local handling across both commands, accepting merged-only remnants and retaining associations on blocked outcomes.
  • Adds regression coverage for successful, partial, and failed unstacking.
  • Updates prompts and documentation to avoid promising remote stack deletion.
File Description
README.md Explains partial unstacking and recreation.
docs/​src/​content/​docs/​reference/​cli.md Updates sync conflict-resolution guidance.
docs/​src/​content/​docs/​guides/​workflows.md Documents keep-local behavior.
cmd/​utils.go Centralizes safe unstacking and lookup-error handling.
cmd/​sync_test.go Covers sync outcomes and verifies no pushing or recreation.
cmd/​checkout.go Uses shared handling and injectable selection.
cmd/​checkout_test.go Covers checkout outcomes and local-stack preservation.

Review effort: Balanced

@skarim
skarim force-pushed the skarim/fix-keep-local-partial-merge branch from 50d4a66 to 14706fe Compare October 21, 2026 19:35
@skarim
skarim force-pushed the skarim/fix-keep-local-partial-merge branch from 14706fe to 620c787 Compare October 21, 2026 19:48
@skarim
skarim merged commit 282dffa into main Oct 21, 2026
8 checks passed
@skarim
skarim deleted the skarim/fix-keep-local-partial-merge branch October 21, 2026 20:30
@skarim skarim linked an issue Oct 27, 2026 that may be closed by this pull request
doranoda added a commit to bex-co/bex that referenced this pull request Nov 24, 2026
… pull request below it through GitHub's merge-async, as Devin's merge button does (w10/053)

A takeover session, or one given a number, asked to merge a person's
stacked pull request called PUT …/pulls/{n}/merge, which GitHub says "does
not support stacked pull requests or merging with a merge queue". Devin
Review: "merging a PR also merges every open PR below it in the stack",
and its button "shows exactly how many PRs the action will land".

- A pull request the merge-state read finds in a stack, merged without
  auto or after GitHub refuses an auto arm because the stack is ready
  now, goes to PUT …/pulls/{n}/merge-async: sha pinned, the stack base's
  method rule, the commit text, merge_action default (GitHub merges
  directly, or queues the stack where its base requires a merge queue),
  never bypass_rules.
- A 202 is polled at GET …/merge-async/{uuid} once a second for at most
  15 s (github.AsyncMergeWait), inside the :8091 listener's 30 s write
  timeout; a failed read is retried until then. A 409 already pending at
  the pinned head is waited for; at another head it is head_changed.
- merged answers merged with stack: true and records prState merged;
  enqueued answers mergeQueue and records prMergeQueued; failed is
  GitHub's words under merge_blocked, head_changed or
  merge_method_not_allowed; still pending at the bound answers
  mergePending: true and records nothing, and the driver's next says it
  has not merged yet and to call the tool again to read the result.
- The state read adds stackEntry { position } and the stack's entries;
  pullRequestCount is the pull request plus every open one below it, on
  stack merges, queues and fresh stack arms.
- A pull request in no stack, an arm, a queued pull request and
  disableAuto are unchanged.

ADR090 D3 (w10/053 amendment), ADR018, the agent-image README and the
backend AGENTS.md say so. Not walked live (no QA-owned stack fixture):
tested against the REST description's merge-async contract; the state
query ran read-only on github/gh-stack#576.
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.

gh stack submit fails after modifying a partially-merged stack

3 participants