Skip to content

The agent that grows with you

fix: warn when a new Codex login is the same OpenAI account as a pooled credential

teknium165f6e31ffe53
diff --git a/hermes_cli/auth_commands.py b/hermes_cli/auth_commands.py
index 988895bfc53..43d12bf2c39 100644
--- a/hermes_cli/auth_commands.py
+++ b/hermes_cli/auth_commands.py
@@ -14,8 +14,8 @@ import uuid
from agent.credential_pool import (
AUTH_TYPE_API_KEY, AUTH_TYPE_OAUTH, CUSTOM_POOL_PREFIX, SOURCE_MANUAL,
SOURCE_MANUAL_DEVICE_CODE, STATUS_EXHAUSTED, STRATEGY_FILL_FIRST, STRATEGY_ROUND_ROBIN,
- STRATEGY_RANDOM, STRATEGY_LEAST_USED, PooledCredential, REFRESHABLE_OAUTH_PROVIDERS, _exhausted_until,
- _normalize_custom_pool_name, get_pool_strategy, label_from_token, list_custom_pool_providers,
+ STRATEGY_RANDOM, STRATEGY_LEAST_USED, PooledCredential, REFRESHABLE_OAUTH_PROVIDERS, _codex_principal_identity,
+ _exhausted_until, _normalize_custom_pool_name, get_pool_strategy, label_from_token, list_custom_pool_providers,
load_pool)
import hermes_cli.auth as auth_mod
from hermes_cli.auth import PROVIDER_REGISTRY
@@ -407,16 +407,37 @@ def _add_credential(args, provider: str, pool, requested_type: str) -> PooledCre
entry = PooledCredential(
provider=provider, id=uuid.uuid4().hex[:6], label=label, auth_type=spec.auth_type, priority=0,
source=spec.source, access_token=token, **spec.fields(creds, provider))
- first_credential = not pool.entries()
+ existing = pool.entries()
entry = pool.add_entry(entry)
# The first Codex/xAI credential becomes the active provider (as the old singleton save path
# did implicitly); subsequent adds leave the active provider as-is.
- if spec.activate_first and first_credential:
+ if spec.activate_first and not existing:
auth_mod.mark_provider_active_if_unset(provider)
print(f'Added {provider} OAuth credential #{len(pool.entries())}: "{entry.label}"')
+ if provider == "openai-codex":
+ _warn_same_codex_account(token, existing)
return entry
+def _warn_same_codex_account(token: str, existing: list[PooledCredential]) -> None:
+ """Tell the user when a fresh Codex login is the same OpenAI account as a pooled credential.
+
+ Two logins of one account share a single token family upstream: the provider revokes the
+ older grant, so the second credential adds no quota and silently kills the first (#47096).
+ Only distinct accounts rotate independently — the pool cannot keep both alive.
+ """
+ identity = _codex_principal_identity(token)
+ if identity is None:
+ return
+ for position, sibling in enumerate(existing, start=1):
+ if _codex_principal_identity(sibling.access_token) == identity:
+ print(f'warning: this login is the same OpenAI account as openai-codex credential #{position} '
+ f'("{sibling.label}"). Both logins share one token family, so OpenAI will revoke the older one '
+ "and you gain no extra quota. Log into a different account instead, or keep just one "
+ f"(`hermes auth remove openai-codex {position}`).", file=sys.stderr)
+ return
+
+
def _report_priority(provider: str, pool, moved, requested: int, verb: str, prep: str) -> None:
"""Print the effective priority and say why it differs from the request, if it does."""
print(f'{verb} {provider} credential "{moved.label}" {prep} priority {moved.priority} '
diff --git a/tests/hermes_cli/test_auth_commands.py b/tests/hermes_cli/test_auth_commands.py
index aecd6a5635d..df411db9ff9 100644
--- a/tests/hermes_cli/test_auth_commands.py
+++ b/tests/hermes_cli/test_auth_commands.py
@@ -609,6 +609,56 @@ def test_auth_add_codex_oauth_keeps_distinct_pool_accounts(tmp_path, monkeypatch
assert payload["active_provider"] == "openai-codex"
+def _codex_jwt(email: str, account_id: str, subject: str) -> str:
+ header = base64.urlsafe_b64encode(b'{"alg":"RS256","typ":"JWT"}').rstrip(b"=").decode()
+ claims = {"email": email, "sub": subject, "https://api.openai.com/auth": {"chatgpt_account_id": account_id}}
+ payload = base64.urlsafe_b64encode(json.dumps(claims).encode()).rstrip(b"=").decode()
+ return f"{header}.{payload}.signature"
+
+
+def _add_codex_twice(tmp_path, monkeypatch, capsys, second_token: str) -> str:
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes"))
+ _write_auth_store(tmp_path, {"version": 1, "providers": {}})
+ codex_login = {"base_url": "https://chatgpt.com/backend-api/codex", "last_refresh": "2026-09-01T00:00:00Z"}
+ logins = iter([
+ {"tokens": {"access_token": _codex_jwt("[email protected]", "acct-A", "user-1"), "refresh_token": "rt-1"}, **codex_login},
+ {"tokens": {"access_token": second_token, "refresh_token": "rt-2"}, **codex_login},
+ ])
+ monkeypatch.setattr("hermes_cli.auth._codex_device_code_login", lambda: next(logins))
+ from hermes_cli.auth_commands import auth_add_command
+
+ class _Args:
+ provider = "openai-codex"
+ auth_type = "oauth"
+ api_key = None
+ label = None
+
+ auth_add_command(_Args())
+ capsys.readouterr()
+ auth_add_command(_Args())
+ return capsys.readouterr().err
+
+
+def test_auth_add_codex_warns_when_login_is_same_account_as_pooled_entry(tmp_path, monkeypatch, capsys):
+ """A second ``hermes auth add openai-codex`` for the SAME OpenAI account must tell the user
+ which existing credential it duplicates (#47096): the two logins share one token family and
+ the provider revokes the older one, so the extra entry buys no quota. Different accounts
+ get no warning — they rotate independently.
+ """
+ from agent.credential_pool import load_pool
+
+ err = _add_codex_twice(tmp_path, monkeypatch, capsys, _codex_jwt("[email protected]", "acct-A", "user-1"))
+ assert "same OpenAI account as openai-codex credential #1" in err
+ assert '"[email protected]"' in err and "hermes auth remove openai-codex 1" in err
+ # The warning informs; it never blocks the add.
+ assert len(load_pool("openai-codex").entries()) == 2
+
+
+def test_auth_add_codex_stays_quiet_for_a_different_account(tmp_path, monkeypatch, capsys):
+ err = _add_codex_twice(tmp_path, monkeypatch, capsys, _codex_jwt("[email protected]", "acct-B", "user-2"))
+ assert "same OpenAI account" not in err
+
+
def test_codex_auth_status_reports_pool_only_credential(tmp_path, monkeypatch):
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes"))
_write_auth_store(tmp_path, _codex_pool_only_store())
diff --git a/website/docs/user-guide/features/credential-pools.md b/website/docs/user-guide/features/credential-pools.md
index c2bccadb023..2c4c9c8b2ed 100644
--- a/website/docs/user-guide/features/credential-pools.md
+++ b/website/docs/user-guide/features/credential-pools.md
@@ -112,6 +112,8 @@ anthropic supports both API keys and OAuth login.
Type [1/2]:
```
+Each `hermes auth add openai-codex` login becomes its own pool entry, but only **different** OpenAI accounts rotate independently: two logins of the same account share one token family upstream, so OpenAI revokes the older one and the second entry adds no quota. Hermes warns at add time (`warning: this login is the same OpenAI account as openai-codex credential #N`) — log into a different account, or keep just one.
+
## CLI Commands
| Command | Description |