Skip to content

Make reactive MCP OAuth refreshes cancellation-safe - #60981

Merged
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/f52da37d82baf89abcb1585e8e24359de53d40d7
Nov 12, 2026
Merged

copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/f52da37d82baf89abcb1585e8e24359de53d40d7

Conversation

@copyberry

@copyberry copyberry Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Make reactive MCP OAuth refreshes cancellation-safe

Why

Cancelling an MCP HTTP request during a reactive OAuth refresh must not interrupt persistence of rotated credentials. Concurrent requests receiving a 401 also need to reuse a fresh replacement token without refreshing it again.

What changed

  • Route authenticated streamable HTTP requests through OAuthRuntime, giving token exchanges independent tasks that finish persistence even if the caller is cancelled.
  • Serialize refreshes in both legacy and coordinated modes, recheck the rejected token and replacement expiry, and persist legacy credentials before releasing the manager lock.
  • Keep requests waiting to start an exchange cancellable, and use cached access credentials for session cleanup without refreshing tokens.

Testing

Add coverage for reactive refresh cancellation and rotated refresh-token persistence in both modes, concurrent refreshes with fresh or expired replacements, cancelled waiters, and legacy credentials with only a relative expiry.

## Why

Cancelling an MCP HTTP request during a reactive OAuth refresh must not interrupt persistence of rotated credentials. Concurrent requests receiving a `401` also need to reuse a fresh replacement token without refreshing it again.

## What changed

- Route authenticated streamable HTTP requests through `OAuthRuntime`, giving token exchanges independent tasks that finish persistence even if the caller is cancelled.
- Serialize refreshes in both legacy and coordinated modes, recheck the rejected token and replacement expiry, and persist legacy credentials before releasing the manager lock.
- Keep requests waiting to start an exchange cancellable, and use cached access credentials for session cleanup without refreshing tokens.

## Testing

Add coverage for reactive refresh cancellation and rotated refresh-token persistence in both modes, concurrent refreshes with fresh or expired replacements, cancelled waiters, and legacy credentials with only a relative expiry.

GitOrigin-RevId: f52da37d82baf89abcb1585e8e24359de53d40d7
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/f52da37d82baf89abcb1585e8e24359de53d40d7 branch from 7409c57 to 6bfdc75 Compare November 12, 2026 02:54
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor
Codex Review Summary: 🔄 Running

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-11-12T02:54:17.176010Z 7409c57 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@copyberry
copyberry Bot merged commit 6bfdc75 into main Nov 12, 2026
9 of 24 checks passed
@copyberry
copyberry Bot deleted the copyberry/codex-internal-to-codex-oss/f52da37d82baf89abcb1585e8e24359de53d40d7 branch November 12, 2026 02:54
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026

This branch was previously deployed

1 inactive deployment
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.

9 participants