The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui-gateway): blame the pinned provider when runtime_check fails
Brooklyn Nicholson72eaa8306896
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.pyindex dcb8a3fce93..30d485769e9 100644--- a/tests/tui_gateway/test_tui_gateway_server.py+++ b/tests/tui_gateway/test_tui_gateway_server.py@@ -9195,6 +9195,9 @@ def test_probe_credentials_allows_keyless_custom_runtime():def test_setup_runtime_check_rejects_empty_runtime_key(monkeypatch):monkeypatch.setattr("hermes_cli.main._has_any_provider_configured", lambda **_kw: True)monkeypatch.setattr(server, "_resolve_startup_runtime", lambda: ("openrouter/test-model", None))+ # No pin anywhere (startup pin None, config model pin absent): the failure keeps naming the+ # resolved route's provider.+ monkeypatch.setattr(server, "_load_cfg", lambda: {"model": {}})monkeypatch.setattr("hermes_cli.runtime_provider.resolve_runtime_provider",lambda requested=None, **_kw: {@@ -9214,6 +9217,53 @@ def test_setup_runtime_check_rejects_empty_runtime_key(monkeypatch):assert result["error"]+def test_setup_runtime_check_failure_names_the_configured_pin_not_the_chain_tail(monkeypatch):+ """#124939: without an explicit ``provider`` the probe runs the startup pin and then the+ fallback chain. When the chain only resolves at its tail (BWS secrets not yet hydrated at+ boot), the runtime stops on the tail provider and the failure used to blame it — pointing+ the user at a provider they never pinned. The failure must name the pin."""+ monkeypatch.setattr("hermes_cli.main._has_any_provider_configured", lambda **_kw: True)+ monkeypatch.setattr(server, "_resolve_startup_runtime", lambda: ("glm-5.3", None))+ monkeypatch.setattr(server, "_load_cfg", lambda: {"model": {"provider": "zai"}})+ monkeypatch.setattr(+ "hermes_cli.runtime_provider.resolve_runtime_provider",+ lambda requested=None, **_kw: {+ "provider": "openrouter", # the chain tail that "resolved"+ "api_key": "",+ "source": "pool",+ },+ )++ resp = server.handle_request({"id": "1", "method": "setup.runtime_check", "params": {}})++ result = resp["result"]+ assert result["ok"] is False+ assert result["provider"] == "zai"+ assert result["error"] == "No usable credentials found for zai."+ assert "openrouter" not in result["error"]+++def test_setup_runtime_check_failure_names_startup_env_pin(monkeypatch):+ """The startup env pin (HERMES_TUI_PROVIDER) outranks the config model pin."""+ monkeypatch.setattr("hermes_cli.main._has_any_provider_configured", lambda **_kw: True)+ monkeypatch.setattr(server, "_resolve_startup_runtime", lambda: ("glm-5.3", "zai"))+ monkeypatch.setattr(server, "_load_cfg", lambda: {"model": {"provider": "openai-api"}})+ monkeypatch.setattr(+ "hermes_cli.runtime_provider.resolve_runtime_provider",+ lambda requested=None, **_kw: {+ "provider": "openrouter",+ "api_key": "",+ "source": "pool",+ },+ )++ resp = server.handle_request({"id": "1", "method": "setup.runtime_check", "params": {}})++ result = resp["result"]+ assert result["ok"] is False+ assert result["error"] == "No usable credentials found for zai."++def test_setup_runtime_check_allows_no_key_custom_runtime(monkeypatch):monkeypatch.setattr("hermes_cli.main._has_any_provider_configured", lambda **_kw: True)monkeypatch.setattr(@@ -9233,6 +9283,7 @@ def test_setup_runtime_check_allows_no_key_custom_runtime(monkeypatch):def test_setup_runtime_check_rejects_implicit_bedrock_when_unconfigured(monkeypatch):monkeypatch.setattr("hermes_cli.main._has_any_provider_configured", lambda **_kw: False)+ monkeypatch.setattr(server, "_load_cfg", lambda: {})monkeypatch.setattr("hermes_cli.runtime_provider.resolve_runtime_provider",lambda requested=None, **_kw: {@@ -9251,6 +9302,7 @@ def test_setup_runtime_check_rejects_implicit_bedrock_when_unconfigured(monkeypadef test_setup_runtime_check_honors_requested_provider(monkeypatch):"""Onboarding must be able to validate the provider the user just connected."""monkeypatch.setattr("hermes_cli.main._has_any_provider_configured", lambda **_kw: True)+ monkeypatch.setattr(server, "_load_cfg", lambda: {})def fake_resolve(requested=None, **kwargs):if requested == "nous":diff --git a/tui_gateway/methods_config.py b/tui_gateway/methods_config.pyindex fe68cc9f22a..011ebd2e7b6 100644--- a/tui_gateway/methods_config.py+++ b/tui_gateway/methods_config.py@@ -439,17 +439,26 @@ def _(rid, params: dict) -> dict:requested = str(params.get("provider") or "").strip() or Nonedef probe(profile, scoped):+ startup_model, startup_provider = _resolve_startup_runtime()if requested:- model, _startup_provider = _resolve_startup_runtime()- runtime = resolve_runtime_provider(requested=requested, target_model=model or None)+ model, runtime = startup_model, resolve_runtime_provider(+ requested=requested, target_model=startup_model or None)else:model, runtime = _resolve_agent_model_runtime(None, None)provider_configured = bool(_has_any_provider_configured(strict_profile_scope=bool(profile)))provider = runtime.get("provider") or "provider"source = str(runtime.get("source") or "")+ # Without an explicit ``provider`` this probe ran the startup pin and then the+ # configured fallback chain; when the chain only resolves at its tail, ``runtime``+ # stops there and the failure blames a provider the user never pinned (#124939).+ # Attribute failures to the pin (startup pin, else the config model pin).+ cfg_model = _load_cfg().get("model")+ pinned = (requested or startup_provider+ or (str(cfg_model.get("provider") or "").strip() if isinstance(cfg_model, dict) else ""))+ blamed = pinned or providerdef fail(error, src):- return {"ok": False, "provider": provider, "model": model,+ return {"ok": False, "provider": blamed, "model": model,"source": src, "error": error, **scoped}if (not provider_configured and provider == "bedrock"and source in {"iam-role", "aws-sdk-default-chain"}):@@ -458,7 +467,7 @@ def _(rid, params: dict) -> dict:api_key_text = "" if callable(api_key) else str(api_key or "").strip()if not (callable(api_key) or api_key_text in {"aws-sdk", "no-key-required"}or has_usable_secret(api_key_text) or bool(runtime.get("command"))):- return fail(f"No usable credentials found for {provider}.", runtime.get("source"))+ return fail(f"No usable credentials found for {blamed}.", runtime.get("source"))from hermes_cli.anon_auth import route_is_welcome_host# free_tier_route is keyed on the SELECTED route (the welcome host serves only nous/welcome), not# on profile state: a paid Nous key beside a free-tier identity must not read as free.