Skip to content

Worktree GC: per-project retention, batch cleanup, visible disk usage (#316) - #330

Merged
currentbits merged 9 commits into
mainfrom
coder/worktree-garbage-collection-with-ui-rete-c4df92
Aug 17, 2026
Merged

currentbits merged 9 commits into
mainfrom
coder/worktree-garbage-collection-with-ui-rete-c4df92

Conversation

@currentbits

@currentbits currentbits commented Aug 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #316.

Solenta had scripts/prune-worktrees.sh but no in-app garbage collection, so worktrees accumulated invisibly. Measured on a real state dir while building this: 108 worktrees, 58 GB.

What changed

Scan and batch cleanup (electron/worktrees.js)

  • gcScan — sizes every worktree directory (du -sk, no JS tree walking), classifies each as an orphan (no thread references it) or a retention candidate (a settled thread past its project's limit), rolls usage up per project, and returns a blocked reason instead of silently skipping anything unsafe (uncommitted changes, unreadable directory). Read-only, never rejects.
  • gcClean — batch removal. Re-runs the scan internally and only removes paths the fresh scan still reports as unblocked candidates, so a stale UI selection can never delete live work. One store save and one broadcast for the whole batch.
  • Branches are never deleted. GC reclaims directories only, so every commit stays reachable via its branch ref. This is the deliberate answer to Conductor's failure mode, where archiving silently failed to delete branches and left users unsure what had been lost.

Per-project retention

  • ProjectInfo.worktreeRetention — how many settled threads keep their worktree. Absent or 0 means unlimited, so existing behaviour is unchanged until a project opts in.
  • enforceRetention runs on the boot sweep after the existing orphan pass. Orphans are deliberately left to the dialog: those warrant a human look, whereas a project's own retention limit is a standing instruction.
  • Archived threads count as settled for GC. The renderer filters archived threads before the settled split, so they never carry a settled override — and on the reporting machine that was 108 of 127 worktree-holding threads, i.e. precisely the invisible worktrees this issue is about. Without this, retention found nothing to reclaim.

Collision-safe branch names

  • uniqueCoderBranch checks local and all remote refs before using a coder/<slug>-<shortId> name and suffixes -2, -3 on collision. Colliding with a fetched PR branch is what made Conductor surface unrelated merged PRs. A rename that finds no free name leaves the existing branch untouched, keeping that path best-effort and non-throwing.

UI (src/components/WorktreeGcSection.tsx, EditProjectModal)

  • Settings shows worktree disk usage per project plus a total — the visibility half of the issue.
  • One cleanup dialog, one confirm: unblocked candidates pre-selected, blocked rows disabled with their reason shown, a single button reading Delete N worktrees (X MB) that makes one gcClean call, then re-scans and reports what was reclaimed. Explicitly not a per-item nag.
  • Retention input per project; empty or 0 keeps the unlimited default.

Verification

Beyond the suites, the scan was run read-only against the live coder-store.json: at a simulated retention of 10, 26 GB reclaimable; at 3, 44 GB. That exercise is what surfaced the two integration gaps above (nothing enforced retention on boot; archived threads were invisible to it) — both green under unit tests and both wrong against real data.

  • electron/test/worktree-gc.test.js — 13 cases: orphan detection, dirty candidates blocked and refused by gcClean, retention keeping the newest N, archived counted as settled, boot enforcement leaving orphans alone, branch refs surviving removal, -2 collision suffix
  • test/worktreeGc.test.tsx — usage rendering, blocked rows unselectable, single gcClean call with the selected paths, retention round-trip
  • Full suite: electron 917/918, renderer 796/796, core and memory green, tsc --noEmit clean. The single electron failure is the pre-existing web-integration reconnect case, which fails on main independently of this branch.

Note for review

Reclaiming is opt-in per project, so by default disk usage becomes visible but nothing is deleted. Shipping a sane default limit for new projects would be a one-line change if that is preferred.

  • PR created by the Claude Code agent

Willem and others added 9 commits August 17, 2026 18:19
Replace the gcScan/gcClean placeholders with a read-only scan and a
re-scan-then-remove cleaner. GC never deletes a branch. Per-project
worktreeRetention is optional on the project row. New coder/ branches
get -2, -3, … when a local or remote ref is already taken.
Settings now scans worktree disk usage on open and offers one
confirm to reclaim selected directories. Edit project exposes the
per-project settled-thread retention limit. Branches are never
deleted from this UI.
…into coder/worktree-garbage-collection-with-ui-rete-c4df92
Provenance: entries.source column, agent/source persisted and returned on
every read path, agent is now an actual search filter.
Trust: per-agent evidence rollup derived from helpful/harmful/invalidated,
cached agent_trust() folded into ranking, suspect writers flagged in the
maintenance report.

Co-Authored-By: Claude Opus 5 <[email protected]>
…into coder/worktree-garbage-collection-with-ui-rete-c4df92
The scan surfaced retention candidates but nothing acted on them, so a
per-project limit only applied when the user opened the cleanup dialog.
enforceRetention runs gcClean over the retention candidates after the
orphan sweep: opt-in (no limit = no-op), directories only, branches kept.
Orphans stay the dialog's job — those need a human look.

Co-Authored-By: Claude Opus 5 <[email protected]>
An archived thread is further out of attention than a settled one, but
the renderer filters archived threads before the settle split, so they
never carry a settled override and retention could not see them. On the
reporting machine that was 108 of 127 worktree-holding threads — the
invisible worktrees the issue is about.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit f9e1424 into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/worktree-garbage-collection-with-ui-rete-c4df92 branch October 3, 2026 16:07
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.

Worktree garbage collection with UI: retention limits, batch cleanup, visible disk usage

1 participant