Skip to content

The agent that grows with you

fix: cache_only Ollama Cloud read no longer rewrites the disk cache

teknium1fba4cb1cb3f4
diff --git a/hermes_cli/models_local.py b/hermes_cli/models_local.py
index b11877f05f6..5597f1f953b 100644
--- a/hermes_cli/models_local.py
+++ b/hermes_cli/models_local.py
@@ -660,8 +660,9 @@ def fetch_ollama_cloud_models(
cache_only: bool = False,
) -> list[str]:
"""Ollama Cloud models: fresh disk cache (< 1h, unless force_refresh) → live ``/v1/models``
- (freshest) merged with models.dev additions (deduped, live first) → stale cache → ``[]``.
- ``cache_only`` (GUI read path) never runs the 8s network probe. Never None."""
+ (freshest) merged with models.dev additions (deduped, live first) → stale cache → models.dev
+ only → ``[]``. ``cache_only`` (GUI read path) never runs the 8s network probe and never writes
+ the disk cache. Never None."""
from hermes_cli.models import fetch_api_models
if not force_refresh:
cached = _load_ollama_cloud_cache()
@@ -684,9 +685,12 @@ def fetch_ollama_cloud_models(
for m in [*live_models, *(_strip_ollama_cloud_suffix(m) for m in mdev_models)]:
if m and m not in merged:
merged.append(m)
- if merged:
+ if live_models:
+ # Persist only a result that included the live catalog: writing the models.dev-only list here
+ # (cache_only, or a failed probe) would stamp it fresh, drop the live-only ids, and make the
+ # next non-cache_only call serve that trimmed list for an hour instead of probing.
_save_ollama_cloud_cache(merged)
return merged
stale = _load_ollama_cloud_cache(ignore_ttl=True)
- return stale["models"] if stale is not None else []
+ return stale["models"] if stale is not None else merged
diff --git a/tests/hermes_cli/test_ollama_cloud_provider.py b/tests/hermes_cli/test_ollama_cloud_provider.py
index 416e9bc9ac1..e27bf7482b1 100644
--- a/tests/hermes_cli/test_ollama_cloud_provider.py
+++ b/tests/hermes_cli/test_ollama_cloud_provider.py
@@ -195,6 +195,31 @@ class TestOllamaCloudMergedDiscovery:
assert result == ["glm-5"]
+ def test_cache_only_serves_stale_cache_without_rewriting_disk(self, tmp_path, monkeypatch):
+ """cache_only (GUI read path) must not persist a live-less list: that stamps it fresh, drops the
+ live-only ids, and makes the next probing call serve the trimmed list for an hour."""
+ import json
+ import time
+ from hermes_cli.models import fetch_ollama_cloud_models
+
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ monkeypatch.setenv("OLLAMA_API_KEY", "test-key")
+ cache = tmp_path / "ollama_cloud_models_cache.json"
+ cache.write_text(json.dumps({"models": ["live-only", "shared"], "cached_at": time.time() - 7200}))
+ before = (cache.read_text(), cache.stat().st_mtime_ns)
+
+ mock_mdev = {"ollama-cloud": {"models": {"shared": {"tool_call": True}, "mdev-only": {"tool_call": True}}}}
+ with patch("agent.models_dev.fetch_models_dev", return_value=mock_mdev), \
+ patch("hermes_cli.models.fetch_api_models", side_effect=AssertionError("network probe ran")):
+ result = fetch_ollama_cloud_models(cache_only=True)
+
+ assert result == ["live-only", "shared"]
+ assert (cache.read_text(), cache.stat().st_mtime_ns) == before
+
+ with patch("agent.models_dev.fetch_models_dev", return_value=mock_mdev), \
+ patch("hermes_cli.models.fetch_api_models", return_value=["live-only", "shared", "new-live"]) as live:
+ assert fetch_ollama_cloud_models() == ["live-only", "shared", "new-live", "mdev-only"]
+ assert live.called # the stale cache still triggers a probe on the next non-cache_only call