The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(local-runtime): download a model even when its draft can't be fetched
emozilla9835ebe15c24
diff --git a/hermes_cli/web_routers/local_models.py b/hermes_cli/web_routers/local_models.pyindex 2c69def0036..123c1813c96 100644--- a/hermes_cli/web_routers/local_models.py+++ b/hermes_cli/web_routers/local_models.py@@ -445,10 +445,19 @@ def _missing_drafts(engine_tag: str) -> list:return plan-def _run_download_plan(job: dict[str, Any], plan: list, label: str) -> None:- """The downloader counts completed files and every part of this plan."""+def _run_download_plan(job: dict[str, Any], plan: list, label: str, entry=None) -> None:+ """The downloader counts completed files and every part of this plan. A catalog entry's draft+ downloads last and only speeds generation up, so a draft that fails costs the model nothing."""+ draft = bootstrap.assets_dir() / entry.draft.local_name if entry is not None and entry.draft else None+ required = [row for row in plan if row[1] != draft]_step(job, "downloading", f"Downloading {label}")- _download_job(job, plan)+ _download_job(job, required)+ optional = [row for row in plan if row[1] == draft]+ if optional:+ with _JOBS_LOCK:+ job.update(done_bytes=0, total_bytes=None, ranges={})+ _step(job, "downloading", "Downloading the draft model that speeds up generation")+ _download_optional(job, optional)def _download_progress_hook(job: dict[str, Any]):@@ -753,7 +762,7 @@ def local_models_download(body: ModelDownloadBody):return {"job_id": None, "already_downloaded": True, "model_id": variant.model_id}job = _job("model-download", f"{entry.display_name} ({variant.quant})", model_id=entry.id)def _run():- _run_download_plan(job, plan, entry.display_name)+ _run_download_plan(job, plan, entry.display_name, entry)_finish(job, f"{entry.display_name} ready")_refresh_runtime("post-download runtime refresh skipped")@@ -865,7 +874,7 @@ def local_models_quickstart(body: QuickstartBody, profile: Optional[str] = None)if job["phase"] != "downloading":with _JOBS_LOCK:job.update(done_bytes=0, total_bytes=None, ranges={})- _run_download_plan(job, download_plan, entry.display_name)+ _run_download_plan(job, download_plan, entry.display_name, entry)_step(job, "starting-server", "Starting the local server")with _config_profile_scope(profile):_ensure_server(job, _set_runtime_enabled(True), variant.model_id,diff --git a/tests/hermes_cli/test_local_external_draft.py b/tests/hermes_cli/test_local_external_draft.pyindex 2564cf06c99..ff2510db7f5 100644--- a/tests/hermes_cli/test_local_external_draft.py+++ b/tests/hermes_cli/test_local_external_draft.py@@ -275,6 +275,31 @@ def test_the_update_job_downloads_missing_drafts_then_restarts_the_server(clientassert events == ["restart"]+def test_a_draft_that_fails_to_download_leaves_the_model_downloaded(client, monkeypatch, tmp_path):+ """The draft only speeds generation up: a 404 on it costs the user the draft, never the model+ it was meant to speed up."""+ lm = _staged(monkeypatch, ENTRY)+ models, assets = tmp_path / "models", tmp_path / "assets"+ monkeypatch.setattr(lm.bootstrap, "models_dir", lambda: models)+ monkeypatch.setattr(lm.bootstrap, "assets_dir", lambda: assets)+ monkeypatch.setattr(lm, "_refresh_runtime", lambda *args: None)++ def download(job, plan):+ if any(dest.name == ENTRY.draft.local_name for _, dest, _ in plan):+ raise RuntimeError("download failed from https://huggingface.co/lab/Hybrid-DFlash-GGUF: HTTP Error 404")+ for _, dest, _ in plan:+ dest.parent.mkdir(parents=True, exist_ok=True)+ dest.touch()++ monkeypatch.setattr(lm, "_download_job", download)++ job_id = client.post("/api/local-models/download", json={"model_id": BUILD.model_id}).json()["job_id"]++ assert poll(client, job_id, until=("done", "error"))["status"] == "done"+ assert (models / BUILD.files[0].local_name).is_file()+ assert not (assets / ENTRY.draft.local_name).exists()++def _update_job(monkeypatch, *, serving: str, on_download=None):"""The engine update over a running server on ``serving``, with b11671 already installed."""lm = _staged(monkeypatch, ENTRY)diff --git a/tests/hermes_cli/test_local_quickstart.py b/tests/hermes_cli/test_local_quickstart.pyindex 14a829f7a00..889fece991d 100644--- a/tests/hermes_cli/test_local_quickstart.py+++ b/tests/hermes_cli/test_local_quickstart.py@@ -66,7 +66,7 @@ def test_quickstart_without_recommendation_requires_explicit_choice(client, monkcalls: list[tuple] = []- def download(job, plan, label):+ def download(job, plan, label, entry=None):calls.append(("download", label))class Server:@@ -318,7 +318,7 @@ def test_quickstart_prices_after_installing_the_engine(client, monkeypatch):monkeypatch.setattr(lm, "_runtime_target", lambda backend=None: ("b1", "vulkan"))monkeypatch.setattr(lm.binaries, "installed_engine", lambda *a, **k: None)monkeypatch.setattr(lm.binaries, "ensure_engine", lambda backend, **kw: installed.append(backend))- monkeypatch.setattr(lm, "_run_download_plan", lambda job, plan, label: downloaded.append(label))+ monkeypatch.setattr(lm, "_run_download_plan", lambda job, plan, label, entry=None: downloaded.append(label))monkeypatch.setattr(lm, "_ensure_server", lambda *a, **k: None)monkeypatch.setattr(lm, "_assign_default", lambda job, model_id: assigned.append(model_id))