Skip to content

The agent that grows with you

fix(webapp-access): status poll queries the gateway outside the skills lock

Teknium5c668bbe4daa
diff --git a/apps/desktop/src/app/settings/web-access-settings.tsx b/apps/desktop/src/app/settings/web-access-settings.tsx
index bca13ccb250..9659d912596 100644
--- a/apps/desktop/src/app/settings/web-access-settings.tsx
+++ b/apps/desktop/src/app/settings/web-access-settings.tsx
@@ -128,7 +128,9 @@ export function WebAccessSettings(): ReactElement | null {
queryKey: key,
refetchInterval: STATUS_POLL_MS,
refetchOnWindowFocus: true,
- retry: false
+ retry: false,
+ // Reopening the pane reads at once instead of showing the shared client's cached answer.
+ staleTime: 0
})
// react-query's own focus refetch follows `visibilitychange` only, which a native window losing
diff --git a/hermes_cli/web_routers/webapp_access.py b/hermes_cli/web_routers/webapp_access.py
index 1dc6bcdf120..89dc4f8b199 100644
--- a/hermes_cli/web_routers/webapp_access.py
+++ b/hermes_cli/web_routers/webapp_access.py
@@ -115,8 +115,10 @@ async def _restart(gateway: Optional[str], what: str) -> dict:
@router.get("/api/webapp-access/status")
async def webapp_access_status(profile: Optional[str] = None):
"""``restart_failure``: the newest restart of this gateway exited without replacing it, and why;
- the pane waiting on that restart stops and says so instead of timing out."""
- return await _scoped(profile, lambda gateway: {
+ the pane waiting on that restart stops and says so instead of timing out. The pane polls this,
+ so the status (a control-socket round trip) runs outside the skills lock, as in ``_restart``."""
+ gateway = await _scoped(profile, lambda gateway: gateway)
+ return await _in_gateway_home(gateway, lambda: {
**webapp_access.access_status(), "restart_failure": _gateway_restart_failure(gateway)})
diff --git a/tests/hermes_cli/test_webapp_access_status_lock.py b/tests/hermes_cli/test_webapp_access_status_lock.py
new file mode 100644
index 00000000000..7b1461523f7
--- /dev/null
+++ b/tests/hermes_cli/test_webapp_access_status_lock.py
@@ -0,0 +1,47 @@
+"""The Web Access pane's status poll never holds the process-wide skills lock across its gateway query.
+
+``GET /api/webapp-access/status`` asks the gateway over its control socket what it serves. The pane
+repeats that every 10 s, so a gateway slow to answer (mid-restart) must not stall every config,
+skills and tools request, which all take ``_SKILLS_PROFILE_LOCK`` through ``_profile_scope``.
+"""
+
+from __future__ import annotations
+
+import threading
+
+import pytest
+
+pytest.importorskip("fastapi")
+
+
+def test_a_status_poll_waiting_on_the_gateway_does_not_block_a_skills_request(monkeypatch):
+ from hermes_cli import webapp_launcher
+ from tests.hermes_cli.native_gateway_client import native_desktop_client
+
+ client = native_desktop_client(monkeypatch)
+ in_control, release = threading.Event(), threading.Event()
+
+ def _slow_gateway(_home, _command):
+ in_control.set()
+ release.wait(timeout=30)
+ raise webapp_launcher.GatewayUnreachable("no gateway")
+
+ monkeypatch.setattr(webapp_launcher, "_control", _slow_gateway)
+ results: dict[str, int] = {}
+
+ def _get(name, path):
+ results[name] = client.get(path).status_code
+
+ status = threading.Thread(target=_get, args=("status", "/api/webapp-access/status"), daemon=True)
+ status.start()
+ try:
+ assert in_control.wait(timeout=10), "the status route never reached the gateway query"
+ skills = threading.Thread(target=_get, args=("skills", "/api/skills"), daemon=True)
+ skills.start()
+ skills.join(timeout=10)
+ assert not skills.is_alive(), "a skills request waited on the status poll's gateway query"
+ assert results["skills"] == 200
+ finally:
+ release.set()
+ status.join(timeout=10)
+ assert results["status"] == 200