-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
[Performance]: Session switch blocks on synchronous MCP tool materialization (getCatalog + createRuntime) - 5-8s delay per switch #89408
Copy link
Copy link
Open
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.
Type
Fields
Priority
None yet
Problem
Switching between sessions in the OpenClaw TUI/agent runtime takes 5-8 seconds due to synchronous MCP tool materialization in
createRuntime. Every session switch spawns a new stdio MCP subprocess, fetches the full tool catalog, and registers all tools before the session becomes usable.Environment
Root Cause (Source Analysis)
The session switch path in sessions-htxRTdBr.js:
switchSession(path)
-> teardownCurrent() (dispose old session, serial)
-> createRuntime() (rebuilds entire runtime)
-> materializeMcpToolsForAgent()
-> getOrCreateSessionMcpRuntime()
-> getCatalog() (SYNCHRONOUS blocking call)
-> spawn stdio child process (~1-3s)
-> connectWithTimeout(30s) (~0.5-1s)
-> listAllTools() (~1-2s, 70+ tool definitions)
-> register 70+ tools to registry (~0.5-1s)
-> finishSessionReplacement()
Key source evidence:
getCatalog() is synchronous (agent-bundle-mcp-runtime--qlnxWNy.js:625-695): iterates all MCP servers, spawns stdio processes, connects, and lists tools - all awaited in series. Default connection timeout: 30s per server.
Tool materialization blocks createRuntime (agent-bundle-mcp-materialize-DAJQADAM.js:81): catalog = await params.runtime.getCatalog() blocks until all tools fetched.
No cross-session connection pooling (agent-bundle-mcp-runtime--qlnxWNy.js:789-830): runtimesBySessionId.get(params.sessionId) - each session gets its own key, so switching sessions always creates a new runtime with a new Python process.
sweepIdleRuntimes() runs on every getOrCreate call - unnecessary overhead.
Performance Breakdown (Estimated)
Suggested Fixes
P0: Cross-session MCP connection pool
Share a single stdio server connection across sessions instead of spawning per-session. The tool catalog for a given server config is identical across all sessions. Key change: use runtimesByConfigHash instead of runtimesBySessionId. Expected: 5-8s to less than 1s.
P1: Lazy tool materialization
Move getCatalog() out of the synchronous createRuntime path. Start catalog fetch in background, allow session to become usable with partial tool list. Expected: 5-8s to 1-2s.
P2: Tool definition cache
Cache resolved tool definitions to disk per server config hash. Avoid re-fetching identical 70+ tool definitions on every cold start. Expected: cold start 3-5s to 1-2s.
Related Issues
Reproduction