Repository navigation
fix(mcp-oauth): avoid locking across resource requests - #97458
Merged
Merged
Conversation
helix4u
marked this pull request as ready for review
August 28, 2026 21:13
This was referenced Aug 29, 2026
13 of 19 tasks
andrexibiza
added a commit
to andrexibiza/hermes-agent
that referenced
this pull request
Sep 11, 2026
Rematerialize the credited NousResearch#84963 lifecycle remainder on current main (bf51fee): - compose NousResearch#90888's owner-task teardown contract into current main's async_auth_flow: close-once inner-generator teardown under a shielded CancelScope, NousResearch#97458 semaphore rebalancing on every cancellation path, primary-error precedence (cleanup failures attach notes instead of masking the real OAuth error) - carry tests/tools/test_mcp_oauth_lifecycle_owner.py (task-bound teardown, close-once, cancellation shielding, semaphore balance) - credit Igor Verhun (igorhvr) in contributors/emails Zero-file overlap with main's movement since base 4209d37.
3 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
MCP SDK 2.0.0 holds one task-owned OAuth context lock across the entire HTTPX auth-flow generator. A session-long Streamable HTTP GET can therefore hold the lock indefinitely and prevent concurrent schema or tool POST requests from authenticating.
This keeps the SDK's existing OAuth state machine intact while replacing its task-owned lock with a binary semaphore and releasing that semaphore only while the actual MCP resource request is in flight. OAuth initialization, refresh, discovery, registration, and token exchange remain serialized. If another request refreshes the token while a resource request is pending, a stale 401 or 403 now retries with the new token instead of starting another OAuth transition.
This is the narrow lock-scope complement to the auth-flow cleanup work in #90888 and the stale-connection retry work in #91460. It follows the concurrency model proposed upstream in modelcontextprotocol/python-sdk#3243 without copying the SDK's full 401/403 implementation into Hermes.
Related Issue
Related: modelcontextprotocol/python-sdk#1326
Type of Change
Changes Made
How to Test
Focused test command:
scripts/run_tests.sh tests/tools/test_mcp_oauth_bidirectional.py tests/tools/test_mcp_oauth_manager.py -q -j 4Result: 17 passed.
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass. Full-suite coverage is left to GitHub CI; the focused tests above pass.Documentation & Housekeeping
docs/, docstrings) — N/A; behavior is covered by code comments and regression testscli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AScreenshots / Logs
Not applicable. The regression is covered by the focused async OAuth tests above.