Skip to content

The agent that grows with you

fix(local-runtime): keep the engine update when a draft download fails

emozillae8787cd7b59a
diff --git a/hermes_cli/web_routers/local_models.py b/hermes_cli/web_routers/local_models.py
index 0e3e8f4ac1a..2c69def0036 100644
--- a/hermes_cli/web_routers/local_models.py
+++ b/hermes_cli/web_routers/local_models.py
@@ -466,6 +466,19 @@ def _download_job(job: dict[str, Any], plan) -> None:
dl.run(progress=_download_progress_hook(job))
+def _download_optional(job: dict[str, Any], plan) -> bool:
+ """Download files that only speed generation up, such as a DFlash draft. A failure leaves the
+ model running without them, so it is logged instead of failing the job; a pause still pauses."""
+ try:
+ _download_job(job, plan)
+ except DownloadPaused:
+ raise
+ except (RuntimeError, OSError) as exc: # the downloader's transfer, hash and rename failures, and disk errors
+ logger.warning("optional download failed; continuing without it: %s", exc)
+ return False
+ return True
+
+
def _loaded_models(running: dict[str, Any]) -> tuple[dict[str, str], dict[str, Any]]:
"""Resident models right now, plus how each is placed (granted window from the child, spill facts from
the preset decision) — the difference between 'fast' and 'why is my CPU busy', so it must be inspectable.
@@ -697,9 +710,10 @@ def local_models_runtime_install(body: RuntimeInstallBody, profile: Optional[str
engine = _install_engine_job(job, backend)
drafts = _missing_drafts(engine.tag)
if drafts:
- owed["restart"] = True # the restart is what loads them
+ before, owed["restart"] = owed["restart"], True # the restart is what loads them
_step(job, "downloading", "Downloading draft models that speed up generation")
- _download_job(job, drafts)
+ if not _download_optional(job, drafts) and len(_missing_drafts(engine.tag)) == len(drafts):
+ owed["restart"] = before # nothing new landed for a restart to load
running = bootstrap.get_supervisor()
serving = bootstrap.serving_engine()
stale = previous != engine or (serving is not None and serving.tag != engine.tag)
diff --git a/tests/hermes_cli/test_local_external_draft.py b/tests/hermes_cli/test_local_external_draft.py
index b7ea977e171..2564cf06c99 100644
--- a/tests/hermes_cli/test_local_external_draft.py
+++ b/tests/hermes_cli/test_local_external_draft.py
@@ -310,6 +310,46 @@ def test_a_pause_between_the_drafts_and_the_restart_still_restarts_on_resume(cli
assert events == ["restart"]
+def _failing_download(job, plan):
+ raise RuntimeError("download failed from https://huggingface.co/lab/Hybrid-DFlash-GGUF: HTTP Error 404")
+
+
+def test_a_failed_draft_download_still_switches_the_server_to_the_new_build(client, monkeypatch):
+ """The draft only speeds generation up. A draft that fails to download leaves the model on MTP,
+ and the server still moves to the build the update installed."""
+ _, events = _update_job(monkeypatch, serving="b11370", on_download=_failing_download)
+
+ job_id = client.post("/api/local-models/runtime/install", json={"backend": "cpu"}).json()["job_id"]
+
+ assert poll(client, job_id, until=("done", "error"))["status"] == "done"
+ assert events == ["restart"]
+
+
+def test_a_failed_draft_download_alone_leaves_the_server_running(client, monkeypatch):
+ """Nothing new landed for a restart to load, so a server already on the installed build keeps
+ serving."""
+ _, events = _update_job(monkeypatch, serving="b11671", on_download=_failing_download)
+
+ job_id = client.post("/api/local-models/runtime/install", json={"backend": "cpu"}).json()["job_id"]
+
+ assert poll(client, job_id, until=("done", "error"))["status"] == "done"
+ assert events == []
+
+
+def test_a_pause_during_the_draft_download_pauses_the_update(client, monkeypatch):
+ from pm.downloader import DownloadPaused
+
+ def paused(job, plan):
+ raise DownloadPaused("download paused")
+
+ _, events = _update_job(monkeypatch, serving="b11370", on_download=paused)
+
+ job_id = client.post("/api/local-models/runtime/install", json={"backend": "cpu"}).json()["job_id"]
+
+ assert poll(client, job_id, until=("paused", "done", "error"))["status"] == "paused"
+ assert events == []
+
+
def test_the_update_restarts_a_server_still_on_an_older_build(client, monkeypatch):
"""An earlier update installed b11671 and stopped before its restart: the server still runs
the old build, and the next update switches it over."""