Skip to content

The agent that grows with you

fix: TUI auth fallback no longer crashes on `model: <id>` config shorthand

teknium1e7cc3836e156
diff --git a/tests/tui_gateway/test_pre_agent_fallback_notice.py b/tests/tui_gateway/test_pre_agent_fallback_notice.py
index 3fdcea87a3c..f3cdc115446 100644
--- a/tests/tui_gateway/test_pre_agent_fallback_notice.py
+++ b/tests/tui_gateway/test_pre_agent_fallback_notice.py
@@ -45,3 +45,29 @@ def test_primary_build_carries_no_notice(monkeypatch, tmp_path):
agent = _build(monkeypatch, tmp_path, primary_fails=False)
assert agent.kwargs["provider"] == "openai-codex"
assert not hasattr(agent, "_pending_fallback_notice")
+
+
+def test_fallback_build_survives_model_string_shorthand(monkeypatch, tmp_path):
+ """``model: <id>`` (the string shorthand every other reader accepts) must not crash the fallback
+ build while it names the primary in the notice."""
+ from tui_gateway import server
+
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ monkeypatch.setenv("HERMES_IGNORE_RULES", "1")
+ (tmp_path / "config.yaml").write_text("model: gpt-5.6-sol\n", encoding="utf-8")
+ monkeypatch.setattr(server, "_hermes_home", tmp_path)
+ monkeypatch.setattr(server, "_get_db", lambda: None)
+ monkeypatch.setattr(server, "_load_fallback_model",
+ lambda: [{"provider": "anthropic", "model": "claude-sonnet-5", "api_key": "fb"}])
+
+ def _resolve(**kwargs):
+ if kwargs.get("requested") != "anthropic":
+ raise AuthError("expired")
+ return {"api_key": "k", "base_url": "https://example.invalid/v1",
+ "provider": "anthropic", "api_mode": "chat_completions"}
+
+ with patch("hermes_cli.runtime_provider.resolve_runtime_provider", side_effect=_resolve), \
+ patch("run_agent.AIAgent", _StubAgent):
+ agent = server._make_agent("sid", "key", context_cwd_is_launch_artifact=False)
+ assert (agent.kwargs["provider"], agent.kwargs["model"]) == ("anthropic", "claude-sonnet-5")
+ assert "gpt-5.6-sol" in agent._pending_fallback_notice and "anthropic/claude-sonnet-5" in agent._pending_fallback_notice
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index 88ae448518a..475d106c4a9 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -2347,8 +2347,10 @@ def _resolve_agent_model_runtime(model_override, provider_override) -> tuple[str
# Same pre-agent switch the messaging gateway surfaces (#74349); _make_agent pops it onto the
# agent's one-shot notice so the TUI/Desktop user sees which provider actually answered.
from hermes_cli.fallback_config import pre_agent_fallback_notice
- # requested_provider=None means resolve_runtime_provider read the persisted config provider.
- primary_provider = requested_provider or (_load_cfg().get("model") or {}).get("provider")
+ # requested_provider=None means resolve_runtime_provider read the persisted config provider;
+ # ``model: <id>`` (string shorthand) names no provider.
+ cfg_model = _load_cfg().get("model")
+ primary_provider = requested_provider or (cfg_model.get("provider") if isinstance(cfg_model, dict) else None)
resolution.runtime["_fallback_notice"] = pre_agent_fallback_notice(
primary_provider, model, resolution.runtime.get("provider"), resolution.selected_model)
return resolution.selected_model, resolution.runtime