Skip to content

feat(auth): share openai-codex OAuth token across profiles via shared store - #47233

Closed
andrewkangkr wants to merge 1 commit into
NousResearch:mainfrom
andrewkangkr:feat/codex-shared-auth-store
Closed

feat(auth): share openai-codex OAuth token across profiles via shared store#47233
andrewkangkr wants to merge 1 commit into
NousResearch:mainfrom
andrewkangkr:feat/codex-shared-auth-store

Conversation

@andrewkangkr

Copy link
Copy Markdown

Problem

Hermes keeps a per-profile openai-codex singleton token, but OAuth refresh_tokens are single-use. When one gateway (e.g. the default profile) refreshes, it rotates the shared ChatGPT/Codex account token, so a sibling profile (e.g. a separate --profile gateway such as a dedicated assistant) that still holds the old refresh token starts failing with relogin-required 401s until a manual re-auth.

The existing ~/.codex/auth.json self-heal only recovers tokens the Codex CLI rotated. It does not cover the case where a sibling Hermes profile rotated the token, because Hermes deliberately does not write back to ~/.codex (#12360). With two gateways on the same account (default + a profile gateway), they rotate each other's tokens and intermittently 401.

Fix

Mirror the patterns already used for Nous (shared store) and xAI (global-root write-through, #43589), now for openai-codex:

  • Write-through: publish the singleton token to <hermes-root>/shared/codex_auth.json on every _save_codex_tokens, atomically (O_EXCL, 0o600) under a cross-profile lock.
  • Recover: on a relogin-required refresh failure, prefer a still-valid sibling-published token from the shared store before falling back to the Codex CLI store (~/.codex). An expiring shared token is skipped so the caller still falls through.

The shared dir resolution (HERMES_SHARED_AUTH_DIR<hermes-root>/shared/) is factored into _shared_auth_dir() and reused by the existing Nous helper.

Safety / scope

Tests

New tests/hermes_cli/test_auth_codex_shared_store.py (10 tests, all passing):

  • write/read roundtrip; write skips without refresh_token; read returns None on missing/malformed; owner-only file perms
  • _save_codex_tokens publishes to the shared store
  • recovery adopts a valid token, returns None when empty, and skips an expiring token
  • integration: a relogin-required refresh prefers the shared store over ~/.codex

Existing codex/nous auth suites pass unchanged.

🤖 Generated with Claude Code

… store

Hermes keeps a per-profile openai-codex singleton token, but OAuth
refresh_tokens are single-use. When one gateway (e.g. the default profile)
refreshes, it rotates the shared ChatGPT/Codex account token, so a sibling
profile (e.g. a separate `--profile` gateway) holding the old refresh token
starts failing with relogin-required 401s until a manual re-auth.

Mirror the existing shared-Nous-store / xAI global-root write-through (NousResearch#43589)
pattern for openai-codex: publish the singleton token to
`<hermes-root>/shared/codex_auth.json` on every save, and prefer a still-valid
sibling-published token before falling back to the Codex CLI store (~/.codex)
on a relogin-required refresh failure. This complements the existing ~/.codex
self-heal, which only recovers tokens the Codex CLI rotated (Hermes does not
write back to ~/.codex, see NousResearch#12360).

Only the singleton token is shared; independent accounts added via
`hermes auth add openai-codex` live in the credential pool and never flow
through `_save_codex_tokens`, so they are never published (regression guard
for NousResearch#39236).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alt-glitch alt-glitch added type/feature New feature or request comp/cli CLI entry point, hermes_cli/, setup wizard provider/openai OpenAI / Codex Responses API area/auth Authentication, OAuth, credential pools codex P2 Medium — degraded but workaround exists labels Jun 16, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the careful investigation and regression coverage. This is already implemented on current main through the existing global-root OAuth write-through path rather than a second shared-store protocol.

  • Automated hermes-sweeper review verified merged commit a4091e49f (#52760), which writes a refreshed openai-codex credential-pool grant back to the global root when a profile inherited that grant.
  • agent/credential_pool.py:916-996 preserves profile shadowing while updating the rotated token chain for sibling profiles that use the root fallback.
  • tests/agent/test_credential_pool_oauth_writethrough.py:76-176 covers the Codex root write-through and verifies profile-owned credentials do not clobber the root state.
  • The related cross-reference, PR feat(auth): Codex OAuth write-through to global root (multi-profile parity with xAI #43589) #50632, also records that this issue was fixed on main via #52760.

Closing as implemented on main.

@teknium1 teknium1 closed this Jul 14, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 14, 2026
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 codex comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API sweeper:implemented-on-main Sweeper: behavior already present on current main type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants