The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): /api/status does its local file reads off the event loop
Teknium3c88bee749e6
diff --git a/hermes_cli/web_routers/status.py b/hermes_cli/web_routers/status.pyindex 3315ff62ec0..c0f2be118dd 100644--- a/hermes_cli/web_routers/status.py+++ b/hermes_cli/web_routers/status.py@@ -464,21 +464,39 @@ async def _advisory_pressure(status: dict[str, Any], home: Path) -> None:status[key] = {"pressure": "unknown"}try:- from hermes_state import SessionDB as _SDB- from hermes_constants import get_hermes_home as _ghh- _db_path = _ghh() / "state.db"- if _db_path.exists():- _sdb = _SDB(db_path=_db_path, read_only=True)- try:- _rebuild = _sdb.fts_rebuild_status()- finally:- _sdb.close()- if _rebuild is not None:- status["fts_rebuild"] = _rebuild+ # SQLite open + read: off the loop like the rest of the probe.+ _rebuild = await run_in_threadpool(_fts_rebuild_status)+ if _rebuild is not None:+ status["fts_rebuild"] = _rebuildexcept Exception:pass+def _status_local_reads() -> dict[str, Any]:+ """The probe's synchronous local reads: the raw config.yaml stamp, the install method, the+ auth store and (first call only) git provenance. Run on a worker thread: on the event loop that+ also serves the session WebSocket they stalled every Desktop request behind the disk (#143561)."""+ current_ver, latest_ver = check_config_version()+ return {"version": get_version_info().base_version, "config_version": current_ver,+ "latest_config_version": latest_ver,+ "can_update_hermes": not _dashboard_local_update_managed_externally(),+ "nous_session_valid": _nous_session_validity()}+++def _fts_rebuild_status() -> Optional[dict[str, Any]]:+ """Deferred FTS rebuild progress of this home's state.db (read-only open), or None."""+ from hermes_state import SessionDB as _SDB+ from hermes_constants import get_hermes_home as _ghh+ _db_path = _ghh() / "state.db"+ if not _db_path.exists():+ return None+ _sdb = _SDB(db_path=_db_path, read_only=True)+ try:+ return _sdb.fts_rebuild_status()+ finally:+ _sdb.close()++@router.get("/api/status")async def get_status(profile: Optional[str] = None):"""Public machine-level liveness probe (``PUBLIC_API_PATHS``): version, gateway state,@@ -498,7 +516,7 @@ async def get_status(profile: Optional[str] = None):status_scope.__enter__()try:- current_ver, latest_ver = check_config_version()+ local = await run_in_threadpool(_status_local_reads)gateway = await _resolve_gateway_status(profile_dir, _GATEWAY_HEALTH_URL)gateway_running, gateway_state = gateway["gateway_running"], gateway["gateway_state"]@@ -522,9 +540,9 @@ async def get_status(profile: Optional[str] = None):auth = _auth_gate_status()status = {- "version": get_version_info().base_version, "release_date": __release_date__,- "config_version": current_ver, "latest_config_version": latest_ver,- "can_update_hermes": not _dashboard_local_update_managed_externally(),+ "version": local["version"], "release_date": __release_date__,+ "config_version": local["config_version"], "latest_config_version": local["latest_config_version"],+ "can_update_hermes": local["can_update_hermes"],"gateway_running": gateway_running, "gateway_state": gateway_state,"gateway_platforms": gateway["gateway_platforms"],"gateway_exit_reason": gateway["gateway_exit_reason"],@@ -541,7 +559,7 @@ async def get_status(profile: Optional[str] = None):"gateway_drainable": derive_gateway_drainable(gateway_running=gateway_running, gateway_state=gateway_state),"restart_drain_timeout": restart_drain_timeout, "active_sessions": active_sessions,- **auth, "nous_session_valid": _nous_session_validity()}+ **auth, "nous_session_valid": local["nous_session_valid"]}# Stable per-install identity (first call may touch disk). Omitted (not null) when# unpersistable so older-client behavior and the no-identity fallback stay identical.diff --git a/tests/hermes_cli/test_status_probe_off_loop.py b/tests/hermes_cli/test_status_probe_off_loop.pynew file mode 100644index 00000000000..ec81d744089--- /dev/null+++ b/tests/hermes_cli/test_status_probe_off_loop.py@@ -0,0 +1,33 @@+"""/api/status does its local file reads off the event loop (#143561).++The handler runs on the loop that also serves the session WebSocket (Desktop), so a blocking read+of config.yaml / auth.json there stalls every other request for as long as the disk takes.+"""++import asyncio+import threading++import pytest+++class _Stop(Exception):+ pass+++async def test_status_config_stamp_read_runs_off_the_event_loop(monkeypatch):+ import hermes_cli.config as config_mod+ from hermes_cli.web_routers import status as status_router++ loop_thread = threading.get_ident()+ seen = []++ def _check_config_version(*_a, **_kw):+ seen.append(threading.get_ident())+ raise _Stop()++ monkeypatch.setattr(config_mod, "check_config_version", _check_config_version)+ with pytest.raises(_Stop):+ await asyncio.wait_for(status_router.get_status(), 10)+ assert seen, "the config stamp was never read"+ assert seen[0] != loop_thread, "check_config_version ran on the event loop thread"