Skip to content

The agent that grows with you

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.py
index 73813367d38..d09b17ea4d2 100644
--- a/hermes_cli/web_server_chat.py
+++ b/hermes_cli/web_server_chat.py
@@ -20,7 +20,7 @@ from typing import Optional
from fastapi import FastAPI, Request, WebSocket, WebSocketDisconnect
from pathlib import Path
from 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 = False
try:
while True:
chunk = await loop.run_in_executor(None, bridge.read, _PTY_READ_CHUNK_TIMEOUT)
if chunk is None: # EOF
- process_exited = True
return
if not chunk: # no data this tick; yield control and retry
await 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.py
index 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 asyncio
from unittest.mock import Mock
import pytest
from starlette.websockets import WebSocket
-from hermes_cli.pty_session import WS_CLOSE_PROCESS_EXITED
from 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(failur
bridge = 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()