René's URL Explorer Experiment


Title: fix(dispatcher): reject duplicate in-flight request ids by akminx · Pull Request #3064 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: fix(dispatcher): reject duplicate in-flight request ids by akminx · Pull Request #3064 · modelcontextprotocol/python-sdk

X Title: fix(dispatcher): reject duplicate in-flight request ids by akminx · Pull Request #3064 · modelcontextprotocol/python-sdk

Description: Opening this as the concrete artifact of the offer I made on #3060. It's ready and green, but I'm putting it up for your convenience, not to jump the queue — happy to close it immediately if you'd rather own this or fold it into the cancellation work. No hard feelings either way. Disclosure: this change was developed with AI assistance. I reviewed the code and the test results, understand the change, and can speak to it. Motivation and Context Fixes the dispatcher-layer half of #3060, complementary to the transport-level guard in #3063. JSONRPCDispatcher._dispatch_request registered every inbound request in _in_flight with a blind overwrite keyed by request id — the TODO(maxisbey): duplicate ids blind-overwrite (v1/TS parity); revisit rejecting with INVALID_REQUEST added in #3046. On current main, two concurrent requests carrying the same JSON-RPC id on one session silently displace each other: The older request's _in_flight entry is evicted at registration time, so a notifications/cancelled for that id (which correlates against _in_flight) always targets the newest request — the older one becomes uncancellable the moment the duplicate arrives. The completion path carried an identity guard (entry.dctx is dctx) specifically to stop the older request's cleanup from evicting the newer entry. @Sammy-Dabbas's #3063 fixes the streamable-HTTP transport, where the slot overwrite happens at POST-handling time before the dispatcher is reached. This change fixes the dispatcher itself, which covers the other transports plus the cancellation-targeting case, as discussed on the issue. The direct_dispatcher already rejects duplicate in-flight ids for caller-supplied ids (request id ... is already in flight); this makes the wire dispatcher consistent with it. How Has This Been Tested? Rejection is checked before any await in _dispatch_request and the read loop dispatches messages sequentially, so a duplicate can never register between the guard and the write — no new race is introduced. Added three tests in tests/shared/test_jsonrpc_dispatcher.py: test_duplicate_in_flight_request_id_is_rejected_with_invalid_request — a duplicate id while the first is outstanding gets INVALID_REQUEST; its handler never runs; the original still completes. test_duplicate_id_rejection_leaves_original_request_cancellable — after the duplicate is rejected, notifications/cancelled still targets the original, still-running request (the cancellation-targeting regression). test_request_id_is_reusable_after_the_earlier_request_completes — sequential reuse of an id after completion is still accepted. Full suite passes (5288 passed) at 100.00% branch coverage; pyright and ruff check/ruff format are clean on the touched files. Implementation notes The reject guard reuses the coerced key for the later registration, so a stringified cancellation id still correlates. With duplicate registration ruled out, the completion path's identity-guarded pop (entry.dctx is dctx) is now unreachable dead code, so it is simplified to a plain _in_flight.pop(key, None). The two tests that exercised the old overwrite/identity-guard behavior are replaced by the rejection tests above. This flips the behavior the TODO(maxisbey) reserved for "v1/TS parity." That parity now points the other way: #2434 flips the TypeScript server to reject as well, so rejecting here keeps the two SDKs aligned. Happy to adjust the choice (or hold this) if you'd rather fold it into the cancellation work — the tests stand on their own either way. Breaking Changes Behavior change only for a protocol violation: a second request reusing an id that is still in flight now receives an INVALID_REQUEST error instead of silently overwriting the first request's routing. Sequential id reuse after completion is unchanged. Types of changes Bug fix (non-breaking change which fixes an issue) Checklist I have read the MCP Documentation My code follows the repository's style guidelines New and existing tests pass locally I have added appropriate error handling I have added or updated documentation as needed

Open Graph Description: Opening this as the concrete artifact of the offer I made on #3060. It's ready and green, but I'm putting it up for your convenience, not to jump the queue — happy to close it immediately i...

X Description: Opening this as the concrete artifact of the offer I made on #3060. It's ready and green, but I'm putting it up for your convenience, not to jump the queue — happy to close it immed...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3064

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:f6922c6d-1fbb-cbd2-9a3a-f0293daaff10
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA250:26FD39:78808A:A3159F:6A5CD547
html-safe-nonce260faa577c88e2da234d61c212e1e2383613e4bac8e313a5145ca2f4f1d1dcd2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjUwOjI2RkQzOTo3ODgwOEE6QTMxNTlGOjZBNUNENTQ3IiwidmlzaXRvcl9pZCI6IjE5MDAzNzU1NzExNTIyOTUyMzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac85c02f5ffe0f1a9b3315c35ba71647c467c7908f6f80a708bd50ed3e2316a95c
hovercard-subject-tagpull_request:3992529594
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/3064/files
twitter:imagehttps://avatars.githubusercontent.com/u/272697015?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/272697015?s=400&v=4
og:image:altOpening this as the concrete artifact of the offer I made on #3060. It's ready and green, but I'm putting it up for your convenience, not to jump the queue — happy to close it immediately i...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9c975978430e9ad293956f2bbdaf153b1bd84a99
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3064%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3064%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Star 23.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 259 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 306 https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality 6 https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Code https://github.com/modelcontextprotocol/python-sdk
Issues https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
akminxhttps://github.com/akminx
modelcontextprotocol:mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
akminx:fix-dispatcher-duplicate-inflighthttps://github.com/akminx/python-sdk/tree/fix-dispatcher-duplicate-inflight
Conversation 0 https://github.com/modelcontextprotocol/python-sdk/pull/3064
Commits 1 https://github.com/modelcontextprotocol/python-sdk/pull/3064/commits
Checks 30 https://github.com/modelcontextprotocol/python-sdk/pull/3064/checks
Files changed 2 https://github.com/modelcontextprotocol/python-sdk/pull/3064/files
fix(dispatcher): reject duplicate in-flight request ids https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#top
Show all changes 1 commit https://github.com/modelcontextprotocol/python-sdk/pull/3064/files
39c03ad Reject duplicate in-flight request ids in the JSON-RPC dispatcher akminx Jul 5, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3064/commits/39c03adcf6967cf28c1ae785cc0f8159a666d016
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/3064/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files
jsonrpc_dispatcher.py https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
test_jsonrpc_dispatcher.py https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-ce6a750fbce4c4bfa60b1845cdd92c08be0c2ed1fdcecdcb2a2efa24170efabd
src/mcp/shared/jsonrpc_dispatcher.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
View file https://github.com/modelcontextprotocol/python-sdk/blob/39c03adcf6967cf28c1ae785cc0f8159a666d016/src/mcp/shared/jsonrpc_dispatcher.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3064/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
tests/shared/test_jsonrpc_dispatcher.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-ce6a750fbce4c4bfa60b1845cdd92c08be0c2ed1fdcecdcb2a2efa24170efabd
View file https://github.com/modelcontextprotocol/python-sdk/blob/39c03adcf6967cf28c1ae785cc0f8159a666d016/tests/shared/test_jsonrpc_dispatcher.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3064/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-ce6a750fbce4c4bfa60b1845cdd92c08be0c2ed1fdcecdcb2a2efa24170efabd
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-ce6a750fbce4c4bfa60b1845cdd92c08be0c2ed1fdcecdcb2a2efa24170efabd
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-ce6a750fbce4c4bfa60b1845cdd92c08be0c2ed1fdcecdcb2a2efa24170efabd
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-ce6a750fbce4c4bfa60b1845cdd92c08be0c2ed1fdcecdcb2a2efa24170efabd
https://github.com/modelcontextprotocol/python-sdk/pull/3064/files#diff-ce6a750fbce4c4bfa60b1845cdd92c08be0c2ed1fdcecdcb2a2efa24170efabd
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3064/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.