Skip to content

The agent that grows with you

fix(local-runtime): eject 500 on adopted servers — _state_endpoint was scoped to one route

emozillabf55f109c92a
diff --git a/hermes_cli/web_routers/local_models.py b/hermes_cli/web_routers/local_models.py
index e54a391b855..ad396103a8e 100644
--- a/hermes_cli/web_routers/local_models.py
+++ b/hermes_cli/web_routers/local_models.py
@@ -26,6 +26,8 @@ from typing import Any, Dict, Optional
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
+from hermes_cli.local_runtime.endpoint import _state_endpoint
+
logger = logging.getLogger(__name__)
router = APIRouter()
@@ -249,7 +251,6 @@ async def local_models_status():
runtimes_root,
server_binary,
)
- from hermes_cli.local_runtime.endpoint import _state_endpoint
section = _runtime_section()
configured_tag = section.get("tag") or default_tag()
@@ -908,9 +909,7 @@ async def local_models_activate(body: ModelActivateBody):
config = load_config()
sup = ensure_local_runtime(config, force=True)
if sup is None:
- from hermes_cli.local_runtime.endpoint import _state_endpoint as _se
-
- if _se() is None:
+ if _state_endpoint() is None:
raise RuntimeError(
"The local server could not start — check the runtime is installed")
diff --git a/tests/hermes_cli/test_local_models_routes.py b/tests/hermes_cli/test_local_models_routes.py
index 460b73c96d3..51f8134c4b6 100644
--- a/tests/hermes_cli/test_local_models_routes.py
+++ b/tests/hermes_cli/test_local_models_routes.py
@@ -218,3 +218,20 @@ def test_runtime_install_rejects_impossible_combo(client, monkeypatch):
def test_job_poll_unknown_404s(client):
assert client.get("/api/local-models/jobs/deadbeef").status_code == 404
+
+
+def test_eject_without_supervisor_is_not_a_500(client, monkeypatch):
+ """Eject on an ADOPTED server (no in-process supervisor — the shape
+ every backend restart produces, since boot adopts the running server
+ via the state file) must route through the persisted endpoint, not
+ crash. Regression: _state_endpoint was only imported inside the
+ status route, so eject raised NameError -> 500 for every adopted-
+ server session."""
+ monkeypatch.setattr(
+ "hermes_cli.local_runtime.bootstrap.get_supervisor", lambda: None)
+ # No running server either: the route must answer 409 (no server),
+ # never a NameError 500.
+ monkeypatch.setattr(
+ "hermes_cli.web_routers.local_models._state_endpoint", lambda: None)
+ r = client.post("/api/local-models/eject", json={"model_id": "anything"})
+ assert r.status_code == 409, (r.status_code, r.text)