[codex] Prevent MCP tool metadata hangs on malformed responses#110
Open
zoeshawwang wants to merge 1 commit into
Open
[codex] Prevent MCP tool metadata hangs on malformed responses#110zoeshawwang wants to merge 1 commit into
zoeshawwang wants to merge 1 commit into
Conversation
Constraint: MCP Python client can log malformed JSON-RPC errors without waking pending initialize/list_tools awaits. Rejected: Template-side timeout only | leaves SDK callers exposed to the same hang. Confidence: high Scope-risk: narrow Directive: Keep MCP metadata operations bounded so agent creation cannot wait indefinitely on malformed server responses. Tested: uv run ruff check agentrun/tool/api/mcp.py tests/unittests/tool/test_mcp.py; uv run pytest tests/unittests/tool/test_mcp.py -q; uv run pytest tests/unittests/tool -q; git diff --check Not-tested: live MCP server returning malformed JSON-RPC error Closes: coop#82638110 Change-Id: I20569d10af7ba44c140ab19e446d7fc35870f7ec
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.
Summary
Fixes an AgentRun SDK hang where ToolResource MCP metadata loading can wait indefinitely when the MCP Python transport logs a malformed JSON-RPC response, for example an error payload with
error.message = null.Aone: https://project.aone.alibaba-inc.com/v2/project/2139638/req/82638110
Root Cause
The MCP Python streamable HTTP transport can surface malformed JSON-RPC response parsing as an
Exceptionon the read stream. The defaultClientSessionhandler does not route that exception back to the pendinginitializeorlist_toolsrequest, so SDK callers can keep awaiting forever.Changes
initializeandlist_tools) with a 30s timeout so agent creation cannot hang indefinitely on malformed or silent MCP responses.Config.timeoutso tool calls also fail instead of waiting forever.Validation
uv run ruff check agentrun/tool/api/mcp.py tests/unittests/tool/test_mcp.pyuv run pytest tests/unittests/tool/test_mcp.py -quv run pytest tests/unittests/tool -qgit diff --checkNotes
The MCP service should still be fixed to return a valid JSON-RPC error with a string
error.message; this SDK change prevents the client-side hang while preserving that server-side requirement.