Skip to content

fix(agent-manager): evict stale worktree pool slots and cold-create - #14556

Merged
marius-kilocode merged 1 commit into
mainfrom
innovative-jaxartosaurus
Sep 25, 2026
Merged

marius-kilocode merged 1 commit into
mainfrom
innovative-jaxartosaurus

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes #14453.

When a pooled Agent Manager worktree slot was deleted on disk outside the extension (for example by a worktree-hygiene script), every later worktree create failed in about 1.7 s with no git side effects. The pool kept returning the dead slot, so every create failed until the extension host restarted.

Why This Change Was Made

WorktreeManager.createWorktreeImpl asks the pool to claim a slot before running git worktree add. The pool constructed a simple-git client on the slot path before checking that the directory existed. When the directory was gone, simple-git threw Cannot use simple-git on a directory that does not exist, the exception skipped the pool discard path, and the poisoned slot stayed cached in memory.

The pool now validates the slot on claim. A slot whose .git is missing is logged, discarded, and evicted, and the claim tries the remaining slots before falling back to a normal cold git worktree add. Worktree creation failures are also written to the extension Output channel through ctx.log(), not only the webview toast and telemetry.

User Impact

Worktree creation recovers automatically after an externally deleted pool slot. Users no longer need to disable the worktree pool or reload the window.

Evidence

New regression tests use a real temporary git repository:

  • Warm the pool, delete the slot directory, create twice. Both creates succeed through the cold path, the stale slot is evicted, and the eviction is logged.
  • With two pooled slots, delete the slot the pool tries first. The healthy slot is reused instead of a cold create.

Automated checks from packages/kilo-vscode/:

  • bun test tests/unit/worktree-pool.test.ts tests/unit/worktree-create.test.ts - 14 pass, 0 fail
  • bun test tests/unit/worktree-manager.test.ts - 133 pass, 1 skip
  • bun run typecheck - clean
  • bun run lint - clean

A pooled slot deleted on disk outside the pool made every create fail, because simple-git throws when constructed on a missing directory and the exception bypassed the pool discard path. Validate the slot before use, evict stale entries, and try remaining slots before falling back to a cold worktree add. Log worktree creation failures to the Output channel.
@kilo-code-bot

kilo-code-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The stale-slot eviction is guarded before simple-git is constructed, every failed take() removes its slot so the new exact/delta retry loops terminate, and the regression tests exercise a real temporary git repo. No memory leaks or changed-line defects found.

Files Reviewed (5 files)
  • .changeset/stale-worktree-pool-slot.md
  • packages/kilo-vscode/src/agent-manager/worktree-create.ts
  • packages/kilo-vscode/src/agent-manager/worktree-pool.ts
  • packages/kilo-vscode/tests/unit/worktree-create.test.ts
  • packages/kilo-vscode/tests/unit/worktree-pool.test.ts

Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

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.

Agent Manager worktree pool: stale slot never evicted

2 participants