Skip to content

The agent that grows with you

fix(cli): stop _apply_featured() shortlisting user-defined providers

Muhammad Usamafdcae6debac4
diff --git a/hermes_cli/inventory.py b/hermes_cli/inventory.py
index 14587fc653d..6e19b78f72f 100644
--- a/hermes_cli/inventory.py
+++ b/hermes_cli/inventory.py
@@ -369,18 +369,33 @@ _FEATURED_PER_LAB = 5
def _apply_featured(rows: list[dict], *, metadata_config: dict | None = None) -> None:
- """Attach a ``featured_models`` shortlist to each aggregator row: newest ``_FEATURED_PER_LAB`` per
- vendor by models.dev ``release_date`` (ranked within the row, never vs. today, so it is stable);
- ties keep curated order. Non-aggregators get an empty list and keep top-N behaviour."""
+ """Attach a ``featured_models`` shortlist to each routing-aggregator row: newest
+ ``_FEATURED_PER_LAB`` per vendor by models.dev ``release_date`` (ranked within the row, never vs.
+ today, so it is stable); ties keep curated order. Non-aggregators — including every user-defined
+ row, whose ``models:`` list is an explicit allow-list — get an empty list and keep top-N
+ behaviour (#120217)."""
try:
from agent.models_dev import get_model_info
except Exception:
get_model_info = None # type: ignore[assignment]
+ # "Is this row an aggregator?" is answered canonically by is_routing_aggregator() — the same
+ # predicate _strip_aggregator_overlaps() uses. Deriving it from model-id spelling (does any id
+ # contain "/" and span >= 2 prefixes?) misread every Org/Model-shaped user provider as a
+ # multi-lab aggregator and hid the models its owner configured by hand (#120217).
+ try:
+ from hermes_cli.providers import is_routing_aggregator
+ except Exception:
+ is_routing_aggregator = None # type: ignore[assignment]
+
for row in rows:
slug = str(row.get("slug") or "").strip().lower()
models = row.get("models") or []
+ if row.get("is_user_defined") or not (is_routing_aggregator and is_routing_aggregator(slug)):
+ row["featured_models"] = []
+ continue
+
by_lab: dict[str, list[tuple[int, str, str]]] = {} # only multi-lab aggregators get a shortlist
for pos, model in enumerate(models):
lab = model.split("/", 1)[0] if "/" in model else ""
diff --git a/tests/hermes_cli/test_inventory.py b/tests/hermes_cli/test_inventory.py
index 10028df88da..348bdfe7e0c 100644
--- a/tests/hermes_cli/test_inventory.py
+++ b/tests/hermes_cli/test_inventory.py
@@ -790,4 +790,7 @@ def test_picker_metadata_uses_one_config_read_for_real_models_dev_lookups(tmp_pa
model: {"fast": False, "reasoning": model.startswith("openai/")}
for model in models[:3]
}
- assert large_row["featured_models"] == models
+ # #120217: ``providers.lab`` is a user-defined row, so its models: list is an explicit
+ # allow-list and is never shortlisted — the constant-read invariant above is now carried
+ # by the capabilities lookups alone.
+ assert large_row["featured_models"] == []
diff --git a/tests/hermes_cli/test_inventory_featured.py b/tests/hermes_cli/test_inventory_featured.py
new file mode 100644
index 00000000000..3104d6547b6
--- /dev/null
+++ b/tests/hermes_cli/test_inventory_featured.py
@@ -0,0 +1,124 @@
+"""Regression tests for the ``featured_models`` shortlist in hermes_cli.inventory.
+
+The shortlist exists to keep multi-lab *routing aggregators* (OpenRouter) from
+flooding the desktop picker's default-visible set. A user-defined provider's
+``models:`` list is an explicit allow-list: every configured model must stay
+default-visible, so such rows (and every other non-aggregator row) carry an
+empty ``featured_models`` and the frontend falls back to top-N behaviour
+(#120217).
+"""
+
+from hermes_cli.inventory import _apply_featured
+
+# The exact mixed-prefix allow-list from #120217's config.yaml reproduction.
+_MODELScope_MODELS = [
+ "Qwen/Qwen3.8-Flash-Next",
+ "Qwen/Qwen3.8-27B",
+ "Qwen/Qwen3-235B-A22B",
+ "Qwen/Qwen3.5-397B-A17B",
+ "Qwen/Qwen3.5-122B-A10B",
+ "Qwen/Qwen3-VL-235B-A22B-Instruct",
+ "Qwen/Qwen3-VL-8B-Instruct",
+ "Qwen/Qwen3-VL-8B-Thinking",
+ "deepseek-ai/DeepSeek-V4-Flash-0731",
+ "deepseek-ai/DeepSeek-V4-Pro",
+ "ZhipuAI/GLM-4.7-Flash",
+ "ZhipuAI/GLM-5.2",
+ "stepfun-ai/Step-3.7-Flash",
+]
+
+
+def test_user_defined_row_gets_no_featured_shortlist():
+ """A mixed-prefix user-defined provider must not be misread as a multi-lab
+ aggregator: ranking its explicit allow-list against models.dev release dates
+ hides models the user configured by hand — brand-new flagships lose the
+ "top 5 per lab" race whenever the catalog has no/older ``release_date``."""
+ row = {
+ "slug": "modelscope",
+ "name": "modelscope",
+ "is_current": True,
+ "is_user_defined": True,
+ "models": list(_MODELScope_MODELS),
+ "total_models": len(_MODELScope_MODELS),
+ }
+
+ _apply_featured([row])
+
+ assert row["featured_models"] == []
+ assert row["models"] == _MODELScope_MODELS # never trimmed, only shortlisted
+
+
+def test_custom_proxy_row_gets_no_featured_shortlist():
+ """``custom:*`` slugs are aggregators by :func:`is_routing_aggregator`, but a
+ user-defined row wearing one (a hand-written proxy) still owns an explicit
+ allow-list — ``is_user_defined`` wins over the slug shape."""
+ row = {
+ "slug": "custom:lab",
+ "name": "Lab",
+ "is_current": False,
+ "is_user_defined": True,
+ "models": ["openai/model-a", "anthropic/model-b", "openai/model-c"],
+ "total_models": 3,
+ }
+
+ _apply_featured([row])
+
+ assert row["featured_models"] == []
+
+
+def test_builtin_non_aggregator_row_gets_no_featured_shortlist():
+ """A first-party provider keeps top-N behaviour — the shortlist is an
+ aggregator-only affordance, per the docstring."""
+ row = {
+ "slug": "anthropic",
+ "name": "Anthropic",
+ "is_current": False,
+ "is_user_defined": False,
+ "models": ["claude-opus-5", "claude-sonnet-5"],
+ "total_models": 2,
+ }
+
+ _apply_featured([row])
+
+ assert row["featured_models"] == []
+
+
+def test_builtin_flat_namespace_reseller_gets_no_featured_shortlist():
+ """Flat-namespace resellers are first-party catalogs, not routing
+ aggregators, so they are not featured either."""
+ row = {
+ "slug": "opencode-go",
+ "name": "OpenCode Go",
+ "is_current": False,
+ "is_user_defined": False,
+ "models": [f"lab{i % 3}/model-{i}" for i in range(12)],
+ "total_models": 12,
+ }
+
+ _apply_featured([row])
+
+ assert row["featured_models"] == []
+
+
+def test_builtin_routing_aggregator_keeps_featured_shortlist():
+ """The affordance survives: OpenRouter's row still carries a curated
+ shortlist so its huge catalog does not flood the default-visible set."""
+ row = {
+ "slug": "openrouter",
+ "name": "OpenRouter",
+ "is_current": False,
+ "is_user_defined": False,
+ "models": [f"lab{i % 3}/model-{i}" for i in range(12)],
+ "total_models": 12,
+ }
+
+ _apply_featured([row])
+
+ assert row["featured_models"]
+ assert set(row["featured_models"]) <= set(row["models"])
+ # Top-_FEATURED_PER_LAB per lab, row order preserved.
+ assert len(row["featured_models"]) <= 3 * 5
+ order = {m: i for i, m in enumerate(row["models"])}
+ assert [order[m] for m in row["featured_models"]] == sorted(
+ order[m] for m in row["featured_models"]
+ )