Skip to content

The agent that grows with you

fix(local-runtime): a mid-download split model is not staged

emozilladb3feaceafa6
diff --git a/hermes_cli/local_runtime/bootstrap.py b/hermes_cli/local_runtime/bootstrap.py
index 374588c1727..9d440e83d8e 100644
--- a/hermes_cli/local_runtime/bootstrap.py
+++ b/hermes_cli/local_runtime/bootstrap.py
@@ -65,17 +65,29 @@ def assets_dir() -> Path:
def staged_models() -> "list[Path]":
- """Servable staged models: first-parts of split GGUFs count once,
- continuation parts and assets/ don't count at all."""
+ """Servable staged models: single-file GGUFs count when present; a
+ split GGUF counts once, by its first part, and only when EVERY part
+ is on disk — a mid-download split is not servable and must not
+ surface anywhere as a model. Continuation parts and assets/ never
+ count."""
import re
- part = re.compile(r"-(\d{5})-of-\d{5}\.gguf$")
+ part = re.compile(r"-(\d{5})-of-(\d{5})\.gguf$")
+ files = sorted(models_dir().glob("*.gguf"))
+ names = {p.name for p in files}
out = []
- for p in sorted(models_dir().glob("*.gguf")):
+ for p in files:
m = part.search(p.name)
- if m and m.group(1) != "00001":
+ if m is None:
+ out.append(p)
continue
- out.append(p)
+ if m.group(1) != "00001":
+ continue
+ stem = p.name[: m.start()]
+ total = int(m.group(2))
+ if all(f"{stem}-{i:05d}-of-{m.group(2)}.gguf" in names
+ for i in range(2, total + 1)):
+ out.append(p)
return out
diff --git a/hermes_cli/web_routers/local_models.py b/hermes_cli/web_routers/local_models.py
index ebfda06188a..146298a2199 100644
--- a/hermes_cli/web_routers/local_models.py
+++ b/hermes_cli/web_routers/local_models.py
@@ -505,13 +505,17 @@ async def local_models_catalog():
# Planning budget: price against machine capacity, not live-free VRAM.
# A loaded model must not make the catalog call every row unaffordable.
budget = probe_budget(planning=True)
- mdir = _models_dir()
+ # Completeness-checked staging (split parts all present) — the same
+ # answer the picker and the router see, so a mid-download model never
+ # reads as downloaded here.
+ from hermes_cli.local_runtime.bootstrap import staged_model_ids
+
+ staged_ids = set(staged_model_ids())
entries = []
for entry in CATALOG:
choice = select_variant(entry, budget)
# Any variant of this family already on disk counts as downloaded
# (split variants stage under their first part).
- staged_ids = {_model_id_for(p) for p in mdir.glob("*.gguf")} if mdir.exists() else set()
downloaded_variant = next(
(v for v in entry.variants if v.model_id in staged_ids), None)
row: Dict[str, Any] = {
diff --git a/tests/hermes_cli/test_local_runtime.py b/tests/hermes_cli/test_local_runtime.py
index 82a6a271974..082c22afb9b 100644
--- a/tests/hermes_cli/test_local_runtime.py
+++ b/tests/hermes_cli/test_local_runtime.py
@@ -562,6 +562,28 @@ def test_idle_sweep_busy_model_resets_clock(tmp_path, monkeypatch, stub_server):
assert handler.unloaded == []
+def test_staged_models_requires_every_split_part(tmp_path, monkeypatch):
+ """A split GGUF mid-download must NOT count as staged: the picker, the
+ catalog's 'downloaded' flag, and the router's model list all read
+ staged_models(), and a first part with missing continuations is not
+ servable. Single files and complete splits count; continuation parts
+ never count as their own model."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ import hermes_cli.local_runtime.bootstrap as bs
+
+ mdir = bs.models_dir()
+ mdir.mkdir(parents=True, exist_ok=True)
+
+ (mdir / "Single-Q4_K_M.gguf").touch()
+ # Complete split: both parts present.
+ (mdir / "Whole-Q4-00001-of-00002.gguf").touch()
+ (mdir / "Whole-Q4-00002-of-00002.gguf").touch()
+ # Mid-download split: first part only, of three.
+ (mdir / "Partial-Q4-00001-of-00003.gguf").touch()
+
+ assert bs.staged_model_ids() == ["Single-Q4_K_M", "Whole-Q4"]
+
+
def test_bootstrap_skips_boot_with_no_staged_models(tmp_path, monkeypatch):
"""Residency: enabled + installed but zero staged models -> no server
boot (nothing to serve; the walked-away story)."""