Files
hermes-agent/tests/hermes_cli/test_status_probe_off_loop.py
Teknium 3c88bee749 fix(dashboard): /api/status does its local file reads off the event loop
`get_status` read config.yaml for `check_config_version()` (a raw YAML parse), the auth
store for `nous_session_validity`, the install method, git provenance on the first call, and
opened state.db read-only for the FTS rebuild progress, all synchronously inside the `async`
handler. In the gateway that handler runs on the loop that also serves the Desktop session
WebSocket, so every status poll (Desktop polls it constantly; NAS health sweeps too) stalled
every other request for as long as the disk took.

Those reads now run in one threadpool hop (`_status_local_reads`) and one for the FTS
rebuild probe, the same way the handler's other reads already do. The payload is unchanged;
`?profile=` keeps its config scope because the threadpool copies contextvars.

Fixes #143561 (the config-version read; the platform-config read was already off the loop)
2026-10-27 12:35:50 -07:00

34 lines
1.0 KiB
Python

"""/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
@pytest.mark.asyncio
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"