fix(web,mcp): gracefully degrade when MCP loading fails in Web UI worker#1816
Open
AI-fullcup wants to merge 1 commit intoMoonshotAI:mainfrom
Open
fix(web,mcp): gracefully degrade when MCP loading fails in Web UI worker#1816AI-fullcup wants to merge 1 commit intoMoonshotAI:mainfrom
AI-fullcup wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
When an MCP server fails to connect (e.g., due to a port conflict), the Web UI session worker previously crashed entirely, causing messages to get stuck in thinking state indefinitely. Changes: - In `_agent_loop()`, catch `MCPRuntimeError` during `wait_for_background_mcp_loading()` and log a warning instead of letting the exception crash the agent loop. - In `_read_loop()`, when an unexpected exception occurs, clear `_in_flight_prompt_ids` and emit an error status so the frontend can recover instead of leaving prompts stuck in thinking state. Fixes MoonshotAI#1766
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.
Problem
When an MCP server fails to connect (e.g., due to a port conflict when switching from TUI to Web UI), the Web UI session worker crashes entirely. This causes messages to get stuck in the "thinking" state indefinitely, and the frontend becomes unresponsive.
This is described in detail in #1766.
Root Cause
In
kimi_cli/soul/kimisoul.py,_agent_loop()callswait_for_background_mcp_loading()inside atry/finallyblock. Thefinallyonly ensuresMCPLoadingEndis sent, but does not catchMCPRuntimeError. The exception bubbles up and crashes the agent loop.In
kimi_cli/web/runner/process.py,_read_loop()catches unexpected exceptions but:_in_flight_prompt_ids"error"or"idle"status to WebSocketsChanges
src/kimi_cli/soul/kimisoul.py:MCPRuntimeErrorMCPRuntimeErrorduringwait_for_background_mcp_loading()and log a warning, allowing the conversation to continue without MCP tools.src/kimi_cli/web/runner/process.py:_read_loop(), clear_in_flight_prompt_idsand emit an"error"status so the frontend can recover instead of leaving prompts stuck in "thinking".Testing
py_compileFixes #1766