Skip to content

The agent that grows with you

refactor(models): cache-only OpenRouter read parses the disk copy once; test nits

kshitijk4poorb916b3c1306a
diff --git a/hermes_cli/model_switch_providers.py b/hermes_cli/model_switch_providers.py
index 4d2ab8e2dd8..ff766cbdb1c 100644
--- a/hermes_cli/model_switch_providers.py
+++ b/hermes_cli/model_switch_providers.py
@@ -1309,8 +1309,8 @@ def list_picker_providers(
OpenRouter's list is replaced with :func:`hermes_cli.models.fetch_openrouter_models` (curated
snapshot filtered against the live catalog) and rows left with no models are dropped — except
custom endpoints, where the user may supply their own model set through config.
- ``non_blocking_catalogs`` makes every catalog read cache-only (OpenRouter's included, stale disk
- copy over a live GET) with a background warm; the ``probe_*`` flags are forwarded unchanged."""
+ ``non_blocking_catalogs`` makes every catalog read cache-only: provider catalogs warm in the
+ background, OpenRouter's stale disk copy is served as-is; the ``probe_*`` flags are forwarded."""
from hermes_cli.model_switch import list_authenticated_providers
from hermes_cli.models import fetch_openrouter_models
providers = list_authenticated_providers(
diff --git a/hermes_cli/models.py b/hermes_cli/models.py
index 32b575dbb38..b8091b45789 100644
--- a/hermes_cli/models.py
+++ b/hermes_cli/models.py
@@ -585,12 +585,13 @@ def fetch_openrouter_models(
# Cold process: serve from the persisted disk cache when fresh so the
# picker doesn't re-download the full ~686KB catalog on every open.
if not force_refresh:
- disk = _read_openrouter_catalog_disk()
+ disk = _read_openrouter_catalog_disk(allow_stale=cache_only)
if disk:
- profile_slot_set(_me, "_openrouter_catalog_cache", disk)
+ if not cache_only: # a stale copy is served, never memoized as fresh
+ profile_slot_set(_me, "_openrouter_catalog_cache", disk)
return list(disk)
if cache_only:
- return list(_read_openrouter_catalog_disk(allow_stale=True) or OPENROUTER_MODELS)
+ return list(OPENROUTER_MODELS)
# Remote catalog manifest first, in-repo snapshot when unreachable; the live /v1/models filter
# (tool support, free pricing) is applied on top either way.
diff --git a/tests/hermes_cli/test_list_picker_providers.py b/tests/hermes_cli/test_list_picker_providers.py
index 5e03d3dfd6d..657926230e1 100644
--- a/tests/hermes_cli/test_list_picker_providers.py
+++ b/tests/hermes_cli/test_list_picker_providers.py
@@ -246,21 +246,19 @@ def test_non_blocking_listing_opens_no_socket(monkeypatch, tmp_path):
"""#74003: ``non_blocking_catalogs=True`` must not run a single live catalog probe in the calling
thread — not the per-provider ``/models`` prefetch and not OpenRouter's curated-catalog GET —
even with several credentialed providers and an empty on-disk cache."""
- import json
-
import hermes_cli.models as models_mod
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
for key in ("OPENAI_API_KEY", "ANTHROPIC_API_KEY", "DEEPSEEK_API_KEY", "GROQ_API_KEY",
"MISTRAL_API_KEY", "XAI_API_KEY", "OPENROUTER_API_KEY"):
monkeypatch.setenv(key, "dummy")
- (tmp_path / "provider_models_cache.json").write_text(json.dumps({}), encoding="utf-8")
+ (tmp_path / "provider_models_cache.json").write_text("{}", encoding="utf-8")
monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda *a, **k: {})
live: list[str] = []
def _live_probe(*args, **kwargs):
- live.append(str(args[0]) if args else "openrouter-catalog")
+ live.append((args, kwargs))
return []
monkeypatch.setattr(models_mod, "provider_model_ids", _live_probe)