Skip to content

Route MCP OAuth recovery through Codex#30294

Open
stevenlee-oai wants to merge 8 commits into
dev/stevenlee/mcp-oauth-independent-3-refresh-transactionfrom
dev/stevenlee/mcp-oauth-independent-3-transport-recovery
Open

Route MCP OAuth recovery through Codex#30294
stevenlee-oai wants to merge 8 commits into
dev/stevenlee/mcp-oauth-independent-3-refresh-transactionfrom
dev/stevenlee/mcp-oauth-independent-3-transport-recovery

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 4.

Why

Serializing preflight refresh is not enough if RMCP can refresh independently or if RMCP-owned HTTP traffic bypasses Codex recovery. SSE reconnect GETs, session DELETEs, and responses to server-initiated requests need the same Codex-owned policy as public MCP operations.

What this PR does

  • Gives RMCP request-only credentials: no refresh token or expiry metadata is exposed outside Codex's credential transaction.
  • Wraps RMCP's Streamable HTTP client so Codex applies proactive refresh and at most one 401 recovery to RMCP-owned GET/reconnect, DELETE, and server-response POST traffic.
  • Keeps client-originated POST recovery in the outer RmcpClient, where caller deadlines and replay decisions are known.
  • Captures the access token actually sent with a rejected request. A delayed 401 for A after another request installs B adopts and retries B instead of refreshing B again.
  • Bounds a caller's wait for 401 recovery by that operation's remaining deadline. Timing out the wait does not cancel the already-owned refresh transaction; it may still persist B for the next request.
  • Reuses the lifecycle-pinned recipe across initialization retries and transport reconstruction.
  • Preserves the rejected token only for first-401 attribution; if the one allowed retry is also rejected, converts it to the established authentication-required result.
  • Composes one OAuth recovery and one session recovery in either arrival order, without allowing either retry to loop.
  • Keeps static bearer-token 401 challenges on the existing authentication-required path; rejected-token attribution is enabled only for a Codex-owned OAuth lifecycle.
  • Preserves authentication-required and token-expired markers across the RMCP-owned transport wrapper.

Explicit decisions

  • RMCP remains the transport and bearer-injection layer; Codex exclusively owns refresh policy.
  • A refresh transaction may complete after a caller deadline, but a request is retried only if that caller still has time remaining.
  • Every transport path gets at most one 401 retry; non-auth failures keep their existing behavior.

Safe stopping point

After this PR, Codex owns refresh and one-shot 401 recovery for every Streamable HTTP path. Login and logout can still race with refresh until layer 5.

Validation

  • just test -p codex-rmcp-client (112 passed; expected environment skips)
  • End-to-end delayed concurrent 401 and internal GET/POST/DELETE recovery coverage
  • Startup, public-operation, and RMCP-owned-transport coverage for a rejected post-refresh retry
  • Session-expiry-then-401 composition and static-bearer authentication-required coverage
  • Caller-timeout coverage proving the owned transaction can finish for the next request

@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: e4527fd978

ℹ️ 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
@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-3-transport-recovery branch from e4527fd to 0135226 Compare June 26, 2026 21:30
@stevenlee-oai stevenlee-oai force-pushed the dev/stevenlee/mcp-oauth-independent-2-refresh-transaction branch from 38b9e10 to c003752 Compare June 26, 2026 21:48
@stevenlee-oai stevenlee-oai force-pushed the dev/stevenlee/mcp-oauth-independent-3-transport-recovery branch from 0135226 to fc3ba8b Compare June 26, 2026 21:48
@stevenlee-oai stevenlee-oai force-pushed the dev/stevenlee/mcp-oauth-independent-2-refresh-transaction branch from c003752 to c93f236 Compare June 26, 2026 22:25
@stevenlee-oai stevenlee-oai force-pushed the dev/stevenlee/mcp-oauth-independent-3-transport-recovery branch from fc3ba8b to 5eaa4d4 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. Hooray!

Reviewed commit: 5eaa4d4506

ℹ️ 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. Breezy!

Reviewed commit: d5b91df49e

ℹ️ 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

[from Codex] Test-only follow-up: the timeout test now explicitly accepts the two valid request-count outcomes around completion of the owned refresh task, while retaining exact one-provider-refresh and refreshed-token expectations.

@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: 8d9e34b357

ℹ️ 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/http_client_adapter.rs Outdated
…on' into dev/stevenlee/mcp-oauth-independent-3-transport-recovery

# Conflicts:
#	codex-rs/rmcp-client/src/oauth.rs
#	codex-rs/rmcp-client/src/oauth/refresh_transaction.rs
#	codex-rs/rmcp-client/src/rmcp_client.rs
#	codex-rs/rmcp-client/src/streamable_http_retry.rs
@stevenlee-oai stevenlee-oai changed the base branch from dev/stevenlee/mcp-oauth-independent-2-refresh-transaction to dev/stevenlee/mcp-oauth-independent-3-refresh-transaction June 28, 2026 07:10
@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

@codex review

— Codex

@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: a0c55f29f1

ℹ️ 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/streamable_http_retry.rs
Comment thread codex-rs/rmcp-client/src/http_client_adapter.rs Outdated
@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

@codex review

— Codex

@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: 73e4bbcd7c

ℹ️ 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_transport.rs
Comment thread codex-rs/rmcp-client/src/http_client_adapter.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. What shall we delve into next?

Reviewed commit: 4d735e681a

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant