diff --git a/.claude/skills/fixer/SKILL.md b/.claude/skills/fixer/SKILL.md index 5476a81a6..5f6bb23bf 100644 --- a/.claude/skills/fixer/SKILL.md +++ b/.claude/skills/fixer/SKILL.md @@ -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. --- diff --git a/.claude/skills/housekeep/SKILL.md b/.claude/skills/housekeep/SKILL.md index 0794bc2a8..54fa44bac 100644 --- a/.claude/skills/housekeep/SKILL.md +++ b/.claude/skills/housekeep/SKILL.md @@ -165,8 +165,9 @@ git worktree prune - If confirmed: ```bash git worktree remove "" - git branch -d "" # only if fully merged + git branch -D "" ``` + `-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 @@ -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 -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`) @@ -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 ''? (y/n) ``` If confirmed, delete the branch: ```bash -git branch -d "" # safe delete, only if fully merged +git branch -D "" ``` -> **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. @@ -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