Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .claude/skills/fixer/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,19 @@ A reported line is not automatically a bug — `main` may have legitimately supe

After the integrity check passes, re-run local verification and push, then re-evaluate the five gate conditions from Phase: Solve and Merge Loop before merging.

**Exit condition:** Every PR listed in `parked.txt` is merged, or is reported as needing human review with a specific reason. No catch-up merge was pushed without a passing I4 integrity check. Every drain-phase merge's post-merge CI on `main` was confirmed green (I8) before the next merge in the pass. Drain stopped only once a pass merged nothing 3 times in a row, or the 15-pass safety cap was hit — never on a fixed pass count while merges were still happening.
### Housekeep after the drain loop exits

Every catch-up merge above cuts/checks-out a branch the same way Phase 2's Solve and Merge Loop does, so it leaves exactly the same kind of local-branch residue that Phase 3's step 3a runs `/housekeep` to clean up — but the drain loop has its own exit points (all merged, 3-stall, or 15-pass cap) separate from the batch loop, so nothing calls `/housekeep` again after it. Run it once, exactly like 3a, after the drain loop above has actually stopped (do not call it once per pass — it is idempotent, but there is nothing new to clean between passes that haven't yet merged anything):

```bash
mkdir -p .codegraph/fixer
DRY_RUN=$(cat .codegraph/fixer/dry-run)
echo "fixer: drain loop finished — running housekeeping before the final report"
```

Invoke the `housekeep` skill: `/housekeep --dry-run` if `DRY_RUN` is `true`, otherwise plain `/housekeep`. The same confirmation posture from 3a applies unchanged: confirm deletion only for local branches this run itself recorded as `merged` in `state.json` (drain-phase merges included — they are recorded exactly the same way as Phase 2 merges), decline every worktree-removal prompt including this run's own worktree, and decline everything else.

**Exit condition:** Every PR listed in `parked.txt` is merged, or is reported as needing human review with a specific reason. No catch-up merge was pushed without a passing I4 integrity check. Every drain-phase merge's post-merge CI on `main` was confirmed green (I8) before the next merge in the pass. Drain stopped only once a pass merged nothing 3 times in a row, or the 15-pass safety cap was hit — never on a fixed pass count while merges were still happening. `/housekeep` has run once after the drain loop stopped, mirroring 3a.

---

Expand Down
30 changes: 23 additions & 7 deletions .claude/skills/housekeep/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ git worktree prune
- If confirmed:
```bash
git worktree remove "<path>"
git branch -d "<branch>" # only if fully merged
git branch -D "<branch>"
```
`-D`, not `-d`: this worktree was already classified "stale" via Phase 1c's GitHub-PR-state check, not git ancestry, so `-d`'s own ancestry test would wrongly refuse a genuinely squash/rebase-merged branch here — see Phase 4d's identical fix for why `-d` is the wrong tool once a more authoritative source already confirmed the merge (issue #2309). Phase 1c's classifier currently matches by branch name only (not name-and-SHA the way Phase 4a now does), so this inherits the same reused-branch-name gap Phase 4a closed — tracked separately in issue #2310 since the fix belongs in `gc-worktrees.sh`, not here.

**For bloated (non-stale) worktrees:**
- List them with a per-artifact size breakdown
Expand Down Expand Up @@ -305,14 +306,29 @@ Flag any branches marked `[ahead N, behind M]` — these may need attention.

### 4a. Find merged branches

> **Do not hand-roll this with `git branch --merged origin/main`** — same reason as Phase 1c: in a repo that **squash-merges** (confirmed live in this repo, issue #2309), a landed branch's tip is never an ancestor of the default branch, so `--merged` reports almost nothing as merged even right after a run that squash-merged a dozen PRs. Resolve merged-ness from GitHub PR state instead, exactly like Phase 1c/`gc-worktrees.sh` already do:

```bash
Comment on lines +310 to 311

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

git branch --merged origin/main
# name + current tip SHA, not name alone: a branch name can be reused after its earlier
# PR merged (a later /fixer-style run, or a human, creating a new branch of the same
# name for unrelated work) — matching by name only would then classify that NEW, never-
# merged work as "confirmed merged" and hand it straight to 4d's force-delete. Requiring
# the local branch's CURRENT tip to equal the exact SHA GitHub recorded as the merged
# PR's head closes that gap: any commit added since (a rename, a reused name, a new
# unpushed commit) changes the tip SHA, so the pair no longer matches and 4d leaves the
# branch alone instead of guessing (Greptile review, PR #2311).
git branch --format='%(refname:short) %(objectname)' | grep -v '^main ' | sort > /tmp/housekeep-local-branches.txt
gh pr list --state merged --limit 1000 --json headRefName,headRefOid \
--jq '.[] | "\(.headRefName) \(.headRefOid)"' | sort > /tmp/housekeep-merged-heads.txt
comm -12 /tmp/housekeep-local-branches.txt /tmp/housekeep-merged-heads.txt
```

This lists local branches whose name **and current commit** match a PR GitHub reports as **merged** — true regardless of merge strategy (merge commit, squash, or rebase), unlike ancestry, and immune to name reuse since it's pinned to the exact commit GitHub recorded at merge time.

### 4b. Safe to delete

Branches that are:
- Fully merged into main
- Confirmed merged via 4a's name-**and**-SHA check against `gh pr list` (not the ancestry test, and not a name-only match)
- Not `main` itself
- Not the current branch
- Not a worktree branch (check `git worktree list`)
Expand All @@ -329,16 +345,16 @@ This removes local refs to branches that no longer exist on the remote.

**If `DRY_RUN`:** List branches that would be deleted.

**Otherwise:** For each merged branch, ask the user for confirmation before deleting:
**Otherwise:** For each branch 4a confirmed merged, ask the user for confirmation before deleting:
```
Delete merged branch '<branch>'? (y/n)
```
If confirmed, delete the branch:
```bash
git branch -d "<branch>" # safe delete, only if fully merged
git branch -D "<branch>"
```

> **Never use `git branch -D`** (force delete). If `-d` fails, the branch has unmerged work — skip it.
> **Use `-D` here, not `-d`.** This is not a blanket force-delete: 4a already established via authoritative GitHub PR state — not git's own ancestry heuristic — that this exact branch is merged. `-d`'s ancestry check is precisely the thing that's unreliable under squash/rebase merges (verified directly: it refuses a genuinely squash-merged branch once its stale remote-tracking ref has been pruned, e.g. by 4c), so requiring it to *also* agree before deleting is not an extra safety margin — it's reintroducing the exact bug 4a exists to fix. The safety boundary here is 4a's confirmed-merged check plus the per-branch confirmation prompt below, not `-d`'s ancestry test.
> **Always confirm before deleting** — consistent with worktree removal in Phase 1c.

**Exit condition:** every fully-merged, non-protected branch has had a confirmed delete decision (or been listed under `DRY_RUN`); stale remote-tracking refs have been pruned.
Expand Down Expand Up @@ -420,7 +436,7 @@ Status: CLEAN ✓

## Rules

- **Never force-delete** anything — use safe deletes only (`git branch -d`, `git worktree remove`)
- **Never delete a branch without first confirming its *current tip commit* matches a merged PR's recorded head SHA via `gh pr list`** — not `git branch --merged`/`-d`'s ancestry test (unreliable under squash/rebase merges, issue #2309), and not a branch-*name* match alone (a reused name with new, never-merged commits would wrongly qualify, issue #2311). `-D` is correct, not reckless, once that name-and-SHA check confirms the exact commit was merged (see Phase 1c and Phase 4)
- **Never rebase** — sync with main via merge only (per project rules)
- **Never delete tracked files** — only clean untracked/ignored dirt
- **Never delete worktrees with uncommitted changes** — warn and skip
Expand Down
Loading