Skip to content

The agent that grows with you

fix(models_validate): a profile's own catalog endpoint decides, not the generic /models listing

Konstantin Khlopkov57a3bbbcc109
diff --git a/hermes_cli/models_validate.py b/hermes_cli/models_validate.py
index 6290775e7c6..5a35dc6264c 100644
--- a/hermes_cli/models_validate.py
+++ b/hermes_cli/models_validate.py
@@ -469,12 +469,40 @@ def _validate_managed_local(req: _Request) -> Optional[dict[str, Any]]:
return None
+def _profile_owned_catalog(normalized: str) -> Optional[list[str]]:
+ """The profile's catalog when the profile serves it from an endpoint of its own —
+ ``models_url`` pointing somewhere other than the generic ``{base_url}/models``.
+ For such relays that generic listing is a different product line (#101705), so it
+ must not validate models the profile's catalog excludes (#116667). ``None`` when
+ the profile has no separate endpoint (a bare ``fetch_models`` override may just
+ re-shape the generic listing) or its catalog is unavailable — those keep the
+ generic listing as their validator."""
+ from providers import get_provider_profile
+
+ profile = get_provider_profile(normalized)
+ if profile is None or not profile.models_url:
+ return None
+ generic = (profile.base_url or "").rstrip("/") + "/models"
+ if profile.models_url.rstrip("/") == generic:
+ return None
+ return _static_catalog(normalized) or None
+
+
def _validate_live_listing(req: _Request) -> Optional[dict[str, Any]]:
"""Generic live /v1/models probe. Returns None when the API was unreachable (the caller then
tries Bedrock discovery / the curated catalog). A profile that owns its catalog is validated
against that catalog (``provider_model_ids`` — the picker's list) before the generic listing."""
from hermes_cli import models as _m
+ owned = _profile_owned_catalog(req.normalized)
+ if owned is not None:
+ # The catalog endpoint the profile declares decides: a miss there is a reject, never an
+ # acceptance by the generic listing, which for such relays lists a different product line.
+ match = _match_in_catalog(req.lookup, owned, suggest_query=req.requested)
+ if match.exact:
+ return _accept()
+ return _reject(
+ f"Model `{req.requested}` was not found in this provider's catalog.{match.suggestion_text}")
if _profile_owns_catalog(req.normalized) and _match_in_catalog(req.lookup, _static_catalog(req.normalized)).exact:
return _accept()
api_models = _m.fetch_api_models(req.api_key, req.base_url)
diff --git a/tests/hermes_cli/test_model_validation.py b/tests/hermes_cli/test_model_validation.py
index 777bc0b7acb..d06ff339c55 100644
--- a/tests/hermes_cli/test_model_validation.py
+++ b/tests/hermes_cli/test_model_validation.py
@@ -872,3 +872,51 @@ class TestValidateCustomUnreachableFallback:
# The unreachable-listing wording is unchanged.
unreachable = self._validate("kimi-k3", "kimi-coding", models=None, api_mode="anthropic_messages")
assert "do not implement GET /v1/models" in unreachable["message"]
+
+
+# -- validate — profile-owned catalog is authoritative (#116667) ----------------
+
+class TestProfileCatalogAuthoritative:
+ """A profile that points ``models_url`` at its own catalog endpoint (relay re-shape,
+ #101705) owns validation: the generic ``{base_url}/models`` listing may expose a
+ different product line that this deployment cannot serve, so a miss in the
+ profile-owned catalog must not be turned into an acceptance by that generic
+ listing (#116667). Unavailable/empty profile catalogs keep the generic fallback."""
+
+ @pytest.fixture
+ def relay_profile(self, monkeypatch):
+ import providers
+ from providers.base import ProviderProfile
+
+ profile = ProviderProfile(
+ name="relay-owned-catalog", auth_type="api_key",
+ env_vars=("RELAY_TEST_KEY",), base_url="https://relay.example.invalid/v1",
+ models_url="https://relay.example.invalid/catalog",
+ fallback_models=("plan/model-1",),
+ )
+ monkeypatch.setitem(providers._REGISTRY, profile.name, profile)
+ return profile
+
+ def test_model_only_in_generic_listing_is_rejected(self, relay_profile):
+ """Profile catalog: ["plan/model-1"]; generic /models: ["other-vendor/model-a"];
+ requested "other-vendor/model-a" — the generic hit must not accept it."""
+ result = _validate(
+ "other-vendor/model-a", "relay-owned-catalog", api_models=["other-vendor/model-a"])
+ assert result["accepted"] is False
+ assert result["persist"] is False
+ assert "plan/model-1" in result["message"]
+
+ def test_profile_catalog_hit_still_accepts(self, relay_profile):
+ result = _validate("plan/model-1", "relay-owned-catalog", api_models=["other-vendor/model-a"])
+ assert result["accepted"] is True
+ assert result["recognized"] is True
+
+ def test_unavailable_profile_catalog_keeps_generic_fallback(self, relay_profile):
+ """The profile's own catalog unreachable/empty (e.g. no credentials yet):
+ the generic listing stays the validator, as before (#116667's carve-out)."""
+ with patch("hermes_cli.models.fetch_api_models", return_value=["other-vendor/model-a"]), \
+ patch("hermes_cli.models.provider_model_ids", return_value=[]):
+ result = validate_requested_model(
+ "other-vendor/model-a", "relay-owned-catalog", api_key="k")
+ assert result["accepted"] is True
+ assert result["recognized"] is True