René's URL Explorer Experiment


Title: Buffer per-request StreamableHTTP streams to avoid serial-router head-of-line block by maxisbey · Pull Request #2934 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Buffer per-request StreamableHTTP streams to avoid serial-router head-of-line block by maxisbey · Pull Request #2934 · modelcontextprotocol/python-sdk

X Title: Buffer per-request StreamableHTTP streams to avoid serial-router head-of-line block by maxisbey · Pull Request #2934 · modelcontextprotocol/python-sdk

Description: Two related fixes to the stateful StreamableHTTPServerTransport so concurrent requests can't wedge each other and event-store ordering doesn't depend on scheduler timing. Buffer the per-request _request_streams (head-of-line block). Each POST registers a buffer-0 _request_streams[id] channel, start_soons the EventSourceResponse, and pushes the request to the server. The single serial message_router then forwards each response with await _request_streams[id][0].send(...) — which on a buffer-0 stream parks until that request's sse_writer (started lazily, two start_soon hops deep) has reached its first receive(). While the router is parked on one request, every other in-flight response on the session is head-of-line blocked behind it. This gives the three _request_streams[EventMessage] sites a small bounded buffer (REQUEST_STREAM_BUFFER_SIZE = 16) so the router can deposit and move on. The downstream sse_stream dict streams stay at 0 — they're not on the router's send target. Store the priming event before request dispatch (event-store ordering). With an event_store configured, message_router calls store_event(msg) before its send(), while the priming event was stored inside the lazily-started sse_writer — so its event-store position raced the first routed message. Splitting the helper into _mint_priming_event (store + return wire dict) and _run_sse_writer (forward onto the wire) lets the POST handler await _mint_priming_event(...) before writer.send(session_message). The server can't emit anything for a request it hasn't received, so the priming row now precedes every router store for that stream by data dependency rather than scheduler timing — the same shape the TypeScript SDK uses. Motivation and Context Fixes #1764. The natural race is hard to reproduce standalone (multiple parties report 0 hits across thousands of loopback iterations) but is observed consistently in production by several reporters on the issue. The unit-level head-of-line block is straightforward to demonstrate though: register two request streams, give B a consumer, leave A consumer-less, write responses A then B — on main B never arrives until A is closed; with this change B arrives immediately and A's response is buffered. The priming-order fix addresses a review finding that the buffer change widened a pre-existing window where a routed message could be stored before the priming event. How Has This Been Tested? New tests/server/test_streamable_http_router.py drives the routing layer directly: one test for the head-of-line block, one asserting [priming, m₁, …, m₅] event-store order with no sse_writer ever scheduled. tests/shared/test_streamable_http.py priming-helper unit tests updated for _mint_priming_event. Existing reconnection / sse-polling / replay tests pass unchanged. Breaking Changes None. EventStore ABC is unchanged. Intentional behaviour changes: The standalone GET stream now buffers up to 16 server-initiated messages before backpressure engages on a slow GET client (was 0). A request whose consumer stalls past 16 messages (e.g. a long-running tool emitting many progress notifications to a stalled SSE client) can still wedge the router — this moves the threshold from 0 to 16, it doesn't remove the serial router. The routerless design in _streamable_http_modern.py is the structural fix on main. _maybe_send_priming_event is replaced by _mint_priming_event (returns the wire dict instead of sending) and _run_sse_writer. Both are private; no public surface change. The replay path's priming/live-tail ordering window is pre-existing and unchanged here; tracked separately. Types of changes Bug fix (non-breaking change which fixes an issue) New feature (non-breaking change which adds functionality) Breaking change (fix or feature that would cause existing functionality to change) Documentation update 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 Additional context The buffer-size approach matches what reporters on #1764 have field-validated (sed-patching to 10). 16 covers the reported single-response list-request case by construction (one message per id) plus headroom for small notification workloads, while staying bounded for the session-lifetime GET stream. A separate change is needed for the stateless task-leak half of #1764 (#2145's request-scoped task-group approach); that's not bundled here. AI Disclaimer

Open Graph Description: Two related fixes to the stateful StreamableHTTPServerTransport so concurrent requests can't wedge each other and event-store ordering doesn't depend on scheduler timing. Buffer the per-req...

X Description: Two related fixes to the stateful StreamableHTTPServerTransport so concurrent requests can't wedge each other and event-store ordering doesn't depend on scheduler timing. Buffer the...

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

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:c3e2e39d-d034-dfba-7e12-1e7a3358a0a8
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE4F4:2CFBF7:1B65CA5:264846E:6AFD0AD2
html-safe-nonceb86df3ffdf0815546830fb713fc087af26b741c124c1b31eb5d908faa7ce0391
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNEY0OjJDRkJGNzoxQjY1Q0E1OjI2NDg0NkU6NkFGRDBBRDIiLCJ2aXNpdG9yX2lkIjoiMTA0OTk3NTI1OTE5MDMzMjExNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac1d0b6de2c7dccbff00561234de11db3b34e31798d24e618adda3a4738c3d330c
hovercard-subject-tagpull_request:3904579047
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/2934/files
twitter:imagehttps://avatars.githubusercontent.com/u/224885523?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/224885523?s=400&v=4
og:image:altTwo related fixes to the stateful StreamableHTTPServerTransport so concurrent requests can't wedge each other and event-store ordering doesn't depend on scheduler timing. Buffer the per-req...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb29de2abb97b6307b16270785efeb58b51a117d5a9b659acf00b77aa00e7043b
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
release8c9e619def6d670dc18a45d3b02cea938c1c7e47
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F2934%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F2934%2Ffiles
Sign uphttps://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/2934/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues305 (305)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
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
maxisbeyhttps://github.com/maxisbey
mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
fix/streamable-http-hol-bufferhttps://github.com/modelcontextprotocol/python-sdk/tree/fix/streamable-http-hol-buffer
Conversation 6 https://github.com/modelcontextprotocol/python-sdk/pull/2934
Commits 6 https://github.com/modelcontextprotocol/python-sdk/pull/2934/commits
Checks 33 https://github.com/modelcontextprotocol/python-sdk/pull/2934/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/2934/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files
Buffer per-request StreamableHTTP streams to avoid serial-router head-of-line block https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#top
Show all changes 6 commits https://github.com/modelcontextprotocol/python-sdk/pull/2934/files
b0b398c Buffer per-request StreamableHTTP streams to avoid serial-router head… maxisbey Jun 20, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2934/commits/b0b398c934ea1bbdadfe4725ccca6f708a6a96c0
dde2df9 Store priming event before request dispatch so storage order == wire … maxisbey Jun 20, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2934/commits/dde2df983e9b4550ac89a9bbbd13e12c5cdcbba4
127b209 Mint priming before per-request state; cover old-pv replay path maxisbey Jun 20, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2934/commits/127b20942f73ca54d72b15865b150525b3ce9721
1f1cb48 replay_sender finally + replace _mint_priming_event unit tests with e… maxisbey Jun 22, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2934/commits/1f1cb4813b675afb5e845018bfb8998261018e76
ac6cc7d Generic 500 body in outer POST except; make leak-test assertion load-… maxisbey Jun 22, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2934/commits/ac6cc7df8c9942ae987154880549fbb8ccbab07b
45fcc1f Drop tautological priming-order unit test; cover retry_interval-None … maxisbey Jun 22, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2934/commits/45fcc1fb0914db86197a377bcf2d3479d9a52888
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/2934/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files
streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
test_hosting_resume.py https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-85f9daa9bed5aaa4f0692a68b218329bd1d04c2bc0d72d270799730e3e7dfa22
test_streamable_http_router.py https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-19d95b11a9e1249b7955143f91e9e2f482f5b09493dc88875c57b3ee08d58c08
test_streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
src/mcp/server/streamable_http.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
View file https://github.com/modelcontextprotocol/python-sdk/blob/45fcc1fb0914db86197a377bcf2d3479d9a52888/src/mcp/server/streamable_http.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2934/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/checks?check_run_id=82739853130
claudehttps://github.com/apps/claude
Jun 22, 2026https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#r3451945120
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files
claudehttps://github.com/apps/claude
Jun 22, 2026https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#r3453366131
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
#1764https://github.com/modelcontextprotocol/python-sdk/issues/1764
#1764https://github.com/modelcontextprotocol/python-sdk/issues/1764
#1764https://github.com/modelcontextprotocol/python-sdk/issues/1764
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
claudehttps://github.com/apps/claude
Jun 22, 2026https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#r3452582364
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
tests/interaction/transports/test_hosting_resume.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-85f9daa9bed5aaa4f0692a68b218329bd1d04c2bc0d72d270799730e3e7dfa22
View file https://github.com/modelcontextprotocol/python-sdk/blob/45fcc1fb0914db86197a377bcf2d3479d9a52888/tests/interaction/transports/test_hosting_resume.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2934/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-85f9daa9bed5aaa4f0692a68b218329bd1d04c2bc0d72d270799730e3e7dfa22
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-85f9daa9bed5aaa4f0692a68b218329bd1d04c2bc0d72d270799730e3e7dfa22
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-85f9daa9bed5aaa4f0692a68b218329bd1d04c2bc0d72d270799730e3e7dfa22
https://github.com/modelcontextprotocol/python-sdk/pull/2934/files#diff-85f9daa9bed5aaa4f0692a68b218329bd1d04c2bc0d72d270799730e3e7dfa22
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2934/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2934/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.