fix(auth): harden Codex quota probe token refresh - #72690
Open
kchuang1015 wants to merge 3 commits into
Open
Conversation
kchuang1015
marked this pull request as ready for review
July 27, 2026 14:37
Contributor
|
Thanks for the thorough lifecycle coverage. The underlying defect is still present on current The reviewed PR head has successful required CI, including all Python test slices and the blocking Windows-footguns check. GitHub currently marks the branch merge-conflicting against main, so salvage will require resolving the surrounding auth/pool changes rather than a clean merge. Automated hermes-sweeper review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Hardens the OpenAI Codex quota-restored probe so an expired access token can be refreshed safely before the usage request.
The refresh path now:
Motivation
The quota-restored probe can run while a pooled Codex credential is still under a persisted cooldown. If the stored access token expires during that cooldown, probing with it returns an authentication error and cannot demonstrate that upstream quota recovered.
Refreshing outside the owning store's lock is unsafe because Codex refresh tokens rotate and are single-use. A concurrent process or a stale whole-pool write can otherwise replay an old refresh token, split the canonical and pool token chains, or restore stale cooldown state after a newer login.
This change treats authentication and quota as independent lifecycles: successful refresh only restores a usable probe credential; only an explicit positive usage response clears cooldown.
Type of Change
Related Issues
Testing
scripts/run_tests.sh -j 4 tests/hermes_cli/test_auth_codex_quota_probe.py tests/agent/test_credential_pool.py tests/agent/test_credential_pool_oauth_writethrough.py tests/hermes_cli/test_auth_profile_fallback.py tests/hermes_cli/test_auth_codex_provider.py -q— 204 passed.scripts/run_tests.sh -j 4 -q— completed, but not fully green locally; see the baseline analysis below.ruff checkon all changed files.scripts/check-windows-footguns.pyon all changed files.git diff --check.ty checkon changed files — 0 new diagnostics relative to the sameorigin/mainbase.Local full-suite baseline analysis
The complete local runner finished with 8 failing files / 19 failing tests. None of the changed auth/pool regression files failed.
The same eight files were then rerun with the same Python environment and
-j 1in two clean disposable worktrees: currentorigin/mainand the rebased PR head.managed_uvcall count and bundled plugin discovery) passed in both clean worktrees; the latter was caused by an untracked local plugin directory.This produced no deterministic head-only failure. GitHub CI remains authoritative for the clean x86 test matrix.
Screenshots / Demos
Not applicable; this is an authentication lifecycle fix with no user-interface changes.
Checklist
Notes for Reviewers
Codex refresh tokens are rotating and single-use, so the owner-store lock intentionally spans the latest-state re-read, token exchange, and atomic save. The usage request itself remains outside that lock; its final write therefore uses conditional merge logic rather than persisting the pre-probe snapshot.
This overlaps with #64572 around global/root ownership, but it is not a complete duplicate: this change is specifically a current-main follow-up to the quota-restored probe and includes probe refresh, quota/auth separation, persistent transient-failure throttling, terminal lifecycle handling, and stale post-probe/whole-pool write protection. Maintainer guidance on consolidating shared ownership helpers with #64572 is welcome.