[codex] Serialize MCP OAuth credential refreshes#347
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors OAuth token management by introducing cross-process file locking during token operations and implementing a transactional refresh mechanism to prevent replaying stale rotating tokens. It also updates the client to handle unauthorized errors with OAuth recovery. Feedback on the changes highlights critical compilation issues in oauth.rs due to the use of non-existent try_lock methods on std::fs::File, as well as potential thread starvation risks from calling blocking synchronous I/O and std::thread::sleep directly within async functions.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
Upstream-harvest refresh before landing:
Current downstream adoption choice: keep this PR as a downstream port/review surface for the upstream-in-flight architecture rather than waiting for the full upstream stack to merge, because the local MCP login/restart path is already user-visible broken. Fresh validation after formatter repair commit
|
|
Resolving the remaining Gemini review threads after the base-update validation pass:
Given the fresh green checks and the upstream OpenAI stack using the same architectural direction, I’m resolving those threads so branch protection can evaluate the already-validated fix. |
Summary
CODEX_HOME.Auth requiredduring initialize/operation paths.Root cause
A completed MCP OAuth login could leave a usable-looking credential record while another Codex/RMCP client path still relied on stale in-memory access-token state or independently attempted refresh/persistence. After restart, Codex could then report that the server was not logged in even though the login flow appeared to complete.
This change centralizes refresh ownership in Codex and makes refresh/write paths lock and reread the authoritative store before mutating it.
Validation
9dc2b7f54ed0d9f133dd4b7627a6f007452a752c: https://github.com/sednalabs/codex/actions/runs/27863218322codex.mcp-device-login-targeted,codex.mcp-safety-targetedgit diff --checkDraft because this touches shared MCP OAuth client behavior and should get maintainer review before merge.