Title: notifications/cancelled for request `7` cancels a concurrent request `"7"` (`_in_flight` keyed by `coerce_request_id`) · Issue #3807 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: notifications/cancelled for request `7` cancels a concurrent request `"7"` (`_in_flight` keyed by `coerce_request_id`) · Issue #3807 · modelcontextprotocol/python-sdk
X Title: notifications/cancelled for request `7` cancels a concurrent request `"7"` (`_in_flight` keyed by `coerce_request_id`) · Issue #3807 · modelcontextprotocol/python-sdk
Description: Initial checks Reproduced on 2.3.0 and on main d7845c0. Related, but a different code path: #3786 is the Streamable HTTP stream keys (str(id)). This bug also reproduces over stdio. #3432 is about which strings coerce_request_id folds ("0...
Open Graph Description: Initial checks Reproduced on 2.3.0 and on main d7845c0. Related, but a different code path: #3786 is the Streamable HTTP stream keys (str(id)). This bug also reproduces over stdio. #3432 is about w...
X Description: Initial checks Reproduced on 2.3.0 and on main d7845c0. Related, but a different code path: #3786 is the Streamable HTTP stream keys (str(id)). This bug also reproduces over stdio. #3432 is about w...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3807
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"notifications/cancelled for request `7` cancels a concurrent request `\"7\"` (`_in_flight` keyed by `coerce_request_id`)","articleBody":"### Initial checks\n\n- Reproduced on 2.3.0 and on `main` d7845c0.\n- Related, but a different code path:\n - #3786 is the Streamable HTTP stream keys (`str(id)`). This bug also reproduces over stdio.\n - #3432 is about which strings `coerce_request_id` folds (`\"07\"`, `\"+7\"`). This bug occurs with the canonical `\"7\"` the function folds by design.\n - #3060 and #2655 cover a client *reusing* one id. Here the ids differ.\n\n### What happens\n\n`JSONRPCDispatcher` stores inbound requests as `_in_flight[coerce_request_id(req.id)]`. With `7` and `\"7\"` in flight at once, they share a slot. A `notifications/cancelled` naming the earlier one cancels the later one, which then never answers, while the earlier one runs to completion and can no longer be cancelled.\n\n### Reproduction (stdio, unmodified SDK)\n\nA server whose tool blocks until released, receiving these frames in order:\n\n```\n{\"jsonrpc\":\"2.0\",\"id\":\"9007199254740991\",\"method\":\"tools/call\",\"params\":{\"name\":\"gate\",\"arguments\":{\"tag\":\"g0\"}}}\n{\"jsonrpc\":\"2.0\",\"id\":9007199254740991,\"method\":\"tools/call\",\"params\":{\"name\":\"gate\",\"arguments\":{\"tag\":\"g3\"}}}\n{\"jsonrpc\":\"2.0\",\"method\":\"notifications/cancelled\",\"params\":{\"requestId\":\"9007199254740991\"}}\n```\n\nAfter both tools are released, `\"9007199254740991\"` (the one cancelled) answers and `9007199254740991` gets no response. A stdlib-only script that sends these frames to any stdio server command, and exits 1 on the defect: https://github.com/ashirimi1019/mcp-faultline/blob/main/evidence/fl001/minimized/repro_py_stdio_random_seed_6_min.py\n\n### Expected\n\nCancelling one id never affects another. The TypeScript SDK servers (1.32.2 and 2.4.0) key handlers by the typed id and pass the same scenarios.\n\n### Decision needed\n\nShould `notifications/cancelled` match the request id **exactly**?\n\nFixing the slot (exact-id keys) is straightforward. But `test_cancelled_correlates_across_string_and_int_request_id_forms` pins a tolerance where a cancel for `\"7\"` cancels an in-flight `7`. That tolerance can't be kept safely: a late cancel for a just-completed `\"7\"` (a race the spec requires handling gracefully) is indistinguishable from a stringified cancel for `7`. Any fallback, even one that requires a single match, cancels the wrong request in that race. The spec says cancels for unknown or completed ids SHOULD be ignored, and both SDKs' own senders keep the id's type. The analysis is in https://github.com/ashirimi1019/mcp-faultline/blob/main/docs/upstream/exact-id-cancellation.md.\n\n### Patch\n\nA candidate change (8 lines in `jsonrpc_dispatcher.py`, plus regression tests including the late-cancel race) is ready if exact matching is acceptable: https://github.com/ashirimi1019/mcp-faultline/blob/main/docs/upstream/patches/0001-Cancel-only-the-exact-JSON-RPC-request-id.patch\n\nValidated on Ubuntu from source (https://github.com/ashirimi1019/mcp-faultline/actions/runs/41533686584):\n- upstream `scripts/test` passes with 100% coverage and strict-no-cover;\n- `ruff` and `pyright` are clean;\n- typed-id scenarios go from 19/24 to 24/24 over stdio;\n- 150 randomised scenarios pass across stdio and HTTP. The HTTP part also needs the #3786 change.\n\nI'd open a PR only if assigned.\n\n\u003csub>AI disclosure: the defect was found by an automated harness, and this report, the patch and its tests were drafted with AI assistance (Claude Code). Results come from the linked CI run.\u003c/sub>\n","author":{"url":"https://github.com/ashirimi1019","@type":"Person","name":"ashirimi1019"},"datePublished":"2026-11-02T22:58:10Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3807"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fa526992-f1ee-d927-3d4c-bfc49f1a81ab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CAC0:D5AA4:22BB7E:2F7160:6B00B9A9 |
| html-safe-nonce | 54ebe423ac0089adc784cdb7ed9433fb14ce1e5907a7cd507e8ba325e625d04e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUMwOkQ1QUE0OjIyQkI3RToyRjcxNjA6NkIwMEI5QTkiLCJ2aXNpdG9yX2lkIjoiNDIyMTQxNTY5OTM4MzM2ODEwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1254606965e95576c35dba81ecf11b7ea96fd4b4aee6f7b127933f02cc877cfc |
| hovercard-subject-tag | issue:6172585709 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3807/issue_layout |
| twitter:image | https://opengraph.githubassets.com/04b4c9d2a314f042599ef7d4da902da493dc167b12d7a2c1e03a3a0d7b258fa7/modelcontextprotocol/python-sdk/issues/3807 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/04b4c9d2a314f042599ef7d4da902da493dc167b12d7a2c1e03a3a0d7b258fa7/modelcontextprotocol/python-sdk/issues/3807 |
| og:image:alt | Initial checks Reproduced on 2.3.0 and on main d7845c0. Related, but a different code path: #3786 is the Streamable HTTP stream keys (str(id)). This bug also reproduces over stdio. #3432 is about w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ashirimi1019 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1d07c25977adfc5ff6acb0a962a9bc168c07afbda6fef765f9761c350c2ae4a2 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5429cbfc6aca8c7b9a086a3c8f47400346f38cc9 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width