The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(web): synchronize refresh and console cancellation tests
ethernet3a1e59e14d14
diff --git a/hermes_cli/web_routers/chat_ws.py b/hermes_cli/web_routers/chat_ws.pyindex e14ac0573b2..8c787a99a4f 100644--- a/hermes_cli/web_routers/chat_ws.py+++ b/hermes_cli/web_routers/chat_ws.py@@ -187,6 +187,12 @@ async def _unwind_console_worker(worker: Any, scope: InterruptScope, reason: str_log.warning("console worker still running %ss after %s", _CONSOLE_UNWIND_TIMEOUT_SECONDS, reason)+async def _wait_for_console_worker(worker: Any) -> Any:+ return await asyncio.wait_for(+ asyncio.wrap_future(worker), timeout=_CONSOLE_COMMAND_TIMEOUT_SECONDS,+ )++class _ConsoleSender:"""Serialises frames onto one console socket and owns the prompt suffix."""@@ -309,7 +315,7 @@ async def console_ws(ws: WebSocket) -> None:_execute_console_line, engine, line, confirmed=confirmed, profile=profile, scope=scope,)try:- result = await asyncio.wait_for(asyncio.wrap_future(worker), timeout=_CONSOLE_COMMAND_TIMEOUT_SECONDS)+ result = await _wait_for_console_worker(worker)except asyncio.CancelledError:await _unwind_console_worker(worker, scope, "cancelled")raisediff --git a/tests/hermes_cli/test_refresh_singleflight.py b/tests/hermes_cli/test_refresh_singleflight.pyindex 475eff16e73..a39545fc718 100644--- a/tests/hermes_cli/test_refresh_singleflight.py+++ b/tests/hermes_cli/test_refresh_singleflight.py@@ -199,16 +199,21 @@ def test_cookie_gate_burst_with_stale_rt_rotates_once(gated_web_app):register_provider(provider)cookies = {"hermes_session_at": "expired-at", "hermes_session_rt": "stale-rt","hermes_session_provider": "stub"}+ clients_ready = threading.Barrier(5)def call():# One TestClient per request: a shared jar would hand later requests the rotated RT.with TestClient(gated_web_app, base_url="http://gw.example.test") as client:+ clients_ready.wait(timeout=60)return client.get("/api/auth/me", cookies=cookies)with ThreadPoolExecutor(max_workers=4) as pool:futures = [pool.submit(call) for _ in range(4)]- assert provider.entered.wait(3)- provider.release.set()+ clients_ready.wait(timeout=60)+ try:+ assert provider.entered.wait(10)+ finally:+ provider.release.set()statuses = sorted(f.result(timeout=10).status_code for f in futures)assert statuses == [200, 200, 200, 200]assert provider.calls == 1diff --git a/tests/hermes_cli/test_web_server_console_ws.py b/tests/hermes_cli/test_web_server_console_ws.pyindex 212d7db1acb..f1a0262e02d 100644--- a/tests/hermes_cli/test_web_server_console_ws.py+++ b/tests/hermes_cli/test_web_server_console_ws.py@@ -146,16 +146,10 @@ def test_console_cancel_stops_forked_agent_request_before_reporting(console_cliefrom agent import curatorfrom hermes_cli.web_routers import chat_ws- from hermes_constants import get_hermes_home- from tools import skill_usage-- # The LLM pass only forks when an agent-created skill is a candidate: bundled- # built-ins are excluded from the review list, so the temp home needs one.- skill_dir = get_hermes_home() / "skills" / "console-cancel-probe"- skill_dir.mkdir(parents=True, exist_ok=True)- (skill_dir / "SKILL.md").write_text("---\nname: console-cancel-probe\ndescription: x\n---\n", encoding="utf-8")- skill_usage.record_created("console-cancel-probe", agent_created=True)+ # Candidate discovery is unrelated to console cancellation. Pin one candidate so the+ # command always reaches the fork instead of depending on process-global skill caches.+ monkeypatch.setattr(curator, "_render_candidate_list", lambda: "Agent-created skills (1):\n- console-cancel-probe")monkeypatch.setattr(curator, "_resolve_review_provider",lambda: ({"api_key": "test-key", "base_url": blocking_provider["base_url"]}, "test-model", "openai-compat", {}),@@ -171,7 +165,14 @@ def test_console_cancel_stops_forked_agent_request_before_reporting(console_cliemonkeypatch.setattr(chat_ws, "_execute_console_line", observed_execute)if stop == "timeout":- monkeypatch.setattr(chat_ws, "_CONSOLE_COMMAND_TIMEOUT_SECONDS", 2.0)+ async def timeout_after_request_starts(worker):+ while not blocking_provider["started"].is_set():+ if worker.done():+ return worker.result()+ await chat_ws.asyncio.sleep(0.01)+ raise chat_ws.asyncio.TimeoutError++ monkeypatch.setattr(chat_ws, "_wait_for_console_worker", timeout_after_request_starts)line = "curator run --consolidate --dry-run"with console_client.websocket_connect(_url()) as conn: