Skip to content

perf(agent-manager): overlap MCP startup with worktree creation - #11074

Merged
marius-kilocode merged 1 commit into
mainfrom
adjoining-quality
Jun 11, 2026
Merged

perf(agent-manager): overlap MCP startup with worktree creation#11074
marius-kilocode merged 1 commit into
mainfrom
adjoining-quality

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

Cold Agent Manager worktree sessions currently initialize MCP servers only after worktree setup, session creation, and snapshot tracking. That makes MCP connection time a separate serial stage immediately before the first model request, even though MCP initialization does not depend on snapshot completion.

This change starts a directory-scoped MCP status request as soon as worktree setup finishes, before the CLI session is created. Session creation and the initial prompt continue without awaiting that request. The existing mcp.tools() call remains the synchronization point before model dispatch, so tool resolution still waits if initialization is genuinely unfinished.

The warmup lives in the shared Agent Manager worktree-session creation path. This covers normal New Worktree creation, configured and multi-version creation, imported worktrees, and Agent Manager tool-created worktrees without duplicating orchestration. It does not initialize MCP for unrelated directories or during extension startup. Warmup failures are caught and logged, so they cannot reject worktree/session creation or become unhandled promise rejections.

Observed cold-flow difference in the same repository and modal flow:

Stage Before After Difference
MCP/tool resolution after snapshot 1.356s 0.106s 1.250s less serial work (92%)
Provider dispatch to first backend delta 1.304s 1.323s Effectively unchanged
Modal submit to first rendered token 11.642s 12.144s 0.502s slower in this sample

The end-to-end sample varied because worktree/session setup and snapshot tracking were slower in the after run. Backend ordering confirms the intended optimization independently of that variance: MCP discovery and client creation moved into snapshot initialization, completed about 4.5 seconds before snapshot tracking finished, and no longer occupied the serial resolveTools() stage.

This deliberately does not change snapshot behavior or shared CLI code. Snapshot startup remains the dominant cold-worktree cost and can be optimized independently, while this change ensures MCP initialization is already overlapped rather than becoming the next serial bottleneck.

Comment thread packages/kilo-vscode/src/agent-manager/mcp-warmup.ts
@kilo-code-bot

kilo-code-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-vscode/src/agent-manager/mcp-warmup.ts 13 Potential memory/retention leak: if client.mcp.status() never settles, the warm async function suspends indefinitely, holding the log closure (which captures this/the provider instance) alive even after dispose(). No timeout or AbortSignal bounds the warmup lifetime.
Other Observations (not in diff)

Import grouping nit (AgentManagerProvider.ts line 38): The startSession import is separated from the contiguous block of local ./ imports by a blank line after line 36. The existing style in this file groups all local imports together without internal blank lines. This is cosmetic and won't affect behaviour.

Files Reviewed (5 files)
  • .changeset/warm-agent-manager-mcp.md — no issues
  • packages/kilo-vscode/src/agent-manager/mcp-warmup.ts — 1 issue
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts — no issues (call site looks correct)
  • packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts — no issues
  • packages/kilo-vscode/tests/unit/agent-manager-mcp-warmup.test.ts — no issues (tests exercise real implementation, ordering is reliable)

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-4.6 · 446,226 tokens

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit 8a5a64b into main Jun 11, 2026
21 checks passed
@marius-kilocode
marius-kilocode deleted the adjoining-quality branch June 11, 2026 13:52
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
perf(agent-manager): overlap MCP startup with worktree creation
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.

2 participants