The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(chat): the dashboard's legacy /chat socket closes as on main when its child exits
emozillae0ff4f8553b2
diff --git a/hermes_cli/web_server_chat.py b/hermes_cli/web_server_chat.pyindex 73813367d38..d09b17ea4d2 100644--- a/hermes_cli/web_server_chat.py+++ b/hermes_cli/web_server_chat.py@@ -20,7 +20,7 @@ from typing import Optionalfrom fastapi import FastAPI, Request, WebSocket, WebSocketDisconnectfrom pathlib import Pathfrom typing import Optional-from hermes_cli.pty_session import PtySessionRegistry, WS_CLOSE_PROCESS_EXITED+from hermes_cli.pty_session import PtySessionRegistry# Same logger the code used before extraction (record parity)._log = logging.getLogger("hermes_cli.web_server")@@ -72,12 +72,10 @@ async def _legacy_pump(ws: WebSocket, bridge) -> None:loop = asyncio.get_running_loop()async def pump_pty_to_ws() -> None:- process_exited = Falsetry:while True:chunk = await loop.run_in_executor(None, bridge.read, _PTY_READ_CHUNK_TIMEOUT)if chunk is None: # EOF- process_exited = Truereturnif not chunk: # no data this tick; yield control and retryawait asyncio.sleep(_PTY_IDLE_BACKOFF)@@ -97,7 +95,7 @@ async def _legacy_pump(ws: WebSocket, bridge) -> None:# reap independent of that cancellation race (#54028).await asyncio.to_thread(bridge.close)with contextlib.suppress(Exception):- await ws.close(code=WS_CLOSE_PROCESS_EXITED if process_exited else 1000)+ await ws.close()reader_task = asyncio.create_task(pump_pty_to_ws())diff --git a/tests/hermes_cli/test_legacy_pump_close_reason.py b/tests/hermes_cli/test_legacy_pump_close_reason.pyindex e0ba40e60d1..62b5523e072 100644--- a/tests/hermes_cli/test_legacy_pump_close_reason.py+++ b/tests/hermes_cli/test_legacy_pump_close_reason.py@@ -1,11 +1,14 @@-"""Only observed PTY EOF proves that the process exited."""+"""The dashboard's legacy /chat pump (no ``?attach=`` token) closes as on main.++Whether the child exited (EOF) or the socket or read failed, the pump reaps the child and closes the+browser socket normally (1000). Only the keep-alive path reports an exited child with 4410.+"""import asynciofrom unittest.mock import Mockimport pytestfrom starlette.websockets import WebSocket-from hermes_cli.pty_session import WS_CLOSE_PROCESS_EXITEDfrom hermes_cli.web_server_chat import _legacy_pump@@ -16,7 +19,7 @@ def anyio_backend():@pytest.mark.anyio@pytest.mark.parametrize("failure", [None, "send", "read"])-async def test_legacy_pump_close_distinguishes_eof_from_transport_failure(failure):+async def test_legacy_pump_closes_normally_and_reaps_the_child_as_on_main(failure):incoming = asyncio.Queue()await incoming.put({"type": "websocket.connect"})closes = []@@ -33,5 +36,5 @@ async def test_legacy_pump_close_distinguishes_eof_from_transport_failure(failurbridge = Mock()bridge.read.side_effect = [RuntimeError("read failed")] if failure == "read" else [b"output", None]await asyncio.wait_for(_legacy_pump(ws, bridge), timeout=3)- assert closes == [WS_CLOSE_PROCESS_EXITED if failure is None else 1000]+ assert closes == [1000]bridge.close.assert_called()