Skip to content

Avoid duplicate auth refreshes in getAuthStatus - #15798

Merged
etraut-openai merged 3 commits into
mainfrom
etraut/fix-flaky-ci-auth-test
Mar 25, 2026
Merged

etraut-openai merged 3 commits into
mainfrom
etraut/fix-flaky-ci-auth-test

Conversation

@etraut-openai

@etraut-openai etraut-openai commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

I've seen several intermittent failures of get_auth_status_returns_token_after_proactive_refresh_recovery today. I investigated, and I found a couple of issues.

First, getAuthStatus(refreshToken=true) could refresh twice in one request: once via refresh_token_if_requested() and again via the proactive refresh path inside auth_manager.auth(). In the permanent-failure case this produced an extra /oauth/token call and made the app-server auth tests flaky. Use auth_cached() after an explicit refresh request so the handler reuses the post-refresh auth state instead of immediately re-entering proactive refresh logic. Keep the existing proactive path for refreshToken=false.

Second, serialize auth refresh attempts in AuthManager have a startup/request race. One proactive refresh could already be in flight while a getAuthStatus(refreshToken=false) request entered auth().await, causing a second /oauth/token call before the first failure or refresh result had been recorded. Guarding the refresh flow with a single async lock makes concurrent callers share one refresh result, which prevents duplicate refreshes and stabilizes the proactive-refresh auth tests.

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

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

@etraut-openai etraut-openai changed the title Fix duplicate auth refresh in app-server status checks Stabilize app-server auth refreshes in getAuthStatus Mar 25, 2026
@etraut-openai etraut-openai changed the title Stabilize app-server auth refreshes in getAuthStatus Avoid duplicate auth refreshes in getAuthStatus Mar 25, 2026
Comment thread codex-rs/login/src/auth/manager.rs Outdated
self.refresh_token_locked().await
}

async fn refresh_token_locked(&self) -> Result<(), RefreshTokenError> {

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.

quite unfortunate to have two of these methods (one of which doesn't record the error)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll refactor to eliminate the redundancy.

@etraut-openai
etraut-openai merged commit 2c67a27 into main Mar 25, 2026
36 checks passed
@etraut-openai
etraut-openai deleted the etraut/fix-flaky-ci-auth-test branch March 25, 2026 22:03
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 25, 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