René's URL Explorer Experiment


Title: Deflake the session-level timeout test with trio's virtual clock by maxisbey · Pull Request #2788 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Deflake the session-level timeout test with trio's virtual clock by maxisbey · Pull Request #2788 · modelcontextprotocol/python-sdk

X Title: Deflake the session-level timeout test with trio's virtual clock by maxisbey · Pull Request #2788 · modelcontextprotocol/python-sdk

Description: test_session_level_timeout_applies_to_every_request flaked three times in its first week. This switches it to trio's virtual clock so it is deterministic by construction, with no real waiting. Motivation and Context The test sets Client(server, read_timeout_seconds=0.05). A session-level read timeout applies to every request that doesn't set its own — including the InitializeRequest sent inside Client.__aenter__ — so the in-process handshake had to beat 50ms of real clock before the test body even ran. Under CI load it sometimes didn't, and the test died in __aenter__ with Timed out while waiting for response to InitializeRequest: 3.12, locked, ubuntu-latest (May 30) 3.12, locked, windows-latest (Jun 4) 3.12, locked, windows-latest (Jun 5) Looping the in-memory handshake on a CPU-saturated windows-latest runner (3.12, locked) puts its tail at p99 ≈ 70ms and max ≈ 190ms — 4.3% of handshakes exceeded 50ms; even idle, the max was 26ms. So the existing value was a standing bet against scheduler stalls, and any wider real-clock margin pays for itself in wall-clock time on every run. The file's other tests are deterministic because the timed request can never be answered (the handler blocks forever), so an effectively-zero timeout always wins. The session-default test can't use that trick: the same knob governs the handshake, which must succeed first. Running this one test on trio's MockClock(autojump_threshold=0) removes the bet instead of widening it. Virtual time only advances when every task is blocked: during the handshake some task is always runnable, so the handshake cannot time out no matter how slow the runner, and once the tool call blocks on the never-answered request the run goes idle and the clock jumps straight to the deadline. The timeout value and snapshot stay as they were; the file now runs in milliseconds. trio is already a dev dependency, and the per-test anyio_backend parametrization keeps the rest of the suite on asyncio. How Has This Been Tested? 500 iterations of the test shape under the MockClock via the pytest plugin path: identical outcome every time, ~1.1s of real time for 25s of virtual timeouts. 30 consecutive runs of the file, all green; full tests/interaction/ suite passes (529 tests, ~5s). Sanity-checked the failure mode is unchanged: a tiny real-clock timeout racing the handshake is not a viable alternative — on Windows 3.12, time.monotonic has 15.625ms granularity, so fail_after(1e-6) actually lets the handshake win most races (and 3.13+ switched to QPC, flipping the behavior). Virtual time sidesteps clock granularity entirely. Breaking Changes None — test-only. 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 Additional context All three flakes hit the 3.12/locked matrix cell. For the two Windows hits there's a plausible amplifier: on 3.12, asyncio's clock is GetTickCount64-based, so a 50ms deadline computed from a floor-quantized clock can fire up to ~15.6ms early in real time. The CI tracebacks above are also a live reproduction of #2114: the MCPError from the failed initialize surfaces from Client.__aenter__ double-wrapped in ExceptionGroups. AI Disclaimer

Open Graph Description: test_session_level_timeout_applies_to_every_request flaked three times in its first week. This switches it to trio's virtual clock so it is deterministic by construction, with no real waiting. ...

X Description: test_session_level_timeout_applies_to_every_request flaked three times in its first week. This switches it to trio's virtual clock so it is deterministic by construction, with no real waiti...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:811f8a55-1849-2b4b-d185-d1608b2019cc
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD102:195D56:6AD109:8A0CC7:6A5ACD2A
html-safe-nonce576d275ee6538744aaa9efeadf3fded1dff8e3202db23662f0a365d657d08736
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTAyOjE5NUQ1Njo2QUQxMDk6OEEwQ0M3OjZBNUFDRDJBIiwidmlzaXRvcl9pZCI6IjgxNDI2OTAyNTE4NjM0MTIwMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac29c1173e5da3e020aa766babb8ef5c28a649f8cad847d74f7861c272415d8933
hovercard-subject-tagpull_request:3812673797
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/2788/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:alttest_session_level_timeout_applies_to_every_request flaked three times in its first week. This switches it to trio's virtual clock so it is deterministic by construction, with no real waiting. ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None887a0902ea4987c46dd44cbc73dfadecb93a29560d7519a576fcecd81716148c
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
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release2606513ce6b72f8b775db6a60283f9cf7d4d70a5
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/2788/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F2788%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%2F2788%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/2788/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2788/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2788/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2788/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.6k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 258 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 301 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
maxisbeyhttps://github.com/maxisbey
mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
maxisbey/deflake-session-timeout-testhttps://github.com/modelcontextprotocol/python-sdk/tree/maxisbey/deflake-session-timeout-test
Conversation 2 https://github.com/modelcontextprotocol/python-sdk/pull/2788
Commits 1 https://github.com/modelcontextprotocol/python-sdk/pull/2788/commits
Checks 34 https://github.com/modelcontextprotocol/python-sdk/pull/2788/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/2788/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2788/files
Deflake the session-level timeout test with trio's virtual clock https://github.com/modelcontextprotocol/python-sdk/pull/2788/files#top
Show all changes 1 commit https://github.com/modelcontextprotocol/python-sdk/pull/2788/files
7b77f4a Run the session-level timeout test on trio's virtual clock maxisbey Jun 5, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2788/commits/7b77f4a90d5bf35bbb5849b88246342a605ceded
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/2788/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2788/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2788/files
tests/interaction/lowlevel/test_timeouts.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2788/files#diff-72f06b25a7e212f804121ef810f403578c4acd67b76b86ccda04618012a9930d
View file https://github.com/modelcontextprotocol/python-sdk/blob/7b77f4a90d5bf35bbb5849b88246342a605ceded/tests/interaction/lowlevel/test_timeouts.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2788/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2788/files#diff-72f06b25a7e212f804121ef810f403578c4acd67b76b86ccda04618012a9930d
https://github.com/modelcontextprotocol/python-sdk/pull/2788/files#diff-72f06b25a7e212f804121ef810f403578c4acd67b76b86ccda04618012a9930d
https://github.com/modelcontextprotocol/python-sdk/pull/2788/checks?check_run_id=79807959945
claudehttps://github.com/apps/claude
Jun 5, 2026https://github.com/modelcontextprotocol/python-sdk/pull/2788/files#r3365360198
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2788/files
https://github.com/modelcontextprotocol/python-sdk/pull/2788/files#diff-72f06b25a7e212f804121ef810f403578c4acd67b76b86ccda04618012a9930d
https://github.com/modelcontextprotocol/python-sdk/pull/2788/files#diff-72f06b25a7e212f804121ef810f403578c4acd67b76b86ccda04618012a9930d
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2788/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.