[rmcp-client] Refresh OAuth credentials after invalid_token responses - #26522
Closed
anp-oai wants to merge 3 commits into
Closed
[rmcp-client] Refresh OAuth credentials after invalid_token responses#26522anp-oai wants to merge 3 commits into
anp-oai wants to merge 3 commits into
Conversation
Contributor
Author
|
handing this off for now |
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.
Intent
Recover only when an OAuth-backed MCP server rejects a Bearer access token with
invalid_tokenbefore its locally recorded expiry, without introducing general retries or replaying side-effecting tool calls.User-visible behavior
Before
An MCP server can revoke or otherwise reject an OAuth access token while Codex still considers it unexpired. When the server responds with a Bearer
invalid_tokenchallenge, initialization or a tool call fails without refreshing the credentials. The user may need to manually reconnect or log in again before the MCP server works.After
initializerequest receives Bearerinvalid_token, Codex force-refreshes the OAuth credentials, rebuilds the transport, and retries initialization once within the original timeout. A second rejection is returned without another retry.tools/callreceives Bearerinvalid_token, Codex refreshes the OAuth credentials but does not replay the potentially side-effecting tool call. The failed call returns a clear retry-required error, and the user's next call uses the refreshed token and can succeed.401responses keep their existingAuthRequiredbehavior and do not enter the OAuth refresh path.Concrete implementation
OAuthPersistorand classify only Bearerinvalid_tokenchallenges.initializerequest, force-refresh credentials, rebuild the OAuth transport, and retry exactly once within the original startup timeout.tools/call, perform at most one forced refresh for the failed operation, never replay the original call, and return a stable retry-required error.401exclusion, the second-401initialize retry cap, no tool replay, caller-issued retry success, and static-bearer semantics.Validation not covered by CI
just test -p codex-rmcp-client --test streamable_http_oauth_startup(9 passed)just test -p codex-rmcp-client --test streamable_http_recovery(7 passed)just test -p codex-rmcp-client --lib(53 passed)just fix -p codex-rmcp-clientjust fmtDeferred
notifications/initialized,tools/list, resources, and custom operations.401deduplication and every-operation recovery.