Skip to content

fix(cleanup): reclaim squash-merged lanes by default; add gx agents start --cleanup-only - #816

Merged
NagyVikt merged 4 commits into
mainfrom
agent/claude/cleanup-pr-merged-default-2026-10-02
Oct 2, 2026
Merged

NagyVikt merged 4 commits into
mainfrom
agent/claude/cleanup-pr-merged-default-2026-10-02

Conversation

@NagyVikt

@NagyVikt NagyVikt commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Why

gx cleanup judged "merged" by git ancestry unless --include-pr-merged was passed. In squash/rebase-merge repos the branch tip never lands on the base, so every merged lane looked unmerged and its worktree was kept forever. On a KFB station repo 21 merged worktrees (~2.5 GB each) filled the disk to 100%. The cleanup bot (gx agents start) never passed the flag either, and could only be started together with the token-spending review bot.

What

  • cleanup: --include-pr-merged is now the default; --no-include-pr-merged restores ancestry-only. A missing/failing gh still disables the lookup — fail-closed, nothing is treated as merged.
  • agents start --cleanup-only: start just the cleanup bot. It inherits the new default.
  • Help text for both.

Tests

  • parse defaults + opt-out; --cleanup-only parse
  • gx cleanup → prune queries gh pr list --state merged by default (fake GUARDEX_GH_BIN) and not under --no-include-pr-merged
  • agents start --cleanup-only lifecycle: cleanup bot alive, no review pid/log, second start is a no-op, stop works
  • Full suite: branch 1452/1458 pass, 1 fail — identical on origin/main (gx pr-review writes markdown artifact when GitHub auth is unavailable); comm of failing sets: no new failures. biome lint clean.

Not in scope

Merged-PR lookup still filters on the single resolved --base; multi-base repos (station branches) miss PRs merged into other bases.

🤖 Generated with Claude Code

NagyVikt and others added 4 commits October 2, 2026 12:32
…start --cleanup-only`

`gx cleanup` judged "merged" by git ancestry unless --include-pr-merged was
passed. In squash/rebase-merge repos the branch tip never lands on the base,
so every merged lane looked unmerged and its worktree was kept forever — on
one KFB station repo 21 merged worktrees (~2.5 GB each) filled the disk.

- cleanup: --include-pr-merged is now the default; --no-include-pr-merged
  restores ancestry-only. A missing or failing `gh` still disables the
  lookup (fail-closed: nothing is treated as merged).
- agents start --cleanup-only: run just the cleanup bot, without the
  token-spending review bot. The bot inherits the new default.

Tests: parse defaults + opt-out, the cleanup->prune path queries merged PRs
(fake GUARDEX_GH_BIN) and skips it on opt-out, --cleanup-only bot lifecycle.
Full suite: 1452/1458 pass, the one failure is identical on origin/main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up (#816): with --include-pr-merged on by default, a name-only
match would let cleanup delete a reused branch name, or a lane with commits
pushed after its PR merged. The merged-PR lookup now records each PR's
headRefOid; a lane counts as merged only when its tip equals that SHA or is
contained in it. Unknown/unrelated SHAs fail closed.

Also: `agents start --cleanup-only` no longer claims the review bot was not
started when one is already running — it says it was left as is.

Tests: tip == PR head → reclaimed; commits after merge → kept; unrelated
SHA for a reused name → kept. The existing squash-merge cleanup test's fake
gh now reports name + head SHA like the real one. Full suite: 1453/1459,
the one failure identical on origin/main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up (#816): only the local tip was checked, with origin as a
fallback. A stale local branch at the merged PR head while origin carries
newer work read as merged, and cleanup (keepRemote defaults to false) would
delete the remote work. Every visible tip — local and origin — must now equal
or be contained in a merged PR head.

Test: local at PR head + origin past it → kept. Full suite 1453/1459, the
one failure identical on origin/main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… review bot

Review follow-up (#816, LOW): the Logs line now matches the state file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NagyVikt
NagyVikt merged commit b109b51 into main Oct 2, 2026
3 checks passed
@NagyVikt
NagyVikt deleted the agent/claude/cleanup-pr-merged-default-2026-10-02 branch October 2, 2026 10:48
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