The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(local-runtime): review pass — watcher honors the ownership guard; quickstart is single-flight
emozillae900b0d072fa
diff --git a/hermes_cli/local_runtime/catalog.py b/hermes_cli/local_runtime/catalog.pyindex 1b4d80a7c6f..d089fec4c57 100644--- a/hermes_cli/local_runtime/catalog.py+++ b/hermes_cli/local_runtime/catalog.py@@ -17,15 +17,16 @@ fit policy prices the build honestly (zero-spill, spilled, or refused bythe physics check).Validation lifecycle: builds proven end-to-end on real hardware are-marked validated. Day-0 entries ship before that proof under the-"day-0" tag — ensure_model_ready's touch generation still gates every-first load at runtime.+marked validated. Day-0 entries ship before that proof (they simply lack+the validated flag) — ensure_model_ready's touch generation still gates+every first load at runtime.Multi-file models: variants may carry split-GGUF parts (llama-server loads-from the first part; all parts download together, each sha-verified).-Entries may carry an mmproj (vision projector) and a speculative-decode-draft model — both download alongside the weights. Spec decode is enabled-only when the launch decision spills, where its speedup is largest.+from the first part; all parts download together). Entries may carry an+mmproj (vision projector) and a speculative-decode draft model — both+download alongside the weights. MTP-integrated models run spec decode+wherever they load; a separate draft model attaches only when the launch+decision spills, where its speedup is largest.File sizes come from HF LFS metadata and feed the estimator, the fitpills, and download progress. There is no download-time integrity checkdiff --git a/hermes_cli/local_runtime/load_progress.py b/hermes_cli/local_runtime/load_progress.pyindex db85854822e..379955c6e8c 100644--- a/hermes_cli/local_runtime/load_progress.py+++ b/hermes_cli/local_runtime/load_progress.py@@ -56,11 +56,19 @@ def _composite_percent(stages: list[str], current: str, value: float) -> int:def _endpoint() -> "tuple[str, str] | None":- """(base_root, api_key) of the managed router, or None."""+ """(base_root, api_key) of the managed router, or None.++ Resolved through the endpoint module's ownership-guarded reader, not+ a raw state-file read: on the shared stable port, a foreign install's+ server answers /health for anyone, and a raw read would attach this+ watcher to someone else's SSE stream (or spin on 401s against it).+ The guard's dead-pid check is the ownership proof."""try:- from hermes_cli.local_runtime.supervisor import state_path+ from hermes_cli.local_runtime.endpoint import _state_endpoint- state = json.loads(state_path().read_text(encoding="utf-8"))+ state = _state_endpoint()+ if state is None:+ return Nonebase = str(state.get("base_url", "")).rsplit("/v1", 1)[0]return (base, str(state.get("api_key", ""))) if base else Noneexcept Exception: # noqa: BLE001diff --git a/hermes_cli/web_routers/local_models.py b/hermes_cli/web_routers/local_models.pyindex 14f71d61aac..ebfda06188a 100644--- a/hermes_cli/web_routers/local_models.py+++ b/hermes_cli/web_routers/local_models.py@@ -866,6 +866,12 @@ class QuickstartBody(BaseModel):model_id: str | None = None # default: the catalog's recommended entry+# One quickstart at a time: the job sequences installs, downloads, a+# server bounce, and a config write — two racing runs would interleave+# all four. Held for the job's lifetime, released in the worker.+_QUICKSTART_LOCK = threading.Lock()++@router.post("/api/local-models/quickstart")async def local_models_quickstart(body: QuickstartBody):"""The dummy-proof path: one job that installs the runtime (if@@ -944,6 +950,10 @@ async def local_models_quickstart(body: QuickstartBody):(f"https://huggingface.co/{entry.repo}/resolve/main/{asset.path}",assets_dir() / asset.local_name, asset.size_bytes))+ if not _QUICKSTART_LOCK.acquire(blocking=False):+ raise HTTPException(status_code=409,+ detail="Setup is already running")+job = _job("quickstart", entry.display_name, model_id=entry.id)job["total_bytes"] = sum(p[2] for p in download_plan) or None@@ -1015,6 +1025,8 @@ async def local_models_quickstart(body: QuickstartBody):logger.warning("quickstart failed: %s", exc)job["status"] = "error"job["error"] = str(exc)+ finally:+ _QUICKSTART_LOCK.release()threading.Thread(target=_run, daemon=True, name="lr-quickstart").start()return {diff --git a/tests/hermes_cli/test_load_progress.py b/tests/hermes_cli/test_load_progress.pyindex 6b6b79a9938..3da34a8a444 100644--- a/tests/hermes_cli/test_load_progress.py+++ b/tests/hermes_cli/test_load_progress.py@@ -240,3 +240,21 @@ def test_prefill_progress_reads_busiest_processing_slot(monkeypatch):monkeypatch.setattr(lp.urllib.request, "urlopen", _boom)assert lp.get_prefill_progress("m") is None+++def test_endpoint_respects_ownership_guard(monkeypatch):+ """The watcher's endpoint MUST come from the ownership-guarded reader.+ Regression: a raw state-file read attached the SSE watcher to a+ foreign install's server on the shared stable port (health answers+ for anyone; only the dead-pid check proves ownership)."""+ import hermes_cli.local_runtime.load_progress as lp++ # Guard says "not ours": no endpoint, regardless of state on disk.+ monkeypatch.setattr("hermes_cli.local_runtime.endpoint._state_endpoint",+ lambda: None)+ assert lp._endpoint() is None++ monkeypatch.setattr(+ "hermes_cli.local_runtime.endpoint._state_endpoint",+ lambda: {"base_url": "http://127.0.0.1:18434/v1", "api_key": "k"})+ assert lp._endpoint() == ("http://127.0.0.1:18434", "k")diff --git a/tests/hermes_cli/test_local_quickstart.py b/tests/hermes_cli/test_local_quickstart.pyindex c82bacdf213..6270ae01edd 100644--- a/tests/hermes_cli/test_local_quickstart.py+++ b/tests/hermes_cli/test_local_quickstart.py@@ -150,3 +150,18 @@ def test_quickstart_skips_satisfied_legs(client, monkeypatch):assert job["status"] == "done", job["error"]assert "install" not in calls and "download" not in callsassert calls == ["assign"] or calls[-1] == "assign"+++def test_quickstart_is_single_flight(client, quickstart_ready, monkeypatch):+ """A second quickstart while one runs must 409, not start a twin job+ (the job sequences installs, downloads, a server bounce, and a config+ write — two interleaved runs corrupt all four)."""+ import hermes_cli.web_routers.local_models as lm++ lm._QUICKSTART_LOCK.acquire()+ try:+ r = client.post("/api/local-models/quickstart", json={})+ assert r.status_code == 409+ assert "already running" in r.json()["detail"].lower()+ finally:+ lm._QUICKSTART_LOCK.release()