The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auth): Nous "not logged in" refresh failures leave rotation instead of a silent hour-long bench
teknium189c6a8a14586
diff --git a/hermes_cli/auth.py b/hermes_cli/auth.pyindex 9b8df2caf9f..07affc6cbfc 100644--- a/hermes_cli/auth.py+++ b/hermes_cli/auth.py@@ -1547,7 +1547,7 @@ def resolve_nous_access_token(with _provider_state_transaction("nous") as (auth_store, state, state_source_path):if not state:- raise _nous_err("Hermes is not logged into Nous Portal.", relogin=True)+ raise _nous_err("Hermes is not logged into Nous Portal.", "nous_auth_missing", relogin=True)portal_base_url = _nous_portal_base_url(state)client_id = str(state.get("client_id") or DEFAULT_NOUS_CLIENT_ID)verify = _resolve_verify(insecure=insecure, ca_bundle=ca_bundle, auth_state=state)@@ -1575,7 +1575,8 @@ def resolve_nous_access_token(access_token = state.get("access_token")refresh_token = state.get("refresh_token")if not isinstance(access_token, str) or not access_token:- raise _nous_err("No access token found for Nous Portal login.", relogin=True)+ raise _nous_err(+ "No access token found for Nous Portal login.", "nous_auth_missing_access_token", relogin=True)if not _is_expiring(state.get("expires_at"), refresh_skew_seconds):if merged_shared:@@ -1586,7 +1587,9 @@ def resolve_nous_access_token(return _memo(access_token)if not isinstance(refresh_token, str) or not refresh_token:- raise _nous_err("Session expired and no refresh token is available.", relogin=True)+ raise _nous_err(+ "Session expired and no refresh token is available.", "nous_auth_missing_refresh_token",+ relogin=True)with httpx.Client(timeout=httpx.Timeout(timeout_seconds or 15.0),headers={"Accept": "application/json"}, verify=verify) as client:@@ -1673,10 +1676,15 @@ class OAuthProviderFlow:_OAUTH_GRANT_DEAD_CODES = frozenset({"invalid_grant", "invalid_token", "refresh_token_reused"})+# Nous state-shape failures raised BEFORE any refresh POST (no login, no token pair): retrying+# cannot succeed either, so the pool must not bench them as a transient outage (#113718).+_NOUS_AUTH_MISSING_CODES = frozenset({+ "nous_auth_missing", "nous_auth_missing_access_token", "nous_auth_missing_refresh_token"})+OAUTH_PROVIDER_FLOWS: Dict[str, OAuthProviderFlow] = {"nous": OAuthProviderFlow("nous", "resolve_nous_runtime_credentials", "get_nous_auth_status",- terminal_refresh_codes=_OAUTH_GRANT_DEAD_CODES, logout_from_config=True),+ terminal_refresh_codes=_OAUTH_GRANT_DEAD_CODES | _NOUS_AUTH_MISSING_CODES, logout_from_config=True),"openai-codex": OAuthProviderFlow("openai-codex", "resolve_codex_runtime_credentials", "get_codex_auth_status",terminal_refresh_codes=_OAUTH_GRANT_DEAD_CODES | {"codex_refresh_failed", "codex_auth_missing_refresh_token"},diff --git a/hermes_cli/auth_nous.py b/hermes_cli/auth_nous.pyindex b016acb21bf..a3b510f2e3b 100644--- a/hermes_cli/auth_nous.py+++ b/hermes_cli/auth_nous.py@@ -786,7 +786,9 @@ def refresh_nous_oauth_from_state(if current_invoke_jwt_status is not None:raise _unusable_invoke_jwt_error(current_invoke_jwt_status, no_refresh_token=True)- raise _nous_err("No refresh token is available for Nous Portal.", relogin=True)+ raise _nous_err(+ "No refresh token is available for Nous Portal.", "nous_auth_missing_refresh_token",+ relogin=True)refreshed = _refresh_access_token(client=client, portal_base_url=state["portal_base_url"],client_id=state["client_id"], refresh_token=refresh_token_value)@@ -996,7 +998,8 @@ class _NousRuntimeResolve:if self.merge_shared():self.persist("runtime_shared_merge_missing_access_token")if not self.has_access_token():- raise _nous_err("No access token found for Nous Portal login.", relogin=True)+ raise _nous_err(+ "No access token found for Nous Portal login.", "nous_auth_missing_access_token", relogin=True)invoke_jwt_status = self.invoke_jwt_status()self.skip_refresh_if_peer_rotated()if not (self.force_refresh or invoke_jwt_status is not None):@@ -1054,7 +1057,7 @@ def _resolve_nous_runtime_credentials(_tls_state_from_verify)with _provider_state_transaction("nous") as (auth_store, state, state_source_path):if not state:- raise _nous_err("Hermes is not logged into Nous Portal.", relogin=True)+ raise _nous_err("Hermes is not logged into Nous Portal.", "nous_auth_missing", relogin=True)run = _NousRuntimeResolve(auth_store, state, state_source_path, force_refresh=force_refresh,stale_access_token=stale_access_token, timeout_seconds=timeout_seconds)diff --git a/tests/agent/test_credential_pool_terminal_refresh_visibility.py b/tests/agent/test_credential_pool_terminal_refresh_visibility.pyindex 2e7d5e14584..9c902a29c54 100644--- a/tests/agent/test_credential_pool_terminal_refresh_visibility.py+++ b/tests/agent/test_credential_pool_terminal_refresh_visibility.py@@ -117,20 +117,21 @@ def test_surviving_manual_entry_is_marked_dead_after_terminal_refresh(monkeypatcassert [e.id for e in pool._entries] == ["e1"] # manual rows are never dropped by the quarantineassert pool._entries[0].last_status == STATUS_DEAD-def test_nous_relogin_required_without_code_clears_state(monkeypatch, caplog):- """A Nous refresh failure demanding relogin is terminal even when the provider- supplied no dead code: benching it for an hour hides a lost login (#113718)."""- from hermes_cli.auth_constants import AuthError+def test_nous_login_missing_refresh_failure_is_terminal(monkeypatch, caplog):+ """The resolver's "not logged in" raise (``nous_auth_missing``, relogin_required) is terminal:+ retrying cannot succeed, so the row leaves rotation with a WARNING naming the fix and the+ reason recorded, instead of an hour-long bench with null error fields (#113718)."""+ from hermes_cli.auth_constants import _nous_errpool = _pool("nous")- entry = _entry("nous")+ entry = _entry("nous", source="manual:device_code")pool._entries = [entry]cleared: list = []monkeypatch.setattr(pool, "_sync_nous_entry_from_auth_store", lambda e: e)monkeypatch.setattr(pool, "_clear_terminal_nous_state", lambda e, exc: cleared.append(e.id))monkeypatch.setattr(pool, "_quarantine_sources", lambda e, sources: None)- exc = AuthError("session expired", provider="nous", code=None, relogin_required=True)+ exc = _nous_err("Hermes is not logged into Nous Portal.", "nous_auth_missing", relogin=True)with caplog.at_level(logging.INFO, logger=cp.logger.name):result = pool._recover_failed_refresh(entry, exc)@@ -138,10 +139,13 @@ def test_nous_relogin_required_without_code_clears_state(monkeypatch, caplog):warnings = [r for r in caplog.records if r.levelno == logging.WARNING and "terminally invalid" in r.getMessage()]assert len(warnings) == 1assert "hermes auth add nous" in warnings[0].getMessage()+ row = pool._entries[0]+ assert row.last_status == STATUS_DEAD+ assert (row.last_error_reason, row.last_error_message) == ("nous_auth_missing", str(exc))def test_nous_transient_error_still_benched(monkeypatch, caplog):- """Without relogin_required the failure stays transient: benched, not cleared."""+ """A failure that says nothing about the login stays transient: benched, not cleared."""pool = _pool("nous")entry = _entry("nous")pool._entries = [entry]diff --git a/website/docs/user-guide/features/credential-pools.md b/website/docs/user-guide/features/credential-pools.mdindex a12dce76fdb..e78931311ce 100644--- a/website/docs/user-guide/features/credential-pools.md+++ b/website/docs/user-guide/features/credential-pools.md@@ -188,7 +188,8 @@ cooldown. Billing (`402`, usage-limit) and auth (`401`) failures still bench the**A dead OAuth login is reported, not benched.** When a refresh token is rejected for good(`invalid_grant`, `invalid_token`, `refresh_token_reused` — the token was revoked, or another program-holding the same login rotated it first), the pool logs one WARNING naming the entry and the repair+holding the same login rotated it first — or, for Nous, the profile holds no Portal login or token+pair to refresh with), the pool logs one WARNING naming the entry and the repaircommand (`hermes auth add <provider>`), and the credential leaves rotation — marked `dead`, or droppedwhen it only mirrored a token file the pool has just cleared — until you sign in again. This applies to Anthropic, Codex, xAIand Nous OAuth logins alike. A dead credential never re-enters rotation on a timer, so a lost login