Title: fix(shared): stop concurrent int/string request ids from colliding in _in_flight by 1828703450qqcom-ux · Pull Request #3815 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix(shared): stop concurrent int/string request ids from colliding in _in_flight by 1828703450qqcom-ux · Pull Request #3815 · modelcontextprotocol/python-sdk
X Title: fix(shared): stop concurrent int/string request ids from colliding in _in_flight by 1828703450qqcom-ux · Pull Request #3815 · modelcontextprotocol/python-sdk
Description: fix(shared): stop concurrent int/string request ids from colliding in _in_flight Fixes #3807 Summary JSONRPCDispatcher._in_flight keyed inbound requests by coerce_request_id(req.id), which folds "7" and 7 into one dict slot. Two concurrent requests whose ids differ only in JSON-RPC type blind-overwrote each other, and a notifications/cancelled naming one cancelled whichever was stored — the other ran to completion and could no longer be cancelled. Store in-flight requests under the verbatim id so distinct wire representations stay distinct. Cancellation looks up the exact id first and falls back to coerced/stringified forms so a peer that echoes a different type between request and cancel still cancels the request (the existing test_cancelled_correlates_across_string_and_int_request_id_forms passes unchanged in both parametrizations). Reproduction Unmodified SDK, stdio, two concurrent requests with ids "9007199254740991" (string) and 9007199254740991 (int), plus a notifications/cancelled for the string id (see the reproduction script linked in #3807): on main: the cancel hits the int-id request (they share the coerced slot); the string-id request answers, the int-id request never does. after the fix: the cancel hits only the string-id request; the int-id request answers normally. Fix src/mcp/shared/jsonrpc_dispatcher.py — three hunks: Store (_dispatch_request): self._in_flight[req.id] = ... — verbatim id, no coercion. Cancel (_dispatch_notification): exact-id lookup first; if missed, try the coerced id and its stringified form so cross-type echo still correlates. Delete (_handle_request): pop by verbatim id, matching the store. The pending (outbound correlation) table is untouched: its coercion is correct and needed for response matching. Validation New regression test test_peer_cancel_does_not_cross_request_id_types: case on main (af4c6f4) after concurrent "9007199254740991" and 9007199254740991, cancel the string one int-id request cancelled (wrong); string-id answered string-id cancelled; int-id answers cross-type echo: cancel with int for a string-id request passes passes (coerced fallback) cross-type echo: cancel with string for an int-id request passes passes (stringified fallback) The regression test fails on unmodified main (the int-id request gets no response) and passes after. Full tests/shared/test_jsonrpc_dispatcher.py: 80 passed, 0 failed — zero regressions, including both parametrizations of the cross-type correlation test. Scope 2 files: src/mcp/shared/jsonrpc_dispatcher.py and tests/shared/test_jsonrpc_dispatcher.py. No change to the outbound pending table, _allocate_id, the direct dispatcher's collision detection, or any handler/cancellation semantics beyond the id-keying described above.
Open Graph Description: fix(shared): stop concurrent int/string request ids from colliding in _in_flight Fixes #3807 Summary JSONRPCDispatcher._in_flight keyed inbound requests by coerce_request_id(req.id), which folds &...
X Description: fix(shared): stop concurrent int/string request ids from colliding in _in_flight Fixes #3807 Summary JSONRPCDispatcher._in_flight keyed inbound requests by coerce_request_id(req.id), which folds &...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3815
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2ab40882-040f-f2f8-4da3-b21a61e0c223 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DE18:3A347:27F9EF:36986C:6B00C242 |
| html-safe-nonce | 4d59f76d1c8243905ae828d51e0a2461fc6bf911cf5d2420c95d9d172ee0f120 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTE4OjNBMzQ3OjI3RjlFRjozNjk4NkM6NkIwMEMyNDIiLCJ2aXNpdG9yX2lkIjoiNzkwNzExNjg3OTE0NjE3Mjk5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6c36add75d2c7caa39d2847b4b7db682cdfe1e9298630ce480b1c576a517d4f8 |
| hovercard-subject-tag | pull_request:5157563906 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/modelcontextprotocol/python-sdk/pull/3815/files |
| twitter:image | https://avatars.githubusercontent.com/u/265310764?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/265310764?s=400&v=4 |
| og:image:alt | fix(shared): stop concurrent int/string request ids from colliding in _in_flight Fixes #3807 Summary JSONRPCDispatcher._in_flight keyed inbound requests by coerce_request_id(req.id), which folds &... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 93edd3bebc4afb7ce711ee74cb5d2a95927850b082a4d43e212222389cb1c415 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1fee81a280ea86312b69448e261b418189bfd5b5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width