The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): startup auth fallback re-resolves reasoning effort through the CLI chokepoint
teknium18e1b4216b5b1
diff --git a/hermes_cli/cli_agent_setup_mixin.py b/hermes_cli/cli_agent_setup_mixin.pyindex 154c8f74969..d26399b1855 100644--- a/hermes_cli/cli_agent_setup_mixin.py+++ b/hermes_cli/cli_agent_setup_mixin.py@@ -326,14 +326,14 @@ class CLIAgentSetupMixin:platform="cli")self.requested_provider = _fb_providerself.model = _fb_model+ # Startup resolved reasoning_config for the launch model; the fallback model has its+ # own per-model contract (an always-thinking model 400s on the primary's effort).+ # Same chokepoint as /model, /new and --resume; an explicit --reasoning is the+ # user's intent for this run and outranks the fallback model's config.if getattr(self, "_explicit_reasoning_config", None) is None:- try:- from cli import CLI_CONFIG- from hermes_constants import resolve_reasoning_config- self.reasoning_config = resolve_reasoning_config(CLI_CONFIG, self.model)- except Exception:- # Fallback routing must remain available when optional config refresh fails.- pass+ from hermes_cli.cli_model_switch_mixin import _resolve_cli_reasoning+ _resolve_cli_reasoning(self)+ logger.info("Fallback %s: reasoning_config resolved: %s", self.model, self.reasoning_config)return runtimeexcept Exception:continuediff --git a/tests/hermes_cli/test_cli_provider_resolution.py b/tests/hermes_cli/test_cli_provider_resolution.pyindex 769fd507593..3c6fd435a68 100644--- a/tests/hermes_cli/test_cli_provider_resolution.py+++ b/tests/hermes_cli/test_cli_provider_resolution.py@@ -533,58 +533,35 @@ def test_codex_provider_uses_config_model(monkeypatch):@pytest.mark.parametrize(- ("reasoning_flag", "expected_reasoning"),- [- (None, {"enabled": True, "effort": "low"}),- ("medium", {"enabled": True, "effort": "medium"}),- ],- ids=["fallback_model_override", "explicit_cli_override_wins"],+ ("reasoning_flag", "expected_effort"),+ [(None, "high"), ("low", "low")],+ ids=["fallback_model_override_applies", "explicit_cli_flag_outranks"],)-def test_startup_fallback_re_resolves_reasoning_for_selected_model(- monkeypatch, reasoning_flag, expected_reasoning,-):- """Startup fallback must use its model's config without replacing --reasoning."""- from hermes_cli.cli_agent_setup_mixin import CLIAgentSetupMixin-- config = {- "reasoning_effort": "high",- "reasoning_overrides": {- "primary-model": "high",- "fallback-model": "low",- },- }- shell = SimpleNamespace(- _fallback_model=[{"provider": "fallback", "model": "fallback-model"}],- requested_provider="primary",- model="primary-model",- reasoning_config={"enabled": True, "effort": "high"}- if reasoning_flag is None else {"enabled": True, "effort": reasoning_flag},- _explicit_reasoning_config=None- if reasoning_flag is None else {"enabled": True, "effort": reasoning_flag},- )- monkeypatch.setitem(sys.modules, "cli", SimpleNamespace(- CLI_CONFIG={"agent": config},- _cprint=lambda _message: None,- logger=SimpleNamespace(warning=lambda *_args, **_kwargs: None),- ))- monkeypatch.setattr("hermes_cli.fallback_config.resolve_entry_api_key", lambda _entry: None)-- def resolve_runtime(**kwargs):- return {- "provider": "fallback",- "api_mode": "chat_completions",- "base_url": "https://fallback.example/v1",- "api_key": "fallback-key",- }+def test_startup_fallback_re_resolves_reasoning_for_the_fallback_model(monkeypatch, reasoning_flag, expected_effort):+ """Startup auth fallback swaps the model, so the CLI-level reasoning_config must follow it+ (per-model override for the fallback model, not the launch model's effort); an explicit+ ``--reasoning`` is the user's intent for this run and survives the swap."""+ cli = _import_cli()+ monkeypatch.setattr(cli, "_cprint", lambda *a, **k: None)+ monkeypatch.setitem(cli.CLI_CONFIG, "model", {"default": "primary-model", "provider": "openai-codex"})+ monkeypatch.setitem(cli.CLI_CONFIG, "fallback_providers", [{"provider": "zai", "model": "glm-5.3-flash"}])+ monkeypatch.setitem(cli.CLI_CONFIG, "agent", {+ **cli.CLI_CONFIG.get("agent", {}), "reasoning_effort": "medium",+ "reasoning_overrides": {"glm-5.3-flash": "high"}})++ def _runtime_resolve(requested=None, **kwargs):+ if requested == "openai-codex":+ raise AuthError("quota exhausted", provider="openai-codex", code="auth_failed")+ return {"provider": "zai", "api_mode": "chat_completions",+ "base_url": "https://api.z.ai/api/coding/paas/v4", "api_key": "sk-zai", "source": "env"}- monkeypatch.setattr("hermes_cli.runtime_provider.resolve_runtime_provider", resolve_runtime)+ monkeypatch.setattr("hermes_cli.runtime_provider.resolve_runtime_provider", _runtime_resolve)+ shell = cli.HermesCLI(compact=True, max_turns=1, reasoning=reasoning_flag)+ assert shell.reasoning_config["effort"] == ("medium" if reasoning_flag is None else reasoning_flag)- runtime = CLIAgentSetupMixin._resolve_fallback_runtime(- shell, AuthError("primary credentials rejected"),- )- assert runtime["provider"] == "fallback"- assert shell.model == "fallback-model"- assert shell.reasoning_config == expected_reasoning+ assert shell._ensure_runtime_credentials() is True+ assert (shell.model, shell.provider) == ("glm-5.3-flash", "zai")+ assert shell.reasoning_config["effort"] == expected_effortdiff --git a/website/docs/user-guide/features/fallback-providers.md b/website/docs/user-guide/features/fallback-providers.mdindex ea3e04efd8e..8cefd8840ff 100644--- a/website/docs/user-guide/features/fallback-providers.md+++ b/website/docs/user-guide/features/fallback-providers.md@@ -123,10 +123,13 @@ When triggered, Hermes:1. Resolves credentials for the fallback provider (including named custom providers using `key_cmd`)2. Builds a new API client, preserving a dynamic credential source across timeout and request-client rebuilds3. Swaps the model, provider, and client in-place-4. Resets the retry counter and continues the conversation+4. Re-resolves the reasoning effort for the fallback model (its `agent.reasoning_overrides` entry, else the global `agent.reasoning_effort`)+5. Resets the retry counter and continues the conversationThe switch is seamless — your conversation history, tool calls, and context are preserved. The agent continues from exactly where it left off, just using a different model.+The same re-resolution happens when the CLI falls back at **startup** because the primary provider's auth fails before the first request: the fallback model is sent its own configured effort, not the primary's. An explicit `hermes chat --reasoning <level>` is kept across that startup switch — it is your intent for the run.+:::warning Fallback resets the prompt cachePrompt caches are keyed to the model (and on most providers, the account) serving the request. When fallback fires, the new provider:model has no cached prefix for your conversation, so the next request re-reads the entire history at full input-token price instead of the ~75–90% discounted cached rate. The same applies when the turn ends and the primary is restored — that first request back on the primary is a full re-read too (unless the primary's cache TTL hasn't expired). This is unavoidable — it's the cost of staying alive through an outage — but it's why a long session that bounces between providers can cost noticeably more than one that stays put.:::