Skip to content

Attempt to reload auth as a step in 401 recovery#8880

Merged
pakrym-oai merged 18 commits intomainfrom
pakrym/attempt-to-reload-auth-as-a-step-in-401-recovery
Jan 8, 2026
Merged

Attempt to reload auth as a step in 401 recovery#8880
pakrym-oai merged 18 commits intomainfrom
pakrym/attempt-to-reload-auth-as-a-step-in-401-recovery

Conversation

@pakrym-oai
Copy link
Copy Markdown
Collaborator

When authentication fails, first attempt to reload the auth from file and then attempt to refresh it.

…cess sync

- Add AuthManager::auth_cached and move stale-token refresh logic into AuthManager
- Make CodexAuth::get_token/get_token_data synchronous and remove CodexAuth::refresh_token
- Change auth_provider_from_auth and BackendClient::from_auth to non-async
- Replace direct CodexAuth usage with AuthManager where appropriate and use cached auth for UI/status
Copy link
Copy Markdown
Contributor

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

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: 56598f3193

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread codex-rs/core/src/auth.rs
Tidy up auth recovery code:

- Fix line formatting in UnauthorizedRecovery::has_next
- Simplify Arc::clone usage in AuthManager::unauthorized_recovery
- Use method pointer for unauthorized_recovery mapping in ModelClient
- Reformat conditional let in handle_unauthorized and drop redundant return
Introduce ReloadOutcome and expected_account_id tracking in UnauthorizedRecovery
to conditionally skip reloading auth when the on-disk account id differs from
the cached one. Refactor AuthManager reload logic into load_auth_from_storage
and store_auth helpers, add reload_if_account_id_matches with account id
validation, and preserve cached auth when reload is skipped. Add a test to
verify that recovery
Base automatically changed from pakrym/immutable-codexauth to main January 8, 2026 19:43
Comment thread codex-rs/core/src/auth.rs
Comment thread codex-rs/core/src/auth.rs
Comment thread codex-rs/core/src/auth.rs Outdated
Comment thread codex-rs/core/src/auth.rs
}
}
UnauthorizedRecoveryStep::RefreshToken => {
self.manager.refresh_token().await?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In this path, should we should avoid writing the refreshed token information back to the credential store? This will happen if the user has subsequently logged out or logged in to a different account. Overwriting that subsequent login info feels wrong. Then again, if we don't overwrite it, other instances that were created with the old token will fail if they later try to refresh their tokens.

  1. Log in with account A to instance 1
  2. Log in with account A to instance 2
  3. Log in with account B to instance 3
  4. Instance 1 gets 401 and refreshes its token. Do we write it back to auth.json? If we do, then instance 2 will see the refreshed token (good) but the next instance launched will use account A rather than B (bad). If we don't, then instance 2 will not see the refreshed token (bad).

Hmm, I don't see a way to handle all of these cases without persisting token state for multiple accounts, which gets even more complex.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Chatted offline, decided to proceed with the status quo for now.

Comment thread codex-rs/core/src/auth.rs Outdated
Comment thread codex-rs/core/src/auth.rs
Comment thread codex-rs/core/src/client.rs
Add high-level docs for UnauthorizedRecovery state machine behavior.
Rename store_auth() to set_auth() and use it consistently in reload
paths. Simplify refresh_token() by using a single auth_cached() call.
@pakrym-oai pakrym-oai merged commit 62a73b6 into main Jan 8, 2026
26 checks passed
@pakrym-oai pakrym-oai deleted the pakrym/attempt-to-reload-auth-as-a-step-in-401-recovery branch January 8, 2026 23:06
@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 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