fix(agent-core-v2): make MCP initial connect non-blocking during startup - #2586
Merged
Conversation
🦋 Changeset detectedLatest commit: de1cf8c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Signed-off-by: 7Sageer <sag77r@hotmail.com>
commit: |
…o fix/mcp-nonblocking-startup
Merged
mbuckaway
pushed a commit
to mbuckaway/kimi-code
that referenced
this pull request
Aug 4, 2026
…tup (MoonshotAI#2586) * fix(agent-core-v2): make MCP initial connect non-blocking during startup * Delete .changeset/mcp-nonblocking-startup.md Signed-off-by: 7Sageer <sag77r@hotmail.com> * fix(agent-core-v2): wait for MCP readiness before first turn * fix(klient): wait for MCP startup before listing * fix(klient): keep MCP server listing non-blocking * test(acp-server): allow pending MCP snapshot --------- Signed-off-by: 7Sageer <sag77r@hotmail.com>
daofazhiran
pushed a commit
to daofazhiran/kimi-code
that referenced
this pull request
Aug 4, 2026
…tup (MoonshotAI#2586) * fix(agent-core-v2): make MCP initial connect non-blocking during startup * Delete .changeset/mcp-nonblocking-startup.md Signed-off-by: 7Sageer <sag77r@hotmail.com> * fix(agent-core-v2): wait for MCP readiness before first turn * fix(klient): wait for MCP startup before listing * fix(klient): keep MCP server listing non-blocking * test(acp-server): allow pending MCP snapshot --------- Signed-off-by: 7Sageer <sag77r@hotmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
No linked issue — the problem is explained below.
Problem
In the v2 engine (kap-server / agent-core-v2), session creation synchronously awaited the workspace MCP initial connect:
materializeSessionawaitedISessionMcpHandle.ready, which only resolves after every configured MCP server has connected or timed out (default 30s per server). The TUI awaits session creation before starting its UI event loop, so a slow or hung MCP server left users staring at a blank terminal on startup — create, resume, and fork were all affected. Agent creation paid the same wait a second time viaawait mcpReadyin the agent lifecycle.The v1 engine does not have this problem: its
Sessionconstructor kicks off MCP loading fire-and-forget and only the first turn waits for the initial load, so the UI comes up immediately and the MCP latency overlaps with the user's reading/typing time.What changed
Adopt the v1 timing in v2 — startup no longer waits for MCP; the first LLM step does:
SessionLifecycleService.materializeSessionno longer awaitsthis.mcp.ready(nor the ephemeral overlay'sready). Workspace MCP connection still starts immediately in the background, and status keeps flowing through the existingmcp.server.status/tool.list.updatedevents, so clients can observe readiness.AgentLifecycleServiceno longer captures/awaits the session MCP handle'sreadybefore creating an agent; the now-unusedISessionMcpHandleinjection is dropped.AgentMcpServiceregisters anonWillBeginStephook that awaitswaitForInitialLoad(ctx.signal)before each LLM request, so the first step still sees the complete MCP tool list. The cost is one-time — the promise is already resolved for subsequent steps — and the hook is interruptible via the turn signal. The existing per-serverwaitUntilgate on MCP tool calls stays as a fallback.Tests: flipped the three blocking assertions (session create/resume, agent create) to assert immediate return, re-gated the resume-hiding test on main-agent creation, added coverage that the first step waits for the initial MCP load while the second runs straight through, and made the shared-manager workspace-resources test await the seeded readiness explicitly. Full agent-core-v2 suite (289 files / 4512 tests) green,
tsc --noEmitclean.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.