feat(auth): share openai-codex OAuth token across profiles via shared store - #47233
Closed
andrewkangkr wants to merge 1 commit into
Closed
feat(auth): share openai-codex OAuth token across profiles via shared store#47233andrewkangkr wants to merge 1 commit into
andrewkangkr wants to merge 1 commit into
Conversation
… 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>
Contributor
|
Thanks for the careful investigation and regression coverage. This is already implemented on current
Closing as implemented on main. |
14 tasks
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.
Problem
Hermes keeps a per-profile
openai-codexsingleton token, but OAuthrefresh_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--profilegateway 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.jsonself-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:<hermes-root>/shared/codex_auth.jsonon every_save_codex_tokens, atomically (O_EXCL,0o600) under a cross-profile lock.~/.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
hermes auth add openai-codexlive in the credential pool and never flow through_save_codex_tokens, so they are never published (regression guard for [Bug]: openai-codex OAuth add/reauth overwrites existing credential-pool entries while preserving stale labels #39236)._auth_store_lockis always acquired before the shared-store lock.auth.jsonremains the source of truth.0o600perms as the Nous/xAI stores (fix(google_oauth): close TOCTOU window when saving credentials #19673, fix(security): close TOCTOU window when saving MCP OAuth credentials #21148).Tests
New
tests/hermes_cli/test_auth_codex_shared_store.py(10 tests, all passing):Noneon missing/malformed; owner-only file perms_save_codex_tokenspublishes to the shared storeNonewhen empty, and skips an expiring token~/.codexExisting codex/nous auth suites pass unchanged.
🤖 Generated with Claude Code