Skip to content

pr-queue: never delete a merged branch with the token; stacked PRs stay open - #250

Merged
scuttletoby merged 1 commit into
mainfrom
fix/stacked-pr-retarget
Nov 16, 2026
Merged

scuttletoby merged 1 commit into
mainfrom
fix/stacked-pr-retarget

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

What

The merge queue armed auto-merge with --delete-branch when the config said delete_branch: true. When GitHub can merge a PR at once (up to date, checks green), gh pr merge --auto does not arm: it merges directly and then deletes the head branch with the token. GitHub closes every open PR whose base was that branch (events base_ref_deleted, then closed). Only GitHub's own "Automatically delete head branches" setting retargets those PRs to the merged PR's base before it deletes.

Option chosen: leave deletion to GitHub's setting (not "retarget, then delete"). The queue never deletes a branch now. This is the smallest change: no new write, no new API call, no race between a retarget and a delete, and GitHub's setting already does the right thing.

  • pr_queue.py: arm() never passes --delete-branch.
  • config.py / README.md: delete_branch is optional and no longer used (still accepted so old configs stay valid; the README says to turn on the repository setting instead).

Tests

StackedGitHub in pr_queue.test.py is a fake GitHub + gh that treats a branch delete the way GitHub does (token delete closes stacked PRs; the setting retargets them first), and merges at once a PR that is mergeable, as gh does.

  • a stacked pair: after the parent merges, the child is open and based on main;
  • a chain of 3: each merge in turn leaves the rest open;
  • an armed parent that GitHub merges later: the child stays open;
  • setting off: the branch stays, the child stays open (the queue deletes nothing);
  • arming again after the branch is gone changes nothing.

Without the change (putting --delete-branch back), 4 of these fail (the pair, the chain, setting off, and the arm-arguments test). pr_queue.test.py 242 OK, lens.test.py 59 OK, fork-contracts.test.py and fork-pr-queue-workflow.test.py pass.

The state question

  • Runs again (branch already gone): the queue only arms; nothing to delete, nothing to repeat.
  • Stops half-way: there is no half-way now. The merge and the delete are one GitHub action (the setting), which retargets before it deletes. The queue's own steps are unchanged.
  • A child opened between a check and the delete: no check-then-delete exists in the queue any more; GitHub's setting reads the open PRs when it deletes.
  • PR chains of 3: tested; each merge retargets the next PR to the merged one's base.
  • Old config: delete_branch: true or false still parses; a config without it parses too.
  • Repository without the setting: merged branches stay (no PR is ever closed). A project that wants them gone turns the setting on.

General vs project

General (this PR): the queue in fork-ci/actions/pr-queue, for every project that uses it. Project part: nothing needed now. A project keeps its delete_branch key until its pin moves past this commit and can drop it then. The project's own tools that delete branches (its arm step, its branch gardener) get the same fix in that project's repository.

🤖 Generated with Claude Code

…ay open

When GitHub can merge a PR at once, `gh pr merge --auto --delete-branch`
merges it directly and then deletes the head branch with the token. GitHub
closes every open PR whose base was that branch. The repository's own
"Automatically delete head branches" setting retargets those PRs to the
merged PR's base first. The queue now never passes --delete-branch and
leaves deletion to that setting.

`delete_branch` in the config is optional and no longer used; old configs
stay valid. Tests: a fake GitHub with stacked PRs (pair, chain of 3,
armed-then-merged, setting off, armed again).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: tests-state · reviewer: opus high (lens1673state) · read at: e3f1cce
covered: fork-ci/actions/pr-queue/pr_queue.py Queue.arm (whole); config.py Config dataclass + KEYS; README.md config table; lens.test.py Config tests (parse/refused + new test); pr_queue.test.py Arm + StackedGitHub + StackedPrsAreRetargetedNeverClosed; git grep of the repo for delete_branch / --delete-branch (only head_check.test.py fixture besides the queue; no other token branch delete on the queue path).
checks: pr_queue.test.py 242 OK, lens.test.py 59 OK at the head. Red without the fix, in a scratch copy: the conditional '--delete-branch' put back in arm() -> 4 FAIL (arm arguments, stacked pair, chain of 3, setting off), as the body says; 'delete_branch' made required again in config.py -> test_delete_branch_is_optional_and_never_turns_deletion_on ERRORs. State question: runs again (branch already gone) - arm only arms, nothing to repeat. Stops half-way - the queue has no delete step any more; its STATE/recover path is unchanged. Old config - delete_branch true/false parse and are ignored (tested), a non-bool is still refused (existing test). Empty config (key absent) - parses, False (tested). Chain of 3 - tested. Setting off - tested: branch stays, child stays open; merged branches then pile up in that repo, documented in the README (turn the setting on). Projects still pinned to an older queue tag keep the old behaviour until their pin moves (their config can set delete_branch false meanwhile; the old schema accepts it).
finding: minor fork-ci/actions/pr-queue/pr_queue.test.py test_a_second_arm_after_the_branch_is_gone_changes_nothing: passes with --delete-branch put back (the fake no-ops a delete of a branch that is already gone), so it guards nothing; fine as documentation of the rerun case, not a red-to-green test. Same for test_an_armed_parent_merged_later_by_github_leaves_the_child_open (by design: an armed PR never gets gh's delete). (high)

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: correctness · reviewer: opus high (lens1673corr) · read at: e3f1cce
covered: fork-ci/actions/pr-queue/pr_queue.py (Queue.arm and every other gh write in it), fork-ci/actions/pr-queue/config.py (Config, KEYS, parse of optional keys), fork-ci/actions/pr-queue/README.md (Config table), fork-ci/actions/pr-queue/lens.test.py (new Config test), fork-ci/actions/pr-queue/pr_queue.test.py (Arm, StackedGitHub, StackedPrsAreRetargetedNeverClosed), .github/workflows/fork-pr-queue.yml (workflow_call only); a repo-wide grep of fork-ci/ and .github/ for --delete-branch, delete_branch, push --delete, :refs/heads, git/refs/heads and DELETE
checks: (1) Token deletes left in the fork. The queue now has none. Its only merge call is arm, and --disable-auto deletes nothing. The other deletes in .github/scripts are the candidate branch in fork-follow-push.sh (no work PR is based on it) and releases and runners. None is on the merge path.
(2) Config. delete_branch is optional. If it is absent, the default is False. true and false still parse, and a non-bool is still refused. Neither value adds a flag (test_the_merge_method_comes_from_the_config_and_the_queue_never_deletes_a_branch checks both).
(3) Revert check in a scratch worktree. pr_queue.py at HEAD1: 4 tests fail (the arm-arguments test, the pair, the chain of 3, setting off). config.py at HEAD1: lens.test.py has 1 error. With the fix: pr_queue.test.py, lens.test.py, fork-contracts.test.py and fork-pr-queue-workflow.test.py all pass.
(4) Callers. A caller pinned to an older ci/ tag with delete_branch: true still deletes with the token until it moves its pin. A caller can stop that today without a pin bump by setting delete_branch: false, since the old config accepts any bool. Each caller fixes this in its own repository.
State question: What happens when this runs again, stops half-way, or meets existing/old/empty state (rerun, half-applied, legacy data, empty history)?

  • Rerun: arming again after the branch is gone changes nothing (tested).
  • Half-way: the queue has no delete step now.
  • Old config: true, false and absent all parse.
  • Empty or no stacked PRs: unchanged.
  • Chain of 3: tested.
  • Setting off: branches stay and no PR is closed.
    finding: minor fork-ci/actions/pr-queue/README.md:32 The queue now relies on the repository setting "Automatically delete head branches", but it never checks or reports it. With the setting off, merged branches pile up without a warning. A one-line note at the queue's start (read delete_branch_on_merge from gh api repos/{repo}) would make that visible. Not required for this fix. (medium)

@scuttletoby
scuttletoby marked this pull request as ready for review November 16, 2026 23:49
@scuttletoby
scuttletoby merged commit 1eef95e into main Nov 16, 2026
35 checks passed
scuttletoby added a commit that referenced this pull request Nov 18, 2026
…ay open (#250)

When GitHub can merge a PR at once, `gh pr merge --auto --delete-branch`
merges it directly and then deletes the head branch with the token. GitHub
closes every open PR whose base was that branch. The repository's own
"Automatically delete head branches" setting retargets those PRs to the
merged PR's base first. The queue now never passes --delete-branch and
leaves deletion to that setting.

`delete_branch` in the config is optional and no longer used; old configs
stay valid. Tests: a fake GitHub with stacked PRs (pair, chain of 3,
armed-then-merged, setting off, armed again).

Co-authored-by: Claude Opus 5.5 <[email protected]>
scuttletoby added a commit that referenced this pull request Nov 18, 2026
…ay open (#250)

When GitHub can merge a PR at once, `gh pr merge --auto --delete-branch`
merges it directly and then deletes the head branch with the token. GitHub
closes every open PR whose base was that branch. The repository's own
"Automatically delete head branches" setting retargets those PRs to the
merged PR's base first. The queue now never passes --delete-branch and
leaves deletion to that setting.

`delete_branch` in the config is optional and no longer used; old configs
stay valid. Tests: a fake GitHub with stacked PRs (pair, chain of 3,
armed-then-merged, setting off, armed again).

Co-authored-by: Claude Opus 5.5 <[email protected]>
scuttletoby added a commit that referenced this pull request Nov 21, 2026
…ay open (#250)

When GitHub can merge a PR at once, `gh pr merge --auto --delete-branch`
merges it directly and then deletes the head branch with the token. GitHub
closes every open PR whose base was that branch. The repository's own
"Automatically delete head branches" setting retargets those PRs to the
merged PR's base first. The queue now never passes --delete-branch and
leaves deletion to that setting.

`delete_branch` in the config is optional and no longer used; old configs
stay valid. Tests: a fake GitHub with stacked PRs (pair, chain of 3,
armed-then-merged, setting off, armed again).

Co-authored-by: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

(Reposted 2026-11-22 with private details removed; original 2026-11-16.)

Both lenses: safe (correctness, tests-state). Minors left: #253. The game-project side sets its config key to false now, so the old pinned queue no longer deletes branches either.

scuttletoby added a commit that referenced this pull request Nov 28, 2026
…ay open (#250)

When GitHub can merge a PR at once, `gh pr merge --auto --delete-branch`
merges it directly and then deletes the head branch with the token. GitHub
closes every open PR whose base was that branch. The repository's own
"Automatically delete head branches" setting retargets those PRs to the
merged PR's base first. The queue now never passes --delete-branch and
leaves deletion to that setting.

`delete_branch` in the config is optional and no longer used; old configs
stay valid. Tests: a fake GitHub with stacked PRs (pair, chain of 3,
armed-then-merged, setting off, armed again).

Co-authored-by: Claude Opus 5.5 <[email protected]>
scuttletoby added a commit that referenced this pull request Nov 28, 2026
…ay open (#250)

When GitHub can merge a PR at once, `gh pr merge --auto --delete-branch`
merges it directly and then deletes the head branch with the token. GitHub
closes every open PR whose base was that branch. The repository's own
"Automatically delete head branches" setting retargets those PRs to the
merged PR's base first. The queue now never passes --delete-branch and
leaves deletion to that setting.

`delete_branch` in the config is optional and no longer used; old configs
stay valid. Tests: a fake GitHub with stacked PRs (pair, chain of 3,
armed-then-merged, setting off, armed again).

Co-authored-by: Claude Opus 5.5 <[email protected]>
@scuttletoby
scuttletoby deleted the fix/stacked-pr-retarget branch November 29, 2026 20:11
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.

1 participant