Skip to content

fix: delete sync branches that auto-delete misses - #61

Merged
SmailG merged 3 commits into
mainfrom
fix/sync-branch-cleanup
Oct 19, 2026
Merged

SmailG merged 3 commits into
mainfrom
fix/sync-branch-cleanup

Conversation

@SmailG

@SmailG SmailG commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Problem

The repo has "Automatically delete head branches" on, but 52 merged sync branches had piled up. GitHub skips that cleanup when an app token does the merge (community discussion #63409). The sync's auto-merge is enabled with GITHUB_TOKEN, so every one of those PRs shows mergedBy: app/github-actions. The two sync PRs merged by a person (#3, #60) were cleaned up normally.

Auto-delete also never applies to a closed PR, so the branch of each superseded sync PR that "Close stale sync PRs" closes is left behind too.

The 56 leftover branches were deleted by hand on 2026-10-19. 52 of them still pointed at their merged PR heads. The other 4 had no PR and held only stale rebased copies of the original port commit, whose one unique file, the supertool symlink, had been removed from main on purpose (0e061ce).

Fix

A new step, "Delete finished sync branches", runs before upstream is fetched on every scheduled run, including runs with no upstream change. It uses only gh api, so no upstream code runs with its token.

  • It deletes the branch of every merged or closed sync/* PR, if the branch still exists and still points at that PR's head.
  • It keeps a branch whose name an open PR uses. Sync branch names are derived from the upstream commit, so a run can reuse a name.
  • It keeps a branch that moved after its PR closed, with a warning.
  • A missing branch (404) is skipped silently; any other read error and any failed delete is a warning.
  • After a delete it removes the local refs/remotes/origin/<branch>. Otherwise a later push --force-with-lease of the same name in this run would fail its lease.
  • The step is continue-on-error with a 5-minute timeout, so a cleanup failure or hang never blocks the sync. It sets shell: bash, because the default bash -e has no pipefail and would show a failed gh pr list as a green step.

"Close stale sync PRs" is unchanged. Passing it --delete-branch was the first version of this PR. It was dropped because it would also delete a branch name that the current run is reusing.

Verification

GitHub's automatically-delete-head-branches skips merges made with an
app token, and the sync's auto-merge runs with GITHUB_TOKEN, so 52
merged sync branches had piled up. Each run now deletes merged sync
branches that still point at their merged head, and closing a
superseded sync PR deletes its branch.
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one): 1
  • sync

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: SmailG/claude-cursor-plugins/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c23e1129-dc43-4fca-9723-cc69f7191592

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…anup

Covers superseded (closed) PRs in the cleanup step instead of passing
--delete-branch to gh pr close, which would delete a branch name the
current run reuses. Skips names an open PR uses, warns on non-404 read
errors, drops the stale tracking ref after a delete, and marks the step
continue-on-error.
@SmailG
SmailG marked this pull request as ready for review October 19, 2026 19:17
@SmailG
SmailG merged commit 47dc03c into main Oct 19, 2026
1 check passed
@SmailG
SmailG deleted the fix/sync-branch-cleanup branch October 19, 2026 19:18
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