Skip to content

The agent that grows with you

fix: follow-up for salvaged PR #95943

Tekniume2037a6c710d
diff --git a/hermes_cli/models.py b/hermes_cli/models.py
index 59e193a2d99..b545ffea653 100644
--- a/hermes_cli/models.py
+++ b/hermes_cli/models.py
@@ -572,11 +572,12 @@ _PROVIDER_MODELS: dict[str, list[str]] = {
# tier, so a relay-delisted model stops appearing in the picker and a
# newly-live one becomes selectable without a release. This floor keeps the
# picker populated when the relay is unreachable. Note: this floor may lag
- # the live relay (e.g. x-preview-f-free was delisted 2026-08-26) — that is
- # intentional; the live revalidation is the source of truth when reachable.
- # deepseek-v4-flash-free and mimo-v2.5-free are back on the live list.
+ # the live relay — that is intentional; the live revalidation is the
+ # source of truth when reachable. Known-delisted models are REMOVED from
+ # the floor (x-preview-f-free delisted 2026-08-26 — offline fallback must
+ # not offer a model that 401s). deepseek-v4-flash-free and mimo-v2.5-free
+ # are back on the live list.
"opencode-free": [
- "x-preview-f-free", # "Ox Alpha" stealth model — free, 1M ctx, ZDR
"deepseek-v4-flash-free",
"hy3-free",
"mimo-v2.5-free",
@@ -4113,7 +4114,9 @@ def provider_model_ids(provider: Optional[str], *, force_refresh: bool = False)
# empty. This is what keeps a relay-delisted model (e.g. x-preview-f-free)
# from lingering in the picker until a release re-syncs the snapshot.
if normalized == "opencode-free":
- return _fetch_opencode_free_models() or list(_PROVIDER_MODELS.get(normalized, []))
+ return _fetch_opencode_free_models(
+ force_refresh=force_refresh
+ ) or list(_PROVIDER_MODELS.get(normalized, []))
# ── Profile-based generic live fetch (all simple api-key providers) ──
# Handles any provider registered in providers/ with auth_type="api_key".
@@ -5475,6 +5478,14 @@ _OPENCODE_KEYLESS_EXTRA_SLUGS = frozenset({"big-pickle"})
# subscription twin of the Zen keyless Ox Alpha (verified 2026-08-21).
_OPENCODE_FREE_KEYED_SUFFIX_MODELS = frozenset({"ox-alpha-free"})
+# In-process memo for _fetch_opencode_free_models(): (fetched_at, ids-or-None).
+# Direct provider_model_ids("opencode-free") callers (model validation, healing)
+# can run several times per resolution — without this each would block on a
+# network round-trip. Failures are memoized too (negative caching) so an
+# unreachable relay doesn't stall every validation for `timeout` seconds.
+_opencode_free_live_memo: Optional[tuple[float, Optional[list[str]]]] = None
+_OPENCODE_FREE_LIVE_MEMO_TTL = 300.0 # 5 min; SWR disk cache handles the rest
+
def is_opencode_zen_free_model(model_id: Optional[str]) -> bool:
"""True when ``model_id`` is an OpenCode Zen free-tier slug.
@@ -5511,7 +5522,9 @@ def opencode_zen_free_headers() -> dict:
}
-def _fetch_opencode_free_models(timeout: float = 8.0) -> Optional[list[str]]:
+def _fetch_opencode_free_models(
+ timeout: float = 8.0, *, force_refresh: bool = False
+) -> Optional[list[str]]:
"""Fetch the live keyless OpenCode Free catalog from the Zen relay.
GETs ``{_OPENCODE_ZEN_FREE_BASE_URL}/models`` ANONYMOUSLY (the free tier
@@ -5522,6 +5535,13 @@ def _fetch_opencode_free_models(timeout: float = 8.0) -> Optional[list[str]]:
treated as a failure for the same reason (a relay with zero free models is
not worth trusting over the floor).
+ A short in-process memo (``_OPENCODE_FREE_LIVE_MEMO_TTL``) keeps direct
+ ``provider_model_ids("opencode-free")`` callers — model validation runs
+ it several times per resolution — from issuing one blocking network
+ round-trip each. The picker's cross-process freshness still comes from
+ the SWR disk cache one layer up; ``force_refresh=True`` (the SWR refresh
+ path) bypasses and repopulates the memo.
+
The Zen ``/models`` dump also lists paid/subscription IDs (e.g. Go
``ox-alpha-free`` is KEYED despite the suffix), so a bare ``*-free`` suffix
filter is not safe on its own — this mirrors the existing
@@ -5532,6 +5552,12 @@ def _fetch_opencode_free_models(timeout: float = 8.0) -> Optional[list[str]]:
from hermes_cli.urllib_security import open_credentialed_url
+ now = time.time()
+ if not force_refresh:
+ memo = _opencode_free_live_memo
+ if memo is not None and now - memo[0] < _OPENCODE_FREE_LIVE_MEMO_TTL:
+ return list(memo[1]) if memo[1] else None
+
url = f"{_OPENCODE_ZEN_FREE_BASE_URL.rstrip('/')}/models"
req = urllib.request.Request(url)
req.add_header("Accept", "application/json")
@@ -5543,6 +5569,7 @@ def _fetch_opencode_free_models(timeout: float = 8.0) -> Optional[list[str]]:
data = json.loads(resp.read().decode())
items = data if isinstance(data, list) else data.get("data", [])
except Exception:
+ _set_opencode_free_live_memo(None)
return None
ids = [m["id"] for m in items if isinstance(m, dict) and isinstance(m.get("id"), str)]
# Filter to the anonymous-servable free tier. The Zen dump can contain
@@ -5553,7 +5580,35 @@ def _fetch_opencode_free_models(timeout: float = 8.0) -> Optional[list[str]]:
if mid.lower().endswith("-free")
and mid.lower() not in _OPENCODE_FREE_KEYED_SUFFIX_MODELS
]
- return live_free if live_free else None
+ result = live_free if live_free else None
+ _set_opencode_free_live_memo(result)
+ return result
+
+
+def _set_opencode_free_live_memo(ids: Optional[list[str]]) -> None:
+ global _opencode_free_live_memo
+ _opencode_free_live_memo = (time.time(), list(ids) if ids else None)
+
+
+def _opencode_free_known_model_slugs() -> set[str]:
+ """Lowercased keyless free-tier slugs known right now — WITHOUT network I/O.
+
+ Union of the static ``_PROVIDER_MODELS["opencode-free"]`` floor, the
+ in-process live memo, and the SWR disk-cache entry. Used by the
+ ``opencode_zen_free_runtime`` healing path, which runs during model
+ resolution and must never block on a live fetch. Union (not replacement)
+ so a stale cache can only widen healing, never silently disable it.
+ """
+ known = {m.lower() for m in _PROVIDER_MODELS.get("opencode-free", [])}
+ memo = _opencode_free_live_memo
+ if memo is not None and memo[1]:
+ known.update(m.lower() for m in memo[1])
+ try:
+ entry = _load_provider_models_cache().get("opencode-free") or {}
+ known.update(str(m).lower() for m in entry.get("models", []) or [])
+ except Exception:
+ pass
+ return known
def opencode_zen_free_runtime(provider_id: Optional[str], model_id: Optional[str]) -> Optional[dict]:
@@ -5573,13 +5628,16 @@ def opencode_zen_free_runtime(provider_id: Optional[str], model_id: Optional[str
stopped being a reliable keyless signal when ``ox-alpha-free`` appeared
on the Go relay as a KEYED subscription model (2026-08-21) — suffix-based
healing would have routed it to a Zen relay that doesn't serve it.
+ Membership means the union of the cached LIVE keyless catalog (in-process
+ memo / SWR disk cache — never a blocking fetch on this hot path) and the
+ static floor, so a newly-live free model heals without a release.
"""
family = opencode_provider_family(provider_id)
if family is None:
return None
if family != "opencode-free":
bare = normalize_opencode_model_id(provider_id, model_id).strip().lower()
- if bare not in {m.lower() for m in _PROVIDER_MODELS.get("opencode-free", [])}:
+ if bare not in _opencode_free_known_model_slugs():
return None
normalized = normalize_opencode_model_id(provider_id, model_id)
api_mode = opencode_model_api_mode("opencode-zen", normalized)
diff --git a/hermes_cli/setup.py b/hermes_cli/setup.py
index b68849d3486..0b64de2944b 100644
--- a/hermes_cli/setup.py
+++ b/hermes_cli/setup.py
@@ -112,7 +112,7 @@ _DEFAULT_PROVIDER_MODELS = {
"ai-gateway": ["anthropic/claude-opus-4.6", "anthropic/claude-sonnet-4.6", "openai/gpt-5", "google/gemini-3-flash"],
"kilocode": ["anthropic/claude-sonnet-5", "anthropic/claude-opus-4.6", "anthropic/claude-sonnet-4.6", "openai/gpt-5.4", "google/gemini-3-pro-preview", "google/gemini-3-flash-preview"],
"opencode-zen": ["x-preview-f-free", "gpt-5.6-sol", "gpt-5.4", "gpt-5.3-codex", "claude-opus-5", "claude-sonnet-5", "gemini-3.7-flash", "glm-5.2", "kimi-k3", "minimax-m3"],
- "opencode-free": ["x-preview-f-free", "hy3-free", "laguna-s-2.1-free", "nemotron-3-ultra-free", "nemotron-3.5-lightning-free", "muse-spark-1.2-contributor-free"],
+ "opencode-free": ["deepseek-v4-flash-free", "hy3-free", "mimo-v2.5-free", "laguna-s-2.1-free", "nemotron-3-ultra-free", "nemotron-3.5-lightning-free", "muse-spark-1.2-contributor-free"],
"opencode-go": ["kimi-k3", "kimi-k2.7-code", "kimi-k2.6", "gpt-5.6-luna", "grok-4.5", "glm-5.3", "glm-5.3-flash", "glm-5.2", "mimo-v2.5-pro", "mimo-v2.5", "minimax-m3", "minimax-m2.7", "qwen3.8-max", "qwen3.7-max", "deepseek-v4-pro", "hy3"],
"huggingface": [
"Qwen/Qwen3.5-397B-A17B", "Qwen/Qwen3-235B-A22B-Thinking-2507",
diff --git a/tests/agent/test_opencode_free_provider.py b/tests/agent/test_opencode_free_provider.py
index 8af541971bc..13614bf21ed 100644
--- a/tests/agent/test_opencode_free_provider.py
+++ b/tests/agent/test_opencode_free_provider.py
@@ -91,9 +91,11 @@ class TestOpenCodeFreeModelLists:
for mid in _PROVIDER_MODELS["opencode-free"]:
assert is_opencode_zen_free_model(mid), mid
- def test_ox_alpha_is_listed(self):
+ def test_delisted_ox_alpha_not_in_floor(self):
+ """x-preview-f-free was delisted by the relay 2026-08-26 (401s keyless);
+ the offline floor must not offer it (#95914)."""
from hermes_cli.models import _PROVIDER_MODELS
- assert "x-preview-f-free" in _PROVIDER_MODELS["opencode-free"]
+ assert "x-preview-f-free" not in _PROVIDER_MODELS["opencode-free"]
class TestOpenCodeFreeRuntimeKeyless:
diff --git a/tests/hermes_cli/test_opencode_free_live_catalog.py b/tests/hermes_cli/test_opencode_free_live_catalog.py
index 207354a5adf..24fd7fc6a8d 100644
--- a/tests/hermes_cli/test_opencode_free_live_catalog.py
+++ b/tests/hermes_cli/test_opencode_free_live_catalog.py
@@ -127,3 +127,95 @@ class TestOpencodeFreeCacheFingerprint:
entry = written["opencode-free"]
assert entry["fp"].startswith("keyless:opencode-free")
assert isinstance(entry["at"], float) and not isinstance(entry["at"], bool)
+
+
+class TestOpencodeFreeFollowUps:
+ """Follow-up hardening on top of the salvaged live-catalog fix (#95943)."""
+
+ def _reset_memo(self, mod):
+ mod._opencode_free_live_memo = None
+
+ def test_fetch_memoizes_success_in_process(self):
+ """Direct provider_model_ids() callers must not each pay a network
+ round-trip: the second call within the memo TTL is served in-process."""
+ import hermes_cli.models as mod
+
+ self._reset_memo(mod)
+ calls = {"n": 0}
+
+ def fake_open(req, timeout):
+ calls["n"] += 1
+ import io, json as _json
+
+ class _Resp(io.BytesIO):
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *a):
+ return False
+
+ return _Resp(
+ _json.dumps({"data": [{"id": m} for m in _LIVE_FREE_MODELS]}).encode()
+ )
+
+ with patch("hermes_cli.urllib_security.open_credentialed_url", fake_open):
+ first = mod._fetch_opencode_free_models()
+ second = mod._fetch_opencode_free_models()
+ assert first == second == list(_LIVE_FREE_MODELS)
+ assert calls["n"] == 1 # memo served the second call
+ self._reset_memo(mod)
+
+ def test_fetch_memoizes_failure_negative_cache(self):
+ """An unreachable relay is memoized too — repeated validations must not
+ each block for the full network timeout."""
+ import hermes_cli.models as mod
+
+ self._reset_memo(mod)
+ calls = {"n": 0}
+
+ def fake_open(req, timeout):
+ calls["n"] += 1
+ raise OSError("relay down")
+
+ with patch("hermes_cli.urllib_security.open_credentialed_url", fake_open):
+ assert mod._fetch_opencode_free_models() is None
+ assert mod._fetch_opencode_free_models() is None
+ assert calls["n"] == 1
+ self._reset_memo(mod)
+
+ def test_heal_union_includes_live_only_model(self):
+ """A newly-live free model absent from the static floor must still heal
+ opencode-go/zen selections to the keyless Zen relay (sibling-site widen:
+ opencode_zen_free_runtime used to check the floor only)."""
+ import hermes_cli.models as mod
+
+ live_only = "ling-3.0-flash-fin-free"
+ assert live_only not in {m.lower() for m in _PROVIDER_MODELS["opencode-free"]}
+
+ self._reset_memo(mod)
+ with patch.object(mod, "_load_provider_models_cache", return_value={}):
+ assert mod.opencode_zen_free_runtime("opencode-go", live_only) is None
+
+ mod._set_opencode_free_live_memo(_LIVE_FREE_MODELS + [live_only])
+ try:
+ with patch.object(mod, "_load_provider_models_cache", return_value={}):
+ rt = mod.opencode_zen_free_runtime("opencode-go", live_only)
+ assert rt is not None and rt["source"] == "opencode-zen-free-keyless"
+ finally:
+ self._reset_memo(mod)
+
+ def test_heal_union_reads_swr_disk_cache(self):
+ """A fresh process (empty memo) still heals live-only models via the
+ SWR disk-cache entry — no blocking fetch on the resolution hot path."""
+ import hermes_cli.models as mod
+
+ live_only = "ling-3.0-flash-fin-free"
+ self._reset_memo(mod)
+ entry = {"opencode-free": {"fp": "keyless:opencode-free", "at": 0.0, "models": [live_only]}}
+ with patch.object(mod, "_load_provider_models_cache", return_value=entry):
+ rt = mod.opencode_zen_free_runtime("opencode-zen", live_only)
+ assert rt is not None
+
+ def test_static_floor_excludes_delisted_model(self):
+ """The offline floor must not offer a model known to 401 (#95914)."""
+ assert "x-preview-f-free" not in _PROVIDER_MODELS["opencode-free"]
diff --git a/tests/hermes_cli/test_opencode_zen_free_keyless.py b/tests/hermes_cli/test_opencode_zen_free_keyless.py
index eceedb400b4..e830f60baa4 100644
--- a/tests/hermes_cli/test_opencode_zen_free_keyless.py
+++ b/tests/hermes_cli/test_opencode_zen_free_keyless.py
@@ -64,7 +64,7 @@ class TestFreeSlugDetection:
class TestFreeRuntime:
def test_zen_provider_free_model(self):
- rt = opencode_zen_free_runtime("opencode-zen", "x-preview-f-free")
+ rt = opencode_zen_free_runtime("opencode-zen", "hy3-free")
assert rt is not None
assert rt["base_url"] == "https://opencode.ai/zen/v1"
assert rt["api_key"] == OPENCODE_ZEN_FREE_KEYLESS_PLACEHOLDER
@@ -74,7 +74,7 @@ class TestFreeRuntime:
def test_go_provider_heals_to_zen(self):
# Free slugs only exist on the Zen relay; a Go selection must be
# routed to Zen (the Go relay rejects the model outright).
- rt = opencode_zen_free_runtime("opencode-go", "x-preview-f-free")
+ rt = opencode_zen_free_runtime("opencode-go", "hy3-free")
assert rt is not None
assert rt["base_url"] == "https://opencode.ai/zen/v1"
@@ -114,13 +114,13 @@ class TestRuntimeProviderKeylessRouting:
return resolve_runtime_provider(requested=provider, target_model=model)
def test_zen_free_model_resolves_keyless(self):
- rt = self._resolve("opencode-zen", "x-preview-f-free")
+ rt = self._resolve("opencode-zen", "hy3-free")
assert rt["api_key"] == OPENCODE_ZEN_FREE_KEYLESS_PLACEHOLDER
assert rt["base_url"] == "https://opencode.ai/zen/v1"
assert rt["api_mode"] == "chat_completions"
def test_go_free_model_resolves_keyless_on_zen(self):
- rt = self._resolve("opencode-go", "x-preview-f-free")
+ rt = self._resolve("opencode-go", "hy3-free")
assert rt["api_key"] == OPENCODE_ZEN_FREE_KEYLESS_PLACEHOLDER
assert rt["base_url"] == "https://opencode.ai/zen/v1"
diff --git a/website/docs/integrations/providers.md b/website/docs/integrations/providers.md
index c02d3b8a30b..90dd1cfa825 100644
--- a/website/docs/integrations/providers.md
+++ b/website/docs/integrations/providers.md
@@ -41,7 +41,7 @@ You need at least one way to connect to an LLM. Use `hermes model` to switch pro
| **OpenCode Zen** | `OPENCODE_ZEN_API_KEY` in `~/.hermes/.env` (provider: `opencode-zen`) |
| **CommandCode** | `COMMANDCODE_API_KEY` in `~/.hermes/.env` (provider: `commandcode`, alias: `commandcode-chat`; Claude models via `commandcode-anthropic`, alias: `commandcode-claude`). Works with GOAT/Pro/Max/Provider plans (not the $1 Go plan — no API access). |
| **OpenCode Go** | `OPENCODE_GO_API_KEY` in `~/.hermes/.env` (provider: `opencode-go`) |
-| **OpenCode Free** | Keyless — no API key or account needed (provider: `opencode-free`, aliases: `free`, `opencode_free`). Select via `hermes model` or `/model free`; requests are sent anonymously |
+| **OpenCode Free** | Keyless — no API key or account needed (provider: `opencode-free`, aliases: `free`, `opencode_free`). Select via `hermes model` or `/model free`; requests are sent anonymously. The model list refreshes automatically from OpenCode's live catalog, so rotating free promotions appear (and delisted ones disappear) without a Hermes update |
| **DeepSeek** | `DEEPSEEK_API_KEY` in `~/.hermes/.env` (provider: `deepseek`) |
| **Hugging Face** | `HF_TOKEN` in `~/.hermes/.env` (provider: `huggingface`, aliases: `hf`) |
| **Google / Gemini** | `GOOGLE_API_KEY` (or `GEMINI_API_KEY`) in `~/.hermes/.env` (provider: `gemini`) |