The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): a benched or signed-out credential prints its reason instead of the first-run provider wizard
teknium1d98b1480b984
diff --git a/cli.py b/cli.pyindex 93c46b0693d..e6718e935b9 100644--- a/cli.py+++ b/cli.py@@ -3658,10 +3658,13 @@ class HermesCLI(CLIProcessNotificationsMixin, CLIAgentSetupMixin, CLICommandsMixself._show_browser_backend_notice()# First-run: an unconfigured install routes into provider onboarding instead of- # a chat that spins ~30s and fails with a provider-specific error. TTY only.+ # a chat that spins ~30s and fails with a provider-specific error. TTY only. A+ # configured profile whose credential is benched or signed out gets the reason instead.try:- if sys.stdin.isatty() and not self._runtime_credentials_ready():- self._offer_first_run_setup()+ if sys.stdin.isatty():+ ready, error = self._probe_runtime_credentials()+ if not ready and not self._explain_unusable_credentials(error):+ self._offer_first_run_setup()except Exception:logger.debug("first-run setup offer failed", exc_info=True)diff --git a/hermes_cli/cli_agent_setup_mixin.py b/hermes_cli/cli_agent_setup_mixin.pyindex f3356b1a521..07c32f516fd 100644--- a/hermes_cli/cli_agent_setup_mixin.py+++ b/hermes_cli/cli_agent_setup_mixin.py@@ -51,6 +51,31 @@ def _route_signature(model, runtime: dict) -> tuple:runtime.get("api_mode"), runtime.get("command"), tuple(runtime.get("args") or ()))+def _credential_pool_cooldown_lines(provider: str) -> list:+ """Why *provider*'s pool has nothing selectable right now, for the startup notice: a+ cooldown with its remaining time, or a dead (quarantined) sign-in naming the re-login."""+ import time+ from agent.credential_pool import STATUS_DEAD, load_pool+ try:+ pool = load_pool(provider)+ if not pool.has_credentials() or pool.has_available():+ return []+ next_at = pool.next_available_at()+ dead = [e for e in pool.entries() if e.last_status == STATUS_DEAD]+ except Exception:+ return []+ lines = []+ if next_at is not None:+ minutes = max(1, int((next_at - time.time() + 59) // 60))+ lines.append(f"The {provider} credential is cooling down after a failed refresh; "+ f"it re-enters rotation in about {minutes}m.")+ if dead:+ reason = dead[0].last_error_message or dead[0].last_error_reason or "sign-in lost"+ lines.append(f"The {provider} sign-in was lost ({reason}); run `hermes auth add {provider}` "+ "to sign in again.")+ return lines++def _keyless_custom_base(base_url) -> bool:"""Custom/local endpoints (llama.cpp, ollama, vLLM) often need no auth; only anon-OpenRouter base_url qualifies."""@@ -351,20 +376,45 @@ class CLIAgentSetupMixin:See #62935."""+ return self._probe_runtime_credentials()[0]++ def _probe_runtime_credentials(self) -> tuple:+ """``(ready, error)``: *error* is the exception that stopped resolution, ``None`` when a+ provider resolved (usable or merely keyless). Never prints or mutates CLI state."""from hermes_cli.runtime_provider import resolve_runtime_providertry:runtime = resolve_runtime_provider(requested=self.requested_provider, explicit_api_key=self._explicit_api_key,explicit_base_url=self._explicit_base_url)- except Exception:- return False+ except Exception as exc:+ return False, excif not isinstance(runtime, dict):- return False+ return False, Noneapi_key = runtime.get("api_key")base_url = runtime.get("base_url")if callable(api_key) or (isinstance(api_key, str) and api_key):- return bool(base_url)- return _keyless_custom_base(base_url)+ return bool(base_url), None+ return _keyless_custom_base(base_url), None++ def _explain_unusable_credentials(self, error) -> bool:+ """A configured profile whose credential is benched, quarantined or signed out is not a+ blank install: print what is wrong (and the remaining cooldown) instead of the first-run+ wizard, whose "nothing is configured" claim sends operators into a second login that can+ rotate a single-use OAuth grant away from the session that was working (#113720).++ True when the failure was explained; False when nothing is configured (the wizard's case).+ """+ from cli import _cprint+ from hermes_cli.auth import format_auth_error+ if error is None or getattr(error, "code", None) == "no_provider_configured":+ return False+ provider = getattr(error, "provider", None) or self.requested_provider+ _cprint("")+ _cprint(f"⚠️ {_escape(format_auth_error(error))}")+ if provider and provider != "auto":+ for line in _credential_pool_cooldown_lines(provider):+ _cprint(f" {_escape(line)}")+ return Truedef _offer_first_run_setup(self) -> bool:"""Offer the provider picker when no provider is configured at all (interactivediff --git a/tests/hermes_cli/test_cli_first_run_setup.py b/tests/hermes_cli/test_cli_first_run_setup.pyindex 5882a36388c..d4738d6148f 100644--- a/tests/hermes_cli/test_cli_first_run_setup.py+++ b/tests/hermes_cli/test_cli_first_run_setup.py@@ -270,3 +270,59 @@ def test_empty_key_error_names_actual_provider(monkeypatch, capsys):assert "fireworks" in outassert "OPENROUTER_API_KEY" not in outassert "hermes model" in out or "hermes setup" in out+++# ---------------------------------------------------------------------------+# Configured-but-unusable credential: reason + cooldown, never the wizard (#113720)+# ---------------------------------------------------------------------------+++def test_benched_credential_prints_cooldown_instead_of_wizard(monkeypatch, capsys):+ """A profile whose only credential is cooling down is not a blank install: the startup notice+ names the failure and the remaining cooldown, and the first-run wizard is not offered."""+ import time+ from agent.credential_pool import STATUS_EXHAUSTED, CredentialPool, PooledCredential++ cli = _import_cli()+ shell = _make_shell(cli, monkeypatch)+ shell.requested_provider = "nous"++ def _raise(**kwargs):+ raise AuthError("Hermes is not logged into Nous Portal.", provider="nous",+ code="nous_auth_missing", relogin_required=True)++ monkeypatch.setattr("hermes_cli.runtime_provider.resolve_runtime_provider", _raise)+ benched = PooledCredential(id="e1", provider="nous", auth_type="oauth", access_token="x",+ refresh_token="r", label="portal", source="manual:device_code",+ priority=0, last_status=STATUS_EXHAUSTED, last_status_at=time.time() - 5)+ pool = CredentialPool.__new__(CredentialPool)+ monkeypatch.setattr(pool, "has_credentials", lambda: True, raising=False)+ monkeypatch.setattr(pool, "has_available", lambda **kw: False, raising=False)+ monkeypatch.setattr(pool, "next_available_at", lambda **kw: time.time() + 55, raising=False)+ monkeypatch.setattr(pool, "entries", lambda: [benched], raising=False)+ monkeypatch.setattr("agent.credential_pool.load_pool", lambda provider: pool)+ monkeypatch.setattr("hermes_cli.main.select_provider_and_model",+ lambda: (_ for _ in ()).throw(AssertionError("wizard must not run")))++ ready, error = shell._probe_runtime_credentials()+ assert ready is False+ assert shell._explain_unusable_credentials(error) is True+ out = capsys.readouterr().out+ assert "No inference provider is configured yet" not in out+ assert "not logged into Nous Portal" in out+ assert "cooling down" in out and "about 1m" in out+++def test_nothing_configured_still_reaches_wizard(monkeypatch):+ """Control: the resolver's ``no_provider_configured`` is the blank-install signal — nothing+ to explain, so the first-run wizard is offered as before."""+ cli = _import_cli()+ shell = _make_shell(cli, monkeypatch)++ def _raise(**kwargs):+ raise AuthError("Hermes is not connected to any AI provider yet.", code="no_provider_configured")++ monkeypatch.setattr("hermes_cli.runtime_provider.resolve_runtime_provider", _raise)+ ready, error = shell._probe_runtime_credentials()+ assert ready is False+ assert shell._explain_unusable_credentials(error) is Falsediff --git a/website/docs/user-guide/features/credential-pools.md b/website/docs/user-guide/features/credential-pools.mdindex e78931311ce..4967040eb70 100644--- a/website/docs/user-guide/features/credential-pools.md+++ b/website/docs/user-guide/features/credential-pools.md@@ -195,6 +195,12 @@ when it only mirrored a token file the pool has just cleared — until you signand Nous OAuth logins alike. A dead credential never re-enters rotation on a timer, so a lost loginshows up once in the log instead of failing quietly every hour.+**A cooling-down or dead credential is not a blank install.** When a configured profile starts the+CLI while its only credential is benched or quarantined, startup prints the failure and, for a bench,+the remaining cooldown (or the `hermes auth add <provider>` re-login for a dead one) — the first-run+"No inference provider is configured yet" wizard is offered only when the resolver finds nothing+configured at all.+## Custom Endpoint PoolsCustom OpenAI-compatible endpoints (Together.ai, RunPod, local servers) get their own pools, keyed by the endpoint name from the `providers:` dict in config.yaml (or the legacy `custom_providers` list, which is auto-migrated).