From a74e76632cce62ad6948cf7e4e6b27629d66d147 Mon Sep 17 00:00:00 2001 From: finn763 <165816600+finn763@users.noreply.github.com> Date: Wed, 9 Sep 2026 18:15:11 +0530 Subject: [PATCH] perf(picker): read Nous pricing cache-only when building the picker row MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _nous_picker_model_ids only uses the ids the Portal unions append — both unions discard the pricing map (`model_ids, _ = union_with_portal_*`) — yet it called get_pricing_for_provider("nous") without cached_only, so a cold pricing cache paid a full /v1/models round-trip (network timeout on a slow Portal) on the picker-open path for nothing. Pass cached_only=True; the background pricing prewarm (#101685) fills the same cache for later opens. Re-derived from #102099 by @finn763: the original patched hermes_cli/model_switch.py, which 3b1ecfc0a1 decomposed; the live call site is hermes_cli/model_switch_providers.py. Based on #102099 by @finn763. --- hermes_cli/model_switch_providers.py | 4 +++- .../test_nous_picker_pricing_cached_only.py | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/hermes_cli/test_nous_picker_pricing_cached_only.py diff --git a/hermes_cli/model_switch_providers.py b/hermes_cli/model_switch_providers.py index 0d1c408b0f..00014ab4e2 100644 --- a/hermes_cli/model_switch_providers.py +++ b/hermes_cli/model_switch_providers.py @@ -416,7 +416,9 @@ def _nous_picker_model_ids(curated: dict, force_fresh_nous_tier: bool) -> list: union_with_portal_paid_recommendations, ) from hermes_cli.auth import get_provider_auth_state - pricing = get_pricing_for_provider("nous") or {} + # Cache-only: both Portal unions below discard the pricing map (``model_ids, _ = ...``); + # only the appended ids matter, so a live catalog fetch here buys nothing but latency. + pricing = get_pricing_for_provider("nous", cached_only=True) or {} try: portal = (get_provider_auth_state("nous") or {}).get("portal_base_url", "") or "" except Exception: diff --git a/tests/hermes_cli/test_nous_picker_pricing_cached_only.py b/tests/hermes_cli/test_nous_picker_pricing_cached_only.py new file mode 100644 index 0000000000..12a5609ecd --- /dev/null +++ b/tests/hermes_cli/test_nous_picker_pricing_cached_only.py @@ -0,0 +1,22 @@ +"""The Nous picker row never starts a pricing fetch: the picker only uses the ids the Portal +unions append, and a cold pricing cache must not hold the picker open (salvage of #102099).""" + +import hermes_cli.models_pricing as mp +from hermes_cli import model_switch_providers as msp + + +def test_nous_picker_model_ids_reads_pricing_cache_only(monkeypatch): + seen: list[bool] = [] + + def fake_pricing(provider, *, force_refresh=False, cached_only=False): + seen.append(cached_only) + return {} + + monkeypatch.setattr(mp, "get_pricing_for_provider", fake_pricing) + # Keep the sibling Portal calls off the network; only the pricing call shape is under test. + monkeypatch.setattr("hermes_cli.models.check_nous_free_tier", lambda **kw: False) + monkeypatch.setattr("hermes_cli.models.fetch_nous_recommended_models", lambda *a, **kw: None) + monkeypatch.setattr(mp, "nous_policy_allowed_ids", lambda **kw: None) + + assert msp._nous_picker_model_ids({"nous": ["nous/a"]}, False) == ["nous/a"] + assert seen == [True]