feat(agent-manager): pre-warm worktrees to speed up session creation - #14050
Conversation
Register a detached worktree in the background and claim it for a new session instead of running a full worktree checkout at creation time. Add per-phase creation timing and the "Pre-warm worktrees" Agent Manager setting, enabled by default. Also fix a claim path that could reset an existing branch whose name matched a pooled worktree directory, and raise the worktree add worker count for the fallback path.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Incremental review of Resolved since last review
Files Reviewed (1 file)
Previous Review Summaries (6 snapshots, latest commit 6435aa9)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 6435aa9)Status: No Issues Found | Recommendation: Merge Incremental review of Resolved since last review
Files Reviewed (2 files)
Previous review (commit a81cdf9)Status: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (5 files)
Fix these issues in Kilo Cloud Previous review (commit eb495fa)Status: 3 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (17 files)
Notes on prior findings: the detached Fix these issues in Kilo Cloud Previous review (commit 7b18939)Status: 4 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (20 files)
Fix these issues in Kilo Cloud Previous review (commit b5ab644)Status: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
All four findings from the previous review were re-verified against Previous review (commit f90f52a)Status: 4 Issues Found | Recommendation: Address before merge Fix these issues in Kilo Cloud Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (43 files)
Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
…ed slots Resolve the base ref and its commit before taking the shared git lock so a cold fetch cache never stalls user worktree operations. When adopting a leftover slot, use the worktree's real HEAD instead of persisted metadata. Apply the pre-warm toggle immediately instead of on Save, and drop fixed sleeps from the pool tests.
…-worktree-creation-latency
- remove a worktree's snapshot repository on every teardown path that deletes the worktree, and stop blocking error reporting on preparation - let cleanup remove a prepared repository that was never tracked, and skip preparation when the worktree is already gone - require auth for POST /kilocode/snapshot/prepare like snapshot/remove - keep the multi-version structure test and the snapshot materialization poll aligned with the current code shape
…ot repository - delete the matching refs/kilo/materialize pin from the project checkout after a prepared but never tracked snapshot repository is removed - keep primary checkout paths that contain newlines working by falling back to per-field rev-parse when the combined output does not have exactly four lines - correct the changeset wording (four git calls into one)
What Problem This Solves
Creating a new Agent Manager worktree blocks on
git worktree add, which checks out every tracked file. On the Kilo repository (about 10,000 tracked files) that checkout takes about 2.1 s, and it scales with repository size, so large repositories pay many seconds before a new session is usable.Why This Change Was Made
Register a detached worktree in the background and claim it for a new session with a cheap ref update instead of running a second full checkout at creation time. The behavior is scoped to the new "Pre-warm worktrees" Agent Manager setting (
kilo-code.new.agentManager.worktreePool), enabled by default. Per-phase creation timing was added so the remaining cost is measurable. The change also fixes a claim path that could reset an existing local branch whose name matched a prepared worktree directory, and raises the fallbackgit worktree addworker count.User Impact
Evidence
Creation timing measured through
WorktreeManager.createWorktreeon a local clone, median of 3 runs, macOS/APFS, no setup script.Raw git on the large clone: full
git worktree addabout 2.1 s, registration only about 75 ms, a ref-only claim about 70 ms, and a cold-indexgit statusabout 400 ms. Raising the fallback worker count from 2 to 4 saves about 150 ms.Limitations: these are worktree creation timings, not end-to-end time to first token. The model provider still dominates time to first token, and a configured setup script still runs after creation. Measurements were taken outside VS Code, so file watcher interaction is not included.