Repository navigation
fix(mcp): record canceled client tool calls as errors - #21137
bvolpato-dd wants to merge 1 commit into
Conversation
a5c7c9e to
f28a633
Compare
5cda374 to
65ec576
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
More details
The cancellation handler preserves exception propagation for asyncio and Trio while leaving coroutine closure outside the error path. Runtime behavior remains unverified because required dependencies were unavailable.
🤖 Bits Code Review · Commit 65ec576
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 004bad94c8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
3284bc6 to
a330156
Compare
There was a problem hiding this comment.
More details
Cancellation exceptions now use the existing error-finalization path while preserving exception propagation and coroutine closure behavior. No actionable defect was identified; runtime validation was limited by a missing test dependency.
🤖 Bits Code Review · Commit a330156
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a33015636c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
a330156 to
8876286
Compare
There was a problem hiding this comment.
More details
Canceled MCP client tool calls now reach the existing error-finalization path while the original cancellation continues to propagate.
🤖 Bits Code Review · Commit 8876286
|
Current state ( What the PR does
What changed in this revision
Validation
Why
Still needed before merge
[bruno-seek-approval] |
Description
When a caller cancels an in-flight
ClientSession.call_tool(), the span is reported as successful in APM and LLM Observability.traced_call_tool()only caughtException, butasyncio.CancelledErrorandtrio.Cancelledinherit fromBaseException.The wrapper now catches
BaseException, records the error, and re-raises it. This matchesinitializeandlist_toolsin the same file, which already record cancellation as an error.As a consequence,
KeyboardInterrupt,SystemExitwith a nonzero code, andGeneratorExit(a suspended call whose coroutine is closed) are also recorded as errors for tool calls, as they are forinitializeandlist_tools.Customer impact
Canceled MCP client tool calls appear as errors in APM and LLM Observability, with the cancellation exception as the error type. A release note is included.
Testing
tests/contrib/mcp/test_client_cancellation.pycancels a tool call once its request is in flight. It checks that the cancellation propagates, that the APM span has the error flag and error type, and that the LLM Observability event has error status and the same error type.mcp~=1.10.0,mcp<2, andmcp2.x (Python 3.12).tests/contrib/mcpsuite passes with the fix in all 17 configured environments (Python 3.10 through 3.15).mcp~=1.10.0,trio==0.34.0) and the cancellation cases passed. It is not part of the CI matrix.scripts/lint checkspasses.GitLab CI and System Tests have not run on this commit; see below.
Risks
Applications that cancel MCP client tool calls may see higher error counts, which can affect monitors on MCP error rates.
Additional Notes
download-s3-wheelsfails because GitLab does not build wheels for fork commits. A maintainer needs to run CI through the fork procedure after reviewing the commit.This PR was AI-assisted. If this change is not worth pursuing, please close it with a brief rationale.