Skip to content

fix(skills): housekeep branch pruning ignores squash merges; fixer never re-runs it after draining - #2311

Merged
carlos-alm merged 2 commits into
mainfrom
fix/issue-2309-housekeep-branch-cleanup
Aug 7, 2026
Merged

carlos-alm merged 2 commits into
mainfrom
fix/issue-2309-housekeep-branch-cleanup

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

Two related bugs found while running `/fixer` end-to-end this session (issues #1923-#2077, 12 squash-merged PRs):

1. housekeep's Phase 4a ("Find merged branches") used git branch --merged origin/main — ancestry-based, so a squash-merged branch's tip is never an ancestor of the new squash commit on `main`. Phase 1c already documents this exact failure mode and fixes it for worktree staleness (resolves merged-ness from GitHub PR state instead); Phase 4a never got the same fix.

Verified directly: after this run squash-merged 12 PRs, the ancestry check reported zero mergeable branches both times `/fixer` invoked `/housekeep`, while 10 of those branches sat locally unpruned.

Fixing detection alone isn't sufficient: `git branch -d`'s own internal check is the same ancestry test, so even a correctly `gh pr list`-confirmed-merged branch still gets refused by `-d` once stale remote-tracking refs are pruned (verified directly — reproduced this exact refusal on a real squash-merged branch from this run). Phase 4d and Phase 1e's worktree-branch cleanup now use `-D` for branches a GitHub PR-state check already confirmed merged — not a blanket force-delete, just deferring to a more authoritative signal than git's own unreliable-under-squash-merge heuristic.

2. fixer's Phase 3 (step 3a) runs /housekeep once per completed batch specifically because branches accumulate during the Solve and Merge Loop — but Phase 4 (Drain Parked PRs) also cuts/merges branches via its catch-up-merge procedure, and nothing called /housekeep again after the drain loop's own exit conditions (all merged, 3-stall, or 15-pass cap). Added the same housekeep call, once, after the drain loop stops.

Follow-up filed

#2310 — `gc-worktrees.sh` (a separate executable script, not a skill doc) has the identical `-d`-vs-ancestry bug at its own branch-deletion call site. Left for a separate PR since it's a script + its own test suite, not a doc change.

Verification

  • `npm run lint` clean
  • `tests/unit/docs-skills-mirror-sync.test.ts` + `tests/unit/docs-check-flags.test.ts` pass (22/22) — confirms these skill docs aren't part of the public docs mirror set, so no mirror update needed
  • Manually reproduced both halves of the bug on real branches from this run: `git branch --merged origin/main` returned empty against 10 genuinely-squash-merged branches; `git branch -d` on one of them refused with "not fully merged" once its stale remote-tracking ref was pruned

Closes #2309

…ver re-runs it after draining

Two related bugs found while running /fixer end-to-end (issues
#1923-#2077, 12 squash-merged PRs):

1. housekeep's Phase 4a ("Find merged branches") used
   `git branch --merged origin/main` — ancestry-based, so a
   squash-merged branch's tip is never an ancestor of the new squash
   commit on main. Phase 1c already documents this exact failure mode
   and fixes it for worktree staleness (resolves merged-ness from
   GitHub PR state instead); Phase 4a never got the same fix. Verified
   directly: after this run squash-merged 12 PRs, the ancestry check
   reported zero mergeable branches both times /fixer invoked
   /housekeep, while 10 of those branches sat locally unpruned.

   Fixing detection alone isn't sufficient: git branch -d's own
   internal check is the same ancestry test, so even a correctly
   gh-pr-list-confirmed-merged branch still gets refused by -d once
   stale remote-tracking refs are pruned (verified directly). Phase 4d
   and Phase 1e's worktree-branch cleanup now use -D for branches a
   GitHub PR-state check already confirmed merged — not a blanket
   force-delete, just deferring to a more authoritative signal than
   git's own unreliable-under-squash-merge heuristic.

2. fixer's Phase 3 (step 3a) runs /housekeep once per completed batch
   specifically because branches accumulate during the Solve and Merge
   Loop — but Phase 4 (Drain Parked PRs) also cuts/merges branches via
   its catch-up-merge procedure, and nothing called /housekeep again
   after the drain loop's own exit conditions (all merged, 3-stall, or
   15-pass cap). Added the same housekeep call, once, after the drain
   loop stops.

Filed #2310 as a follow-up: gc-worktrees.sh (a separate executable
script, not a skill doc) has the identical -d-vs-ancestry bug at its
own branch-deletion call site.

docs check acknowledged: skill-doc fix only, no language/feature/
architecture surface change.
@greptile-apps

greptile-apps Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates the housekeeping workflow to recognize squash-merged branches through GitHub PR state and runs housekeeping after Fixer’s parked-PR drain loop.

  • Matches branch names and current tip SHAs against merged PR heads before branch deletion.
  • Uses forced deletion only after the documented merged-state check and user confirmation.
  • Adds a final housekeeping pass after drain-loop completion.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
.claude/skills/housekeep/SKILL.md Replaces ancestry-based merged-branch detection with name-and-tip-SHA matching and fully addresses the prior Phase 4 branch-name reuse finding.
.claude/skills/fixer/SKILL.md Adds one housekeeping invocation after the parked-PR drain loop exits.

Reviews (2): Last reviewed commit: "fix(skills): bind branch-merge classific..." | Re-trigger Greptile

Comment on lines +310 to 311

```bash

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.

P1 Historical names trigger force deletion

When a branch name is reused after an earlier same-named PR merged, this name-only intersection classifies the new local branch as merged and Phase 4d deletes it with git branch -D, causing the only ref to newer unmerged commits to be lost. Bind the classification to the current branch revision or otherwise veto reused branches before authorizing force deletion.

Fix in Claude Code

… alone

Greptile review (PR #2311): matching a local branch to a merged PR by
head-ref *name* alone is insufficient — a branch name can be reused
after its earlier PR merged (a later run, or a human, creating a new
branch of the same name for unrelated work), and the new, never-merged
commits would be misclassified as "confirmed merged" and handed
straight to Phase 4d's force-delete.

Fix: pull headRefOid alongside headRefName from `gh pr list` and only
classify a local branch as confirmed-merged when its current tip SHA
exactly matches the SHA GitHub recorded as that PR's head at merge
time. Any commit added since (a reused name, a new unpushed commit)
changes the tip SHA, so the pair no longer matches and the branch is
left alone instead of guessed at.

Phase 1c's gc-worktrees.sh-backed classifier has the identical
name-only gap; noted inline and added to issue #2310 (already tracking
that script's -d-vs-D bug) rather than duplicating the fix outside
this skill doc.

docs check acknowledged: skill-doc fix only, no language/feature/
architecture surface change.
@carlos-alm

Copy link
Copy Markdown
Contributor Author

Fixed — the branch-name-reuse gap you flagged was real. Phase 4a now pulls headRefOid alongside headRefName from gh pr list and only classifies a local branch as confirmed-merged when its current tip SHA exactly matches the SHA GitHub recorded as that PR's head at merge time (previously it matched on headRefName alone). Any commit added since — a reused name, a new unpushed commit — changes the tip SHA, so the pair no longer matches and the branch is correctly left alone instead of guessed at.

Verified the new comm -12 name+SHA intersection manually against this repo's real branch/PR history — it correctly returns exactly the genuinely-merged branches.

Also noted the same gap exists in Phase 1c's gc-worktrees.sh-backed classifier (which matches by name only too) and added it to #2310 (already tracking that script's separate -d-vs--D bug) rather than fixing it here, since the actual query logic for that path lives in the external script, not this skill doc.

@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@carlos-alm
carlos-alm merged commit 7bd6615 into main Aug 7, 2026
23 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2309-housekeep-branch-cleanup branch August 7, 2026 03:39
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

housekeep/fixer branch cleanup is broken: squash-merge false negative + no post-drain sweep

1 participant