René's URL Explorer Experiment


Title: fix(oauth): narrow context.lock scope in async_auth_flow (rebase of #2660 by @peisuke, closes #2847) by Bartok9 · Pull Request #2858 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: fix(oauth): narrow context.lock scope in async_auth_flow (rebase of #2660 by @peisuke, closes #2847) by Bartok9 · Pull Request #2858 · modelcontextprotocol/python-sdk

X Title: fix(oauth): narrow context.lock scope in async_auth_flow (rebase of #2660 by @peisuke, closes #2847) by Bartok9 · Pull Request #2858 · modelcontextprotocol/python-sdk

Description: Summary Conflict-free salvage of #2660 by @peisuke onto current main, opened as a fresh, mergeable PR so the fix can land without waiting on the original draft to be un-conflicted. All credit for the fix goes to @peisuke — the commit is authored by them; I only resolved the rebase against main and squashed to a single commit. Closes #2847. Addresses the same RuntimeError: The current task is not holding this lock reported in #2644 and #2847. Why a new PR #2660 has been a CONFLICTING draft since May 22 with no maintainer review. Issue #2847 (June 12) is a second, independent production repro of the exact bug, and the reporter explicitly asks for #2660 to be reviewed/merged. Rather than let the fix keep sitting, this PR provides a ready-to-merge version. If maintainers prefer to merge #2660 directly, or @peisuke wants to push the rebase themselves, this PR can be closed — the goal is just to unblock the fix. The bug OAuthContext.lock is an anyio.Lock, which records task identity at acquire() and enforces same-task release(). async_auth_flow holds this lock across yield points. When httpx drives the generator from a different task during concurrent OAuth connections (e.g. Notion's frequent token refresh behind a gateway), release() raises RuntimeError: The current task is not holding this lock. The fix (@peisuke's approach) Narrow the lock scope so no HTTP yield (including the long-poll GET SSE and the token-refresh round trips) runs while holding context.lock, plus a single-flight refresh_lock with a re-check under the lock. Keeps trio portability (unlike swapping to asyncio.Lock). Verification Rebased onto current main. Single commit (authored by @peisuke), touches only src/mcp/client/auth/oauth2.py and tests/client/test_auth.py (+348/-18). $ uv run pytest tests/client/test_auth.py -q 131 passed, 1 xfailed $ uv run ruff check src/mcp/client/auth/oauth2.py tests/client/test_auth.py All checks passed!

Open Graph Description: Summary Conflict-free salvage of #2660 by @peisuke onto current main, opened as a fresh, mergeable PR so the fix can land without waiting on the original draft to be un-conflicted. All credit for t...

X Description: Summary Conflict-free salvage of #2660 by @peisuke onto current main, opened as a fresh, mergeable PR so the fix can land without waiting on the original draft to be un-conflicted. All credit for t...

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

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:0d66d8c9-426a-b2b2-98b9-51efbc7a1963
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA95A:2E7EBB:17480E1:1D743AD:6B013557
html-safe-nonce5d29f460b16896676ff187d63a78077e566a7901cdd9847cdeb65c7e5ceb769e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTVBOjJFN0VCQjoxNzQ4MEUxOjFENzQzQUQ6NkIwMTM1NTciLCJ2aXNpdG9yX2lkIjoiMjczOTQ3NzM0Nzg3MDQ0Njk1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac573b49de95a5a3132258d69d1d9600132adfa81e5d1c5844ce0189add42cebde
hovercard-subject-tagpull_request:3860121384
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/2858/files
twitter:imagehttps://avatars.githubusercontent.com/u/259807879?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/259807879?s=400&v=4
og:image:altSummary Conflict-free salvage of #2660 by @peisuke onto current main, opened as a fresh, mergeable PR so the fix can land without waiting on the original draft to be un-conflicted. All credit for t...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/2858/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F2858%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%2F2858%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/2858/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2858/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2858/files
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues315 (315)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
Bartok9https://github.com/Bartok9
modelcontextprotocol:mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
Bartok9:salvage/2660-oauth-lock-rebasehttps://github.com/Bartok9/python-sdk/tree/salvage/2660-oauth-lock-rebase
Conversation 10 https://github.com/modelcontextprotocol/python-sdk/pull/2858
Commits 6 https://github.com/modelcontextprotocol/python-sdk/pull/2858/commits
Checks 29 https://github.com/modelcontextprotocol/python-sdk/pull/2858/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/2858/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2858/files
fix(oauth): narrow context.lock scope in async_auth_flow (rebase of #2660 by @peisuke, closes #2847) https://github.com/modelcontextprotocol/python-sdk/pull/2858/files#top
Show all changes 6 commits https://github.com/modelcontextprotocol/python-sdk/pull/2858/files
742290b fix(oauth): release context.lock around the primary request Bartok9 Oct 19, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2858/commits/742290ba72114e98fe522afaf6c59c2931e02738
fc80795 fix(oauth): keep the auth flow under the complexity limit Bartok9 Oct 19, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2858/commits/fc80795ca737864bcbf4a7bd2931a23343f3d623
fc0517f style(oauth): format the step-up scope check Bartok9 Oct 19, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2858/commits/fc0517fe98668a2783652d7e0bc49ecbe246881d
aabc009 test(oauth): cover refresh success, failure, and a skipped re-check Bartok9 Oct 19, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2858/commits/aabc0098bfa525e2001a22be6eb203a351fcbea5
c550173 fix(oauth): keep the challenged request's login on its own clock Bartok9 Oct 19, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2858/commits/c550173cfa25dc1208a33c4387ed18aa87ebdac5
5cb9f2d test(oauth): cover both arms of the refresh-lock stand-in Bartok9 Oct 19, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2858/commits/5cb9f2db588af3bfed07b1e772f66afe20768b60
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/2858/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2858/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2858/files
oauth2.py https://github.com/modelcontextprotocol/python-sdk/pull/2858/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
test_auth.py https://github.com/modelcontextprotocol/python-sdk/pull/2858/files#diff-f083d075f463e8b1ecfa6b931c33288c3d09b00ee3af3e5f74df16b7e75c3ab1
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2858/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2858/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.