Skip to content

Resolve and pin MCP OAuth credential stores - #30293

Merged
stevenlee-oai merged 4 commits into
mainfrom
dev/stevenlee/mcp-oauth-independent-2-refresh-transaction
Jul 9, 2026
Merged

Resolve and pin MCP OAuth credential stores#30293
stevenlee-oai merged 4 commits into
mainfrom
dev/stevenlee/mcp-oauth-independent-2-refresh-transaction

Conversation

@stevenlee-oai

@stevenlee-oai stevenlee-oai commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Codex Thread 019edd6d-6f14-74e2-853c-345d1803d4a6

Stack

Review and merge in order. Every layer is independently correct and documents its safe stopping point.

  1. openai/codex#30292 — aggregate File/Secrets store locking
  2. openai/codex#30293 — resolve and lifecycle-pin the exact OAuth store
  3. openai/codex#30416 — serialized authoritative refresh transaction
  4. openai/codex#30294 — Codex-owned transport refresh and one-shot 401 recovery
  5. openai/codex#30295 — login/logout transaction serialization
  6. openai/codex#30296 — diagnostic-only Auto store drift reporting

This PR is layer 2.

Why

Auto is keyring-first with a File fallback, but re-evaluating that policy during transport reconstruction or persistence can make one MCP client read from one store and later write to another. With rotating refresh tokens, the second store may contain an older token. This layer makes the source selected at client startup explicit and keeps that authority stable for the client lifecycle.

What this PR does

  • Keeps resolve_oauth_tokens_from_store_policy as the single configured-policy entry point and returns both credentials and the concrete File or Keyring source that supplied them.
  • Puts exact load, save, and delete operations on ResolvedOAuthCredentialStore, making “resolve configured policy” and “use the selected authority” distinct at call sites.
  • Pins the first concrete source in pinned_credential_store in the transport recipe, so initialization retries and session reconstruction cannot re-evaluate Auto and adopt another store.
  • Gives OAuthPersistor the resolved store and keeps subsequent persistence and removal on that authority.
  • Uses a typed keyring-load error to distinguish aggregate-store coordination failures from ordinary backend failures; a coordination failure is surfaced instead of triggering File fallback.
  • Keeps login-time Auto behavior unchanged: prefer Keyring, fall back to File when unavailable, and clean up legacy File state after a successful keyring save.
  • Adds structured server/backend context when fallback cleanup fails.

Explicit decisions and non-goals

  • The selection is lifecycle-local and in memory. This PR does not add a durable backend selector, migration, reconciliation registry, or global source of truth outside CODEX_HOME.
  • Auto may choose File at the start of a later process if keyring availability changes. Once this client resolves, a selected-store failure is returned instead of hot-switching.
  • Different CODEX_HOME instances remain independent even when they can access the same Direct keyring credential.
  • Cross-process refresh serialization is intentionally not part of this layer.

Safe stopping point

This PR can merge alone. A single MCP client no longer hot-switches credential stores across transport rebuilds or persistence. Two processes can still refresh the same selected credential concurrently until layer 3.

Review size

The net layer is 9 files, +668/−144. The production change remains focused on store resolution and lifecycle pinning; the largest follow-up is integration coverage that drives real session recovery.

Validation

  • just test -p codex-rmcp-client (99 passed; 5 expected skips)
  • Real-client 404 recovery coverage with different Keyring and File tokens; captured bearer headers prove the stale File token is never sent
  • Mutation check: removing the lifecycle pin makes that integration regression fail by observing the stale File token

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c432fcdffc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/rmcp-client/src/oauth/refresh_transaction.rs Outdated
@stevenlee-oai
stevenlee-oai force-pushed the dev/stevenlee/mcp-oauth-independent-2-refresh-transaction branch from c432fcd to 38b9e10 Compare June 26, 2026 21:30
@stevenlee-oai
stevenlee-oai force-pushed the dev/stevenlee/mcp-oauth-independent-1-store-locks branch 2 times, most recently from c99bdc7 to e4dcca6 Compare June 26, 2026 21:48
@stevenlee-oai
stevenlee-oai force-pushed the dev/stevenlee/mcp-oauth-independent-2-refresh-transaction branch 2 times, most recently from c003752 to c93f236 Compare June 26, 2026 22:25
@stevenlee-oai
stevenlee-oai force-pushed the dev/stevenlee/mcp-oauth-independent-1-store-locks branch from e4dcca6 to f1e1c17 Compare June 26, 2026 22:25
@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: c93f2368a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 2722bf8ad5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

@codex review

— Codex

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: fb2c35f05a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

stevenlee-oai added a commit that referenced this pull request Jul 7, 2026
[Codex Thread
019edd6d-6f14-74e2-853c-345d1803d4a6](https://codex-thread-link.openai.chatgpt-team.site/thread/019edd6d-6f14-74e2-853c-345d1803d4a6)

## Stack

Review and merge in order. Every layer is independently correct and
documents its safe stopping point.

1. [#30292](#30292) —
aggregate File/Secrets store locking
2. [#30293](#30293) —
resolve and lifecycle-pin the exact OAuth store
3. [#30416](#30416) —
serialized authoritative refresh transaction
4. [#30294](#30294) —
Codex-owned transport refresh and one-shot 401 recovery
5. [#30295](#30295) —
login/logout transaction serialization
6. [#30296](#30296) —
diagnostic-only Auto store drift reporting

**This PR is layer 1.**

## Why

MCP OAuth credentials stored in File or Secrets share one aggregate map.
Concurrent read-modify-write operations for different MCP servers can
both read the same snapshot and let the later write discard the earlier
update. That is a correctness problem independent of refresh-token
rotation.

## What this PR does

- Adds a bounded cross-process lock around aggregate File and Secrets
loads, saves, and deletes.
- Distinguishes aggregate-lock failures from Secrets backend
unavailability, so Auto can fall back only for the latter and cannot
bypass serialization by reading or writing File.
- Keeps Direct keyring operations outside this lock because they are
already per credential.
- Releases the Secrets aggregate lock before legacy File cleanup so
cross-store cleanup cannot create nested aggregate-lock ordering.
- Tests actual contention by waiting for an observed `WouldBlock`,
rather than assuming a sleeping worker reached the lock.
- Tests load and save with only the Secrets lock path broken while
fallback File remains readable and writable.

## Decisions and non-goals

- This lock protects aggregate-store read-modify-write integrity only.
It does not choose a credential authority or serialize an OAuth refresh
transaction.
- The lock is scoped to the active `CODEX_HOME`, matching the aggregate
files it protects.
- Lock waits are bounded, and coordination failures are surfaced rather
than treated as evidence that Secrets is unavailable.

## Safe stopping point

This PR can merge alone. It prevents lost updates and partial aggregate
reads. Auto can still resolve again during a client lifecycle until
layer 2, and concurrent refreshes remain possible until layer 3.

## Validation

- `just test -p codex-rmcp-client` (96 passed; expected environment
skips)
- Focused aggregate File/Secrets lock contention and Auto fallback tests
Base automatically changed from dev/stevenlee/mcp-oauth-independent-1-store-locks to main July 7, 2026 04:03
@stevenlee-oai
stevenlee-oai force-pushed the dev/stevenlee/mcp-oauth-independent-2-refresh-transaction branch from fb2c35f to e5dc9f3 Compare July 7, 2026 04:30
@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e5dc9f3632

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/rmcp-client/src/rmcp_client.rs Outdated
Comment thread codex-rs/rmcp-client/src/oauth.rs Outdated
Comment thread codex-rs/rmcp-client/src/oauth.rs Outdated
Comment thread codex-rs/rmcp-client/src/oauth/resolved_store.rs Outdated
Comment thread codex-rs/rmcp-client/src/oauth/resolved_store.rs Outdated
Comment thread codex-rs/rmcp-client/src/rmcp_client.rs Outdated
Comment thread codex-rs/rmcp-client/src/rmcp_client.rs Outdated
@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

@codex review

— Codex

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: f538e9d731

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

@codex review

— Codex

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: d493019b6d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@stevenlee-oai
stevenlee-oai enabled auto-merge (squash) July 9, 2026 07:00
@stevenlee-oai
stevenlee-oai disabled auto-merge July 9, 2026 07:00
@stevenlee-oai
stevenlee-oai merged commit cbdee79 into main Jul 9, 2026
64 of 66 checks passed
@stevenlee-oai
stevenlee-oai deleted the dev/stevenlee/mcp-oauth-independent-2-refresh-transaction branch July 9, 2026 22:46
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants