fix: categorize tool transport errors as SYSTEM with actionable messages#967
Open
ionut-mihalache-uipath wants to merge 1 commit into
Open
fix: categorize tool transport errors as SYSTEM with actionable messages#967ionut-mihalache-uipath wants to merge 1 commit into
ionut-mihalache-uipath wants to merge 1 commit into
Conversation
Integration tool calls that hit an httpx timeout and MCP tool calls that fail with a protocol-level McpError (e.g. "Session terminated") currently propagate raw and get mapped to AGENT_RUNTIME.UNEXPECTED_ERROR with category Unknown - and for timeouts, an empty detail, since str(httpx.ReadTimeout) is "". - integration_tool: catch httpx.TimeoutException and raise AgentRuntimeError(HTTP_ERROR, SYSTEM) with a retry hint naming the tool - mcp_tool: catch McpError and raise AgentRuntimeError(HTTP_ERROR, SYSTEM); session errors (32600/-32000) get a "connection terminated, retry later" message, other codes surface the server's own error message - mcp_client: expose the configured server slug as a public property Both raises use should_wrap=False so the message is not buried under the generic unexpected-error prefix, and chain the original exception. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N4bvjRA16sKYhsW3mHHpiZ
There was a problem hiding this comment.
Pull request overview
This PR improves agent run failure triage by mapping two previously “Unknown/Unexpected” tool transport failure modes (Integration Service timeouts and MCP protocol/session errors) into structured AgentRuntimeErrors categorized as SYSTEM, with actionable, unwrapped messages while preserving the original exception as the cause.
Changes:
- Catch
httpx.TimeoutExceptionin Integration Service tool invocation and raiseAgentRuntimeError(HTTP_ERROR, SYSTEM, should_wrap=False)with a retry hint. - Catch protocol-level
McpErrorduring MCP tool calls and map it via_map_mcp_error()intoAgentRuntimeError(HTTP_ERROR, SYSTEM, should_wrap=False), with special messaging for session termination codes. - Expose
McpClient.server_slugto allow MCP error messages to name the server, and add targeted tests for both behaviors.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/uipath_langchain/agent/tools/integration_tool.py |
Maps Integration Service timeouts to categorized AgentRuntimeError with actionable retry guidance. |
src/uipath_langchain/agent/tools/mcp/mcp_tool.py |
Maps protocol/session-level McpError exceptions to categorized AgentRuntimeError with server/tool context. |
src/uipath_langchain/agent/tools/mcp/mcp_client.py |
Adds a public server_slug property for safer access in error reporting. |
tests/agent/tools/test_integration_tool.py |
Adds a regression test ensuring timeouts become SYSTEM AgentRuntimeError with a chained cause. |
tests/agent/tools/test_mcp/test_mcp_tool.py |
Adds tests verifying MCP protocol errors are categorized/messaged correctly and non-McpError exceptions still propagate. |
|
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.



Why
Two production failure modes currently surface as
AGENT_RUNTIME.UNEXPECTED_ERROR/ categoryUnknown, making them useless for alert triage and confusing for agent builders:httpx.ReadTimeoutfrominvoke_activity_asyncpropagates raw tomap_runtime, which only special-casesEnrichedException/HTTPStatusError. Worse,str(httpx.ReadTimeout)is"", so the tracked event shows an emptyError Details:section (observed on a SupplierDueDiligence run,AgentRunId dc567786-6243-4bce-b50f-27b4fee4a107).McpError("Session terminated")(synthesized by our streamable HTTP transport when the server 404s the session, afterMcpClient's session-reinit retry is exhausted) propagates raw the same way.What
integration_tool.py: catchhttpx.TimeoutExceptioninintegration_tool_fnand raiseAgentRuntimeError(HTTP_ERROR, SYSTEM)with a retry hint naming the tool. Only timeouts are caught; other transport errors propagate as before.mcp_tool.py: catchMcpErrorintool_fnand raiseAgentRuntimeError(HTTP_ERROR, SYSTEM)via a new_map_mcp_errorhelper. Session error codes (32600/-32000) get a "connection to MCP server '' was terminated and could not be re-established… retry the run later" message; other codes surface the server's own error message. MCP tool execution failures come back asCallToolResult.isErrorresults, not exceptions, so a raisedMcpErroris always protocol/session/transport-level —SYSTEMis the right category.mcp_client.py: exposeserver_slugas a public property so the error message can name the server without reaching into_config.Both raises use
should_wrap=Falseso the actionable message isn't buried under the generic "An unexpected error occurred…" prefix, and chain the original exception (from e) so tracebacks keep the root cause.Behavior note: for conversational agents, tool exceptions are converted to error
ToolMessages bywrap_tools_with_error_handling, so this only changes run-failure classification on the non-conversational path (the LLM just sees a friendlier message on the conversational one).Testing
test_timeout_raises_agent_runtime_error_with_system_categoryintest_integration_tool.pyTestMcpToolErrorHandlingclass intest_mcp_tool.py(session error, non-session error, non-McpError passthrough)uv run pytest tests/agent/tools/test_integration_tool.py tests/agent/tools/test_mcp/— all passruff check,ruff format --check,mypyclean on touched files🤖 Generated with Claude Code
https://claude.ai/code/session_01N4bvjRA16sKYhsW3mHHpiZ