fix(session): lazy worktree creation — primary only#413
Conversation
POST /api/sessions was creating worktrees across ALL configured repos (11 repos) on every session start. Most sessions never write to secondary repos, causing massive branch/worktree proliferation: ~2,344 session branches across 6 repos, 4GB of worktree disk. Now creates only the primary worktree. Secondary repos are created on-demand by the existing worktree guard when an agent first writes to them (the guard and on-demand creation already work correctly). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Centaur ReviewFound 4 issue(s) (2 warning).
|
When a worktree is cleaned up (stale GC or manual removal) but the session is still alive, findAllowedWorktree() was returning the stale entry. The agent would then try to write to a nonexistent directory and get "path does not exist" errors. Now checks existsSync before returning a worktree match. If the directory is gone, evicts the entry from the session map so on-demand creation can recreate it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Centaur ReviewFound 4 issue(s) (1 warning).
|
Summary
POST /api/sessionswas creating worktrees across ALL configured repos (11) on every session startWhat changed
One function call in
handleSessionCreate: replacedcreateAllWorktrees()(loops all repos) withcreateWorktree()(primary only). The on-demand creation inworktree-guard.tsalready handles secondaries on first write — this path is proven, it's whatstartChat()already uses for Mitzo-native sessions.Test plan
tsc --noEmit)setSessionStatemock)🤖 Generated with Claude Code