The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(setup): profile-owned catalog keeps the curated list when the live fetch fails
kshitijk4poor7fec7cf5941f
diff --git a/hermes_cli/model_setup_flows.py b/hermes_cli/model_setup_flows.pyindex 458ff761568..8f39d8d6f1a 100644--- a/hermes_cli/model_setup_flows.py+++ b/hermes_cli/model_setup_flows.py@@ -872,7 +872,7 @@ def _api_key_provider_model_list(provider_id: str, pconfig, existing_key: str, k``models._profile_live_catalog``; generic /models probe for unregistered providers).Providers in ``_SPECIAL_MODEL_LISTS`` have their own resolution."""from hermes_cli.config import get_env_value- from hermes_cli.models import _PROVIDER_MODELS, fetch_api_models, merge_profile_catalog+ from hermes_cli.models import _PROVIDER_MODELS, fetch_api_models, probe_profile_catalogcurated = _PROVIDER_MODELS.get(provider_id, [])api_key_for_probe = existing_key or (get_env_value(key_env) if key_env else "")@@ -892,18 +892,15 @@ def _api_key_provider_model_list(provider_id: str, pconfig, existing_key: str, kfrom providers import get_provider_profileprofile = get_provider_profile(provider_id)if profile is not None:- # The profile owns endpoint (models_url), headers and response shape; a failing catalog- # degrades to fallback_models the same way the picker does.- try:- live_models = profile.fetch_models(api_key=api_key_for_probe, base_url=effective_base)- except Exception:- live_models = None- model_list = merge_profile_catalog(provider_id, profile, live_models) or []- if live_models:- _report_live_models(model_list, f"{pconfig.name} API")- else:- _show_curated(model_list)- return model_list+ # The profile owns endpoint (models_url), headers and response shape. Same probe as the+ # ``/model`` picker; when neither live nor fallback_models yields rows, the curated+ # ``_PROVIDER_MODELS`` row still applies (built-in providers with a short curated list).+ model_list = probe_profile_catalog(provider_id, profile, api_key_for_probe, effective_base)+ if model_list:+ _report_live_models(model_list, f"{pconfig.name} catalog")+ return model_list+ _show_curated(curated)+ return list(curated)live_models = fetch_api_models(api_key_for_probe, effective_base)if live_models and len(live_models) >= len(curated):_report_live_models(live_models, f"{pconfig.name} API")diff --git a/hermes_cli/models.py b/hermes_cli/models.pyindex 153356a6b17..b3712cbd1fd 100644--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@ -1536,11 +1536,16 @@ def _profile_live_catalog(normalized: str) -> Optional[list[str]]:if not (profile.auth_type == "api_key" and profile.base_url):return list(profile.fallback_models) or Noneapi_key, base_url = _api_key_credentials(normalized)+ return probe_profile_catalog(normalized, profile, api_key, base_url or profile.base_url or None)+++def probe_profile_catalog(normalized: str, profile, api_key: Optional[str], base_url: Optional[str]) -> Optional[list[str]]:+ """``profile.fetch_models`` gated on a key (no key → no doomed probe) and merged with the curated+ list; a raising catalog override degrades like a None return — fallback_models, not an empty picker."""live = Noneif api_key:- # A raising catalog override degrades like a None return: fallback_models, not an empty picker.try:- live = profile.fetch_models(api_key=api_key, base_url=base_url or profile.base_url or None)+ live = profile.fetch_models(api_key=api_key, base_url=base_url)except Exception:live = Nonereturn merge_profile_catalog(normalized, profile, live)diff --git a/tests/hermes_cli/test_setup_provider_catalog.py b/tests/hermes_cli/test_setup_provider_catalog.pyindex 491bc61a6be..ede116cbf7b 100644--- a/tests/hermes_cli/test_setup_provider_catalog.py+++ b/tests/hermes_cli/test_setup_provider_catalog.py@@ -144,3 +144,29 @@ def test_switch_validation_trusts_profile_owned_catalog(monkeypatch):kw = dict(provider=profile.name, api_key="synthetic-test-key", base_url=profile.base_url)assert models_validate.validate_requested_model("plan/model-1", **kw)["accepted"] is Trueassert models_validate.validate_requested_model("plan/model-9", **kw)["accepted"] is False+++def test_setup_keeps_curated_list_when_profile_catalog_is_down_and_declares_no_fallback(monkeypatch):+ """A built-in API-key provider whose profile has no ``fallback_models`` and whose live catalog is+ unreachable still offers its curated ``_PROVIDER_MODELS`` row at first-time setup instead of an+ empty picker."""+ from types import SimpleNamespace++ import providers+ from providers.base import ProviderProfile+ from hermes_cli import model_setup_flows as flows, models++ class DownProfile(ProviderProfile):+ def fetch_models(self, *, api_key=None, base_url=None, timeout=8.0):+ raise ConnectionError("catalog down")++ profile = DownProfile(name="scout-curated-only", auth_type="api_key", env_vars=("SCOUT_CURATED_KEY",),+ base_url="https://down.example.invalid/v1")+ monkeypatch.setitem(providers._REGISTRY, profile.name, profile)+ monkeypatch.setitem(models._PROVIDER_MODELS, profile.name, ["curated-a", "curated-b"])+ monkeypatch.setattr(flows, "_models_dev_merged", lambda *_: [])++ setup_rows = flows._api_key_provider_model_list(+ profile.name, SimpleNamespace(name="Down"), "synthetic-test-key", "", profile.base_url)++ assert setup_rows == ["curated-a", "curated-b"]