[Codex][Codex Auth] Handle stale managed auth refresh races before relogin#15127
[Codex][Codex Auth] Handle stale managed auth refresh races before relogin#15127
Conversation
There was a problem hiding this comment.
💡 Codex Review
codex/codex-rs/core/src/auth.rs
Lines 1158 to 1160 in 2f2ec13
reload_if_account_id_matches computes auth_changed against self.auth_cached() instead of the caller snapshot passed into reload_for_refresh. If another task already updated the cache, stale callers can get ReloadedNoChange; then refresh_if_stale uses the old refresh token and may hit avoidable refresh_token_reused relogin failures.
ℹ️ 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".
2cdf1e9 to
d3a092a
Compare
Port the stale managed auth reload and unauthorized recovery guards into codex-login after auth ownership moved out of codex-core. Keep guarded reload pinned to compatible account and user identity, preserve legacy no-account-id compatibility, and update cloud requirements expectations for the new recovery contract. Co-authored-by: Codex <noreply@openai.com>
d3a092a to
ab557f6
Compare
Deduplicate the repeated never-policy requirements fixture and auth recovery error string in cloud requirements tests without changing the exercised contract. Co-authored-by: Codex <noreply@openai.com>
Factor the repeated proactive auth fixture setup into a small helper and keep the remaining auth manager tests focused on the linear contract surface. Co-authored-by: Codex <noreply@openai.com>
|
Closing this out in favor of #15357, which landed the main proactive stale-auth fix on current This branch still contains additional auth-recovery/policy logic, but I don’t think we should stack that broader surface on top of the merged fix. If any of the remaining non-overlap still looks worthwhile, I’ll cut a much smaller follow-up from current |
CODEX-5156
Summary
auth()path.refresh_token_reusedfailure now does one final guarded reload before forcing relogin.account_idandchatgpt_user_idwhen an account boundary is known.account_idkeeps the old compatibility path instead of being stranded on stale credentials.Rationale (from spec findings)
refresh_token_reused.Scope
codex-rs/login/src/auth/manager.rs,codex-rs/login/src/auth/auth_tests.rs, and the two cloud-requirements expectations incodex-rs/cloud-requirements/src/lib.rs.chatgptAuthTokens, and cross-device auth divergence unchanged.Trade-offs
account_id, reload adoption now requires compatibleaccount_idandchatgpt_user_idinstead of accepting the account boundary alone.Client follow-up
refresh_token_reusedvolume after the same-store race fix.token_exchange_failedseparately.Testing
cargo test -p codex-login stale_proactive_refresh_uses_newer_local_auth_before_spending_cached_refresh_token -- --nocapturecargo test -p codex-login stale_proactive_refresh_does_not_adopt_a_different_user_in_same_account -- --nocapturecargo test -p codex-login stale_proactive_refresh_without_account_id_adopts_auth_with_account_id -- --nocapturecargo test -p codex-login stale_proactive_refresh_without_identity_claims_still_attempts_refresh -- --nocapturecargo test -p codex-login unauthorized_recovery_reload_uses_original_auth_snapshot_for_same_account_user_guard -- --nocapturecargo test -p codex-login refresh_token_reused_recovers_if_guarded_reload_finds_newer_auth -- --nocapturecargo test -p codex-login refresh_token_reused_without_account_id_adopts_auth_when_disk_auth_gains_account_id -- --nocapturecargo test -p codex-login --no-run --message-format shortcargo test -p codex-cloud-requirements fetch_cloud_requirements_uses_reloaded_auth_before_unauthorized_retry -- --nocapturecargo test -p codex-cloud-requirements fetch_cloud_requirements_rejects_different_user_in_same_account -- --nocapturecargo test -p codex-cloud-requirements --no-run --message-format shortjust fmtCODEX_HOME=/tmp/codex-auth-resilience-smokeusing/Users/ccy/code/codex/codex-rs/target/debug/codex.auth.jsonstale, restored newer same-user auth on disk, then prompted again in the same session; it succeeded without relogin.tokens.account_id, then restored current same-user auth on disk; the same session still succeeded without relogin.