Skip to content

Worktree GC shipped opt-in and is inert: 96 GB across 166 stale worktrees, retention unset on every project #559

Closed

Description

@currentbits

#316 shipped the whole GC engine — scan, batch clean, retention, disk rollup — and then made retention opt-in. Nobody opted in, so two days later the maintainer's own machine looks like this.

Read-only scan of this machine (2026-08-19)

~/Library/Application Support/Solenta/worktrees   96.0 GB   166 directories
median worktree                                   709 MB
thread status of those 166                        done 162, working 4
archived                                          161
pinned                                            0

per project
  solenta        119 dirs   57.3 GB
  huskyscout      25 dirs   16.0 GB
  AppVideo         9 dirs   12.3 GB
  Shipnest-v2     12 dirs    9.6 GB
  digitalnomads    1 dir      0.6 GB

worktreeRetention setting
  solenta        undefined
  huskyscout     undefined
  AppVideo       undefined
  Shipnest-v2    undefined
  digitalnomads  undefined

enforceRetention runs on every boot sweep and does nothing, by design:

// electron/worktrees.js:3789
const n = Math.floor(Number(project && project.worktreeRetention));
if (!(n > 0)) continue;

161 of 166 directories belong to archived threads. Four are live. The app has never reclaimed a byte on the machine it was written on.

A default retention of 10 per project reclaims 64.0 GB of the 96.0 GB, computed against the real store (newest 10 settled per project kept, working/pinned excluded — the same rule gcScan already applies).

Why the default is the whole fix

The engine is already conservative in exactly the ways that make a default safe (gcScan, worktrees.js:3829-3860):

  • working / quota-wait and pinned threads are never candidates
  • blocked on uncommitted changes or an unreadable tree, and enforceRetention filters !c.blocked
  • branches are never deleted (removeGcWorktree, worktrees.js:3870-3879) — GC reclaims directories, every commit stays reachable

So the worst case of a default is "a settled thread's directory is gone and git worktree add recreates it from the branch." That is recoverable. The status quo — 96 GB, growing ~700 MB per finished thread — is not what anyone chose; it is what happens when the knob starts at undefined.

Proposed

  1. Default worktreeRetention to 10 for new and existing projects. One constant plus one store migration in migrateProject (electron/store.js:827). Keep 0 as the explicit "keep everything" escape hatch that updateProject already accepts (services.js:313-321).
  2. Surface the number where it is seen without opening a dialog. gcScan already returns usage and totalBytes per project. A single line in the project header or settings — worktrees 57.3 GB · 119 with a button into the existing GC dialog — is enough. No modal, no nag.
  3. Reclaim on the transition, not only on the boot sweep. The natural moment is thread archive / branch merge, which is when the user has already decided the work is done.

Not proposed: deleting branches, touching dirty trees, or auto-removing anything a human has not been able to see first.

This is the category's open wound, and the engine is already built

  • block/buzz #5781: one repo's worktree directory hit 164 GB, enough to make the desktop and relay fail; manual git worktree remove is the only mitigation.
  • anthropics/claude-code #55435: worktree and branch survive session end, success or failure; one manual sweep of 46 stale agent worktrees recovered 10.93 GB.
  • The GitHub Copilot desktop app (Build 2026) markets "automates the entire worktree lifecycle — creating, separating, and removing" as a headline.

Solenta is the only one of these with the scan, the classifier, the batch clean and the disk rollup already written and tested. It is one default away from being the only one where the problem does not occur.

Tests

Related

#316 (the engine this turns on), #213 (worker threads archived but never deleted), #396 (environment contract — provisioning cost is what makes each directory 709 MB), #390 (shared build cache across worktrees — the other half of the same bill), #185 (worktree location/prefix settings).

Activity

  1. added
    plan:todo
    plan:doing
    and removed
    plan:todo
    on Aug 19, 2026
  2. currentbits commented on Aug 20, 2026

    @currentbits
    OwnerAuthor

    Implemented on coder/fork-worktree-gc-shipped-opt-in-and-is-i-a279bf (this worktree).

    Child plan issues: #603 #604 #605.

  3. added
    plan:done
    and removed
    plan:doing
    on Aug 20, 2026
  4. currentbits commented on Aug 20, 2026

    @currentbits
    OwnerAuthor

    Landed on main as 7ef4c56.

    • DEFAULT_WORKTREE_RETENTION = 10 moved to electron/store.js and persisted by migrateProject on every project (junk/missing → 10). An explicit 0 is now the keep-everything hatch and survives migration.
    • enforceRetention no longer skips projects riding the default, so boot GC actually reclaims. Guards unchanged: settled only, never working/pinned, never dirty, never unmerged, directories only — branches always survive.
    • Retention now also runs after archive, after git:mergeWorktree/git:removeWorktree and after orchestrator thread_merge/thread_archive, via scheduleRetention (swallows errors so GC can never fail the user action).
    • Sidebar shows a worktree-count chip that opens Settings → Worktrees.

    Verified: electron worktree-gc-retention / worktree-gc / store / projects-update = 80 pass 0 fail; renderer format / worktreeGc / editProject / sidebar = 94 pass 0 fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions