Skip to content

The agent that grows with you

fix(desktop): skip Anthropic frontier tiers in silent default picker

heyclos92ad572740fa
diff --git a/hermes_cli/models.py b/hermes_cli/models.py
index 9d922ba0850..435e5e8b121 100644
--- a/hermes_cli/models.py
+++ b/hermes_cli/models.py
@@ -454,11 +454,63 @@ def get_preferred_silent_default_model(provider: str = "openrouter") -> str:
return PREFERRED_SILENT_DEFAULT_MODEL
+def _is_anthropic_frontier_tier(model_id: Optional[str]) -> bool:
+ """Return True for Anthropic frontier-tier models (Opus + Fable).
+
+ Both tiers are the priciest Anthropic offerings and are unsafe defaults
+ for a freshly-authenticated provider picker or any other silent fallback:
+ paid users landing on a frontier tier have no opportunity to opt out
+ before the choice pins their main model and inherits into every cron job
+ that doesn't override ``model.provider``.
+
+ Anchored on the ``claude-`` family prefix, then the ``opus-`` / ``fable-``
+ tier token (after vendor-strip and lowercase normalization), so the
+ predicate survives future Anthropic releases (``claude-opus-5-0``,
+ ``claude-fable-6``, etc.) and rejects community / distill models whose
+ slug merely *contains* the substring ``opus`` (e.g. ``qwopus3.6-27b-coder``).
+ Sonnet and Haiku are deliberately NOT classified as frontier here — they
+ remain reasonable auto-default candidates.
+ """
+ raw = _strip_vendor_prefix(str(model_id or ""))
+ base = raw.split(":")[0].lower()
+ if not base.startswith("claude-"):
+ return False
+ return ("opus-" in base) or ("fable-" in base)
+
+
def pick_silent_default_model(model_ids: list[str], provider: str = "openrouter") -> str:
- """Catalog-labeled default when ``model_ids`` carries it, else the first entry, else "". Used by
- every surface that must choose a model without an interactive picker."""
+ """Pick a cost-safe silent default from an available-models list.
+
+ Shared policy for every surface that must choose a model on the user's
+ behalf without an interactive confirmation (GUI onboarding
+ recommended-default, empty-model runtime fallback, provider-set-but-
+ model-missing resolution):
+
+ 1. If the catalog-labeled preferred default (see
+ :func:`get_preferred_silent_default_model`) is present in
+ ``model_ids``, return it.
+ 2. Else, return the first entry that is NOT an Anthropic frontier tier
+ (Opus / Fable — see :func:`_is_anthropic_frontier_tier`). Catalog
+ ordering is preserved, so a freshly-released cheaper model still
+ wins over a leftover Sonnet.
+ 3. Else (every entry is a frontier tier), return ``model_ids[0]`` so the
+ picker is never empty — defensive last resort only.
+ 4. Else (empty list), return ``\"\"``.
+
+ This hardened fallback closes the hole where a Portal-augmented list
+ that didn't carry the catalog label fell through to ``model_ids[0]``
+ (currently ``anthropic/claude-fable-5``) and billed the most expensive
+ Anthropic flagship for traffic the user never opted into.
+ """
+ if not model_ids:
+ return ""
preferred = get_preferred_silent_default_model(provider)
- return preferred if preferred in model_ids else (model_ids[0] if model_ids else "")
+ if preferred in model_ids:
+ return preferred
+ non_frontier = [mid for mid in model_ids if not _is_anthropic_frontier_tier(mid)]
+ if non_frontier:
+ return non_frontier[0]
+ return model_ids[0]
def recommended_nous_default_model() -> dict[str, Any]:
diff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.py
index b58279c00ab..4543bb78296 100644
--- a/tests/hermes_cli/test_web_server.py
+++ b/tests/hermes_cli/test_web_server.py
@@ -2857,6 +2857,42 @@ CONFIG_SCHEMA = ProviderConfigSchema(
assert payload["messages"][-1]["content"] == "msg 500"
# Transfer projection: archived rows ride along with their flags (import re-archives them).
assert calls == [(500, 0, True), (500, 500, True)]
+ def test_pick_silent_default_model_empty_list_returns_empty_string(self):
+ """Empty model list must return \"\" so the caller degrades gracefully."""
+ from hermes_cli.models import pick_silent_default_model
+
+ assert pick_silent_default_model([], "nous") == ""
+ assert pick_silent_default_model([], "") == ""
+ assert pick_silent_default_model([], "openrouter") == ""
+
+ def test_is_anthropic_frontier_tier(self):
+ """Unit coverage for the frontier-tier predicate used by the cost-safe
+ silent policy. Anchored on the claude- prefix so community/distill
+ slugs whose lowercase form merely contains opus are rejected."""
+ from hermes_cli.models import _is_anthropic_frontier_tier
+
+ # Opus + Fable, dash + dot, vendor-prefixed, colon-suffixed.
+ assert _is_anthropic_frontier_tier("claude-opus-4-8") is True
+ assert _is_anthropic_frontier_tier("claude-opus-4.8") is True
+ assert _is_anthropic_frontier_tier("anthropic/claude-opus-4.8") is True
+ assert _is_anthropic_frontier_tier("claude-fable-5") is True
+ assert _is_anthropic_frontier_tier("anthropic/claude-fable-5") is True
+ assert _is_anthropic_frontier_tier("anthropic/claude-fable-5:thinking") is True
+ assert _is_anthropic_frontier_tier("claude-opus-5-0") is True # forward-compat
+
+ # Sonnet / Haiku remain non-frontier.
+ assert _is_anthropic_frontier_tier("claude-sonnet-5") is False
+ assert _is_anthropic_frontier_tier("claude-haiku-4.5") is False
+ assert _is_anthropic_frontier_tier("anthropic/claude-sonnet-4.6") is False
+
+ # Community / distill / non-Anthropic must not match.
+ assert _is_anthropic_frontier_tier("qwopus3.6-27b-coder") is False
+ assert _is_anthropic_frontier_tier("jackrong/qwopus3.6-27b-coder") is False
+ assert _is_anthropic_frontier_tier("openai/gpt-5.5") is False
+ assert _is_anthropic_frontier_tier("z-ai/glm-5.2") is False
+ assert _is_anthropic_frontier_tier("") is False
+ assert _is_anthropic_frontier_tier(None) is False
+
# ---------------------------------------------------------------------------
@@ -5954,3 +5990,133 @@ class TestSubmittedCustomEndpointSurvivesAssignment:
assert applied["base_url"] == "https://api.anthropic.com"
assert applied["api_mode"] == "anthropic_messages"
assert applied["api_key"] == "submitted-key"
+
+
+
+class TestNousRecommendedDefaultCostSafePolicy:
+ """Paid-tier Nous recommended default must never land on an Anthropic frontier
+ tier (Opus / Fable) — the user gets no opt-out before it pins their main model
+ (#51491). Regression tests from PR #51493."""
+
+ def test_recommended_default_nous_paid_uses_curated_default(self, monkeypatch):
+ """A paid Nous user gets the cost-safe silent default from the list.
+
+ With no preferred catalog label present in the curated list and no
+ Anthropic frontier entries, the first curated entry is selected.
+ """
+ import hermes_cli.models as models_mod
+ from hermes_cli.web_routers.models import get_recommended_default_model
+
+ monkeypatch.setattr(models_mod, "get_curated_nous_model_ids", lambda: ["top/model", "other/model"])
+ import hermes_cli.models_pricing as mp
+ monkeypatch.setattr(mp, "get_pricing_for_provider", lambda provider: {})
+ monkeypatch.setattr(models_mod, "check_nous_free_tier", lambda *, force_fresh=False: False)
+ monkeypatch.setattr(
+ models_mod, "union_with_portal_paid_recommendations",
+ lambda ids, pricing, url: (ids, pricing),
+ )
+ # Keep the catalog preferred out of this list so we exercise the
+ # non-frontier fallback rather than the preferred-hit branch.
+ monkeypatch.setattr(
+ models_mod, "get_preferred_silent_default_model",
+ lambda provider="openrouter": "z-ai/glm-5.2",
+ )
+
+ result = get_recommended_default_model(provider="nous")
+ assert result["provider"] == "nous"
+ assert result["model"] == "top/model"
+ assert result["free_tier"] is False
+
+ @pytest.mark.parametrize(
+ "model_ordering, expected_model",
+ [
+ # Opus-first ordering (historical PR-branch catalog shape).
+ (
+ [
+ "anthropic/claude-opus-4.8",
+ "anthropic/claude-sonnet-5",
+ "anthropic/claude-haiku-4.5",
+ ],
+ "anthropic/claude-sonnet-5",
+ ),
+ # Fable-first ordering (current origin/main catalog shape).
+ (
+ [
+ "anthropic/claude-fable-5",
+ "anthropic/claude-opus-4.8",
+ "anthropic/claude-sonnet-5",
+ "anthropic/claude-haiku-4.5",
+ ],
+ "anthropic/claude-sonnet-5",
+ ),
+ # Preferred silent default present in the list always wins,
+ # independent of relative ordering / frontiers.
+ (
+ [
+ "anthropic/claude-fable-5",
+ "anthropic/claude-opus-4.8",
+ "z-ai/glm-5.2",
+ "anthropic/claude-sonnet-5",
+ ],
+ "z-ai/glm-5.2",
+ ),
+ ],
+ ids=["opus_first", "fable_first_main", "override_beats_ordering"],
+ )
+ def test_recommended_default_nous_paid_cost_safe_policy(
+ self, monkeypatch, model_ordering, expected_model,
+ ):
+ """Regression for PR #51493 maintainer feedback (Teknium + DavidMetcalfe).
+
+ The interactive Nous recommended default must use the shared
+ cost-safe silent policy: preferred catalog label when present,
+ else first non-frontier (Opus / Fable) entry. Covers both the
+ current Fable-first catalog and a future Opus-first catalog.
+ """
+ import hermes_cli.models as models_mod
+ from hermes_cli.web_routers.models import get_recommended_default_model
+
+ monkeypatch.setattr(
+ models_mod, "get_curated_nous_model_ids", lambda: list(model_ordering),
+ )
+ import hermes_cli.models_pricing as mp
+ monkeypatch.setattr(mp, "get_pricing_for_provider", lambda provider: {})
+ monkeypatch.setattr(models_mod, "check_nous_free_tier", lambda *, force_fresh=False: False)
+ monkeypatch.setattr(
+ models_mod, "union_with_portal_paid_recommendations",
+ lambda ids, pricing, url: (ids, pricing),
+ )
+ monkeypatch.setattr(
+ models_mod, "get_preferred_silent_default_model",
+ lambda provider="openrouter": "z-ai/glm-5.2",
+ )
+
+ result = get_recommended_default_model(provider="nous")
+ assert result["provider"] == "nous"
+ assert result["model"] == expected_model
+ assert result["free_tier"] is False
+
+ def test_recommended_default_nous_paid_falls_back_when_all_frontier(self, monkeypatch):
+ """If every curated entry is a frontier tier (Opus / Fable), fall
+ back to the head of the list so the picker is never empty."""
+ import hermes_cli.models as models_mod
+ from hermes_cli.web_routers.models import get_recommended_default_model
+
+ monkeypatch.setattr(
+ models_mod, "get_curated_nous_model_ids",
+ lambda: ["anthropic/claude-fable-5", "anthropic/claude-opus-4.8"],
+ )
+ import hermes_cli.models_pricing as mp
+ monkeypatch.setattr(mp, "get_pricing_for_provider", lambda provider: {})
+ monkeypatch.setattr(models_mod, "check_nous_free_tier", lambda *, force_fresh=False: False)
+ monkeypatch.setattr(
+ models_mod, "union_with_portal_paid_recommendations",
+ lambda ids, pricing, url: (ids, pricing),
+ )
+ monkeypatch.setattr(
+ models_mod, "get_preferred_silent_default_model",
+ lambda provider="openrouter": "z-ai/glm-5.2",
+ )
+
+ result = get_recommended_default_model(provider="nous")
+ assert result["model"] == "anthropic/claude-fable-5"