Skip to content

The agent that grows with you

fix(auth): inherit global Codex pool in profiles

nekwo3767c2eacdde
diff --git a/hermes_cli/auth_codex.py b/hermes_cli/auth_codex.py
index fa0e6f8a213..3b767bd3f91 100644
--- a/hermes_cli/auth_codex.py
+++ b/hermes_cli/auth_codex.py
@@ -607,11 +607,13 @@ def _codex_pool_dicts(entries: Optional[List[Any]]) -> Iterator[Dict[str, Any]]:
def _read_codex_pool_entries() -> Optional[List[Any]]:
- """Locked read of ``credential_pool.openai-codex`` from auth.json (None when absent)."""
- from hermes_cli.auth import _auth_store_lock, _load_auth_store
+ """Locked read of ``credential_pool.openai-codex`` (None when absent).
+
+ Goes through ``read_credential_pool`` so a named profile with an empty local Codex pool
+ inherits the global-root pool, the same per-provider fallback every other pool read uses."""
+ from hermes_cli.auth import _auth_store_lock, read_credential_pool
with _auth_store_lock():
- auth_store = _load_auth_store()
- return _pool_entries(auth_store, "openai-codex")
+ return read_credential_pool("openai-codex") or None
def _codex_pool_rate_limit_status() -> Optional[Dict[str, Any]]:
diff --git a/tests/hermes_cli/test_auth_profile_fallback.py b/tests/hermes_cli/test_auth_profile_fallback.py
index 410137f6510..394113261ba 100644
--- a/tests/hermes_cli/test_auth_profile_fallback.py
+++ b/tests/hermes_cli/test_auth_profile_fallback.py
@@ -153,6 +153,37 @@ def test_provider_auth_state_returns_none_when_neither_has_it(profile_env):
+def test_codex_runtime_uses_global_pool_when_profile_singleton_is_empty(profile_env):
+ """Stale empty profile Codex state must not block the global credential pool."""
+ from hermes_cli.auth import resolve_codex_runtime_credentials
+
+ _write(profile_env["global"] / "auth.json", _make_auth_store(pool={
+ "openai-codex": [{
+ "id": "glob-codex",
+ "label": "global-codex",
+ "auth_type": "oauth",
+ "priority": 0,
+ "source": "manual:device_code",
+ "access_token": "global-codex-access-token",
+ "refresh_token": "global-codex-refresh-token",
+ }],
+ }))
+ _write(profile_env["profile"] / "auth.json", _make_auth_store(
+ providers={
+ "openai-codex": {
+ "auth_mode": "chatgpt",
+ "tokens": {"access_token": "", "refresh_token": ""},
+ },
+ },
+ pool={"openai-codex": []},
+ ))
+
+ creds = resolve_codex_runtime_credentials(refresh_if_expiring=False)
+
+ assert creds["source"] == "credential_pool"
+ assert creds["api_key"] == "global-codex-access-token"
+
+
# ---------------------------------------------------------------------------
# Classic mode — no fallback path should ever trigger
# ---------------------------------------------------------------------------