Repository navigation
Description
Summary
/reload can report success and resume the current session before initial MCP loading has completed. A prompt submitted immediately after the command may therefore be sent to the model with only built-in tools and none of the configured MCP tools.
This is a readiness race in the reload lifecycle, not an MCP server failure and not merely a prompting problem: the missing tool was absent from the actual request tool schema.
Environment
- Kimi Code CLI:
0.39.1 - Platform: Linux x86_64
- MCP transport: streamable HTTP
- Also inspected current upstream
mainat0fd89695f5b6427fab53c5284e9eee4360ef15b8; the same asynchronous initialization pattern is still present
The issue occurs before model execution, so it should not depend on the selected model or subscription.
Observed behavior
Before /reload, the configured MCP server was connected and its tools were available.
After /reload:
- A fresh SessionStart reminder was added to the resumed conversation.
- The first outgoing model request contained only built-in tools and zero tools from the configured MCP server.
- A following request still contained zero tools from that MCP server.
- The model could not call the requested MCP tool because it did not exist in the supplied schema. It selected an unrelated built-in tool and subsequently produced unsupported state claims.
- A full Kimi process restart restored the MCP tools in the first outgoing request.
No MCP server name, tool name, URL, or private request data is required to reproduce the lifecycle race.
Source-level cause
The reload path performs a full session runtime teardown and reconstruction:
- The TUI command awaits
reloadSession():kimi-code/apps/kimi-code/src/tui/commands/reload.ts
Lines 16 to 24 in 0fd8969
export async function handleReloadCommand(host: SlashCommandHost): Promise<void> { const tuiConfig = await loadTuiConfig(undefined, (message) => host.showStatus(message, 'warning'), ); const session = host.session; if (session !== undefined) { await session.reloadSession({ forcePluginSessionStartReminder: true }); reloadSession()callscloseForReload(), removes the active session, and resumes it:kimi-code/packages/agent-core/src/rpc/core-impl.ts
Lines 681 to 706 in 0fd8969
async reloadSession(input: ReloadSessionPayload): Promise<ResumeSessionResult> { const summary = await this.sessionStore.get(input.sessionId); const active = this.sessions.get(summary.id); if (active?.hasActiveTurn === true) { throw new KimiError( ErrorCodes.TURN_AGENT_BUSY, `Session "${summary.id}" cannot be reloaded while a turn is running`, { details: { sessionId: summary.id } }, ); } this.reloadProviderManager(); this.clearRuntimeCache(); await this.reloadPlugins({}); if (active !== undefined) { await active.closeForReload(); this.sessions.delete(summary.id); } return this.resumeSessionWithOverrides( { sessionId: summary.id }, { forcePluginSessionStartReminder: input.forcePluginSessionStartReminder, refreshPluginAgents: true, }, ); closeForReload()shuts down all MCP connections:kimi-code/packages/agent-core/src/session/index.ts
Lines 579 to 590 in 0fd8969
async closeForReload(): Promise<void> { this.unsubscribeMcpOAuthCredentials?.(); try { await Promise.allSettled( Array.from(this.readyAgents(), async (agent) => agent.cron?.stop()), ); await this.flushMetadata(); } finally { try { await this.mcp.shutdown(); } finally { await this.logHandle?.close(); - The reconstructed Session starts MCP loading as fire-and-forget work via
void this.loadMcpServers():kimi-code/packages/agent-core/src/session/index.ts
Lines 354 to 356 in 0fd8969
void this.loadMcpServers().catch((error: unknown) => { this.emitInitialMcpLoadError(error); });
Unlike skill loading, MCP loading has no readiness promise awaited by session resume or by the /reload command. Consequently, the command can reload the view and accept the next prompt while MCP discovery is still pending.
Reproduction
- Configure a streamable-HTTP MCP server that exposes at least one uniquely named read-only tool.
- Start Kimi Code and verify that the server is connected and the tool is included in outgoing model requests.
- Run
/reload. - Immediately submit a prompt that requires the unique MCP tool.
- Inspect the first post-reload request tool schema or the session wire.
The race is easier to observe when MCP initialization takes a non-zero amount of time.
Expected behavior
/reload should not report completion or accept the first resumed turn until initial MCP loading has reached a settled state for every configured server (connected, needs-auth, disabled, or a surfaced failure).
Possible approaches:
- Track an MCP readiness promise similarly to
skillsReadyand await it during resume/reload. - Or gate the first post-reload turn until initial MCP discovery settles.
If an MCP server cannot initialize, the reload should surface that failure explicitly rather than silently proceeding with an incomplete tool schema.
Relation to #2742 and #2748
#2742 reports dropped streamable-HTTP sessions, disappearing tools, and unrelated tool selection. #2748 adds call-driven reconnect behavior for dropped sessions.
This report covers a different boundary: initial MCP readiness after an explicit /reload. Even with reconnect support, reloadSession() can currently return while loadMcpServers() is still running, so the first resumed request can still have an incomplete tool list.
Activity