GET /api/webapp-access/status ran access_status() inside _scoped -> _profile_scope, holding the process-wide _SKILLS_PROFILE_LOCK across the gateway control-socket round trip. The pane polls it every 10 s, so each poll stalled every config, skills and tools request for the gateway's answer time (the full timeout when it is slow or mid-restart). Resolve the gateway with _scoped, then query through _in_gateway_home, as _restart does. The pane's status query also takes staleTime: 0, so reopening it reads at once instead of showing the shared client's cached answer until the next poll tick. Review suggestions from @kshitijk4poor.
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
"""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
|