Skip to content

fix(codex): adopt refresh_token from auth.json even without access_token - #77028

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/70111-codex-credential-pool-adoption
Aug 2, 2026
Merged

fix(codex): adopt refresh_token from auth.json even without access_token#77028
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/70111-codex-credential-pool-adoption

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Codex credential pool profiles go terminally DEAD when a sibling profile rotates the shared token pair — the adoption path silently no-ops when auth.json has a refresh_token but no access_token, and the 401-retry path falsely logs "auth refreshed" when no new token was minted.

Changes

  • agent/credential_pool.py: Adopt refresh_token from auth.json even when store_access is empty (preserve entry's existing access_token via store_access or entry.access_token)
  • agent/credential_pool.py: Widen source guard to include manual:device_code entries (follow-up commit — the original PR's fix was unreachable for manual:device_code, the recommended quarantine-safe config)
  • run_agent.py: Return False from _try_refresh_codex_client_credentials when the refresh produced the same token (compare before/after)

Validation

  • 96 targeted tests pass (credential_pool + codex_responses)
  • E2E with real imports: confirmed fix works for both device_code and manual:device_code sources
  • /simplify-code 3-agent review completed (HIGH on source guard gap folded)

Closes #70097

Credits @JonthanaHanh for the original fix and @imgyf for the source guard analysis.

JonthanaHanh and others added 2 commits August 3, 2026 00:11
…ken (NousResearch#70097)

Two defects in the openai-codex credential pool recovery path:

Defect 1 — adoption path silently no-ops when store_access is empty

_sync_codex_entry_from_auth_store() skipped adoption when the auth
store had no access_token (only last_refresh).  When another process
rotated the token pair, the stale profile's entry kept the consumed
refresh_token and replayed it, getting refresh_token_reused and going
terminally DEAD.

Fix: also adopt when store_refresh differs from entry_refresh, even
when store_access is empty.  Keep the entry's existing access_token
in that case (store_access or entry.access_token).

Defect 2 — false 'auth refreshed' success log

_try_refresh_codex_client_credentials() returned True whenever
resolve_codex_runtime_credentials() returned any non-empty credentials,
including the same stale token when the underlying refresh failed.
The conversation loop then logged 'auth refreshed after 401' right
before the retry failed with the identical token_expired.

Fix: compare the access token before/after the refresh.  If unchanged,
return False so the 401-retry path logs the truth.

Fixes NousResearch#70097
The _sync_codex_entry_from_auth_store source guard returned early for
source='manual:device_code', which is the recommended quarantine-safe
configuration (hermes auth add openai-codex produces SOURCE_MANUAL_DEVICE_CODE).
The PR's fix for refresh_token adoption was unreachable for these entries.

Widen the guard to accept both 'device_code' and 'manual:device_code'.

Follow-up to NousResearch#70111. Issue reporter (imgyf) confirmed this caused a
12-of-16 fleet outage on Aug 1.

Co-authored-by: imgyf <imgyf@users.noreply.github.com>
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 2, 2026 18:53
@kshitijk4poor
kshitijk4poor merged commit 7380b48 into NousResearch:main Aug 2, 2026
35 checks passed
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API area/auth Authentication, OAuth, credential pools P2 Medium — degraded but workaround exists sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data labels Aug 2, 2026
@kshitijk4poor
kshitijk4poor deleted the salvage/70111-codex-credential-pool-adoption branch August 5, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

3 participants