{"repo":"NousResearch/hermes-agent","public_id":"54028","display_label":"Dashboard PTY WebSocket file descriptor leak reports and fixes","summary":"The members concern a file descriptor leak in the dashboard's PTY/WebSocket handling: two pull requests propose changes (racing the PTY reader against WS receive, and closing the WebSocket on child EOF), and one bug report describes an FD leak regression tied to earlier PTY reconnect PRs. The titles alone do not show whether the changes address the reported issue.","subsystem":"dashboard","counts":{"members":3,"open_issues":0,"open_issues_distinct":0,"open_prs":0,"closed_issues":1,"merged_prs":1,"attempt_prs":1},"landed_fix":{"status":"merged_to_main","basis":"structural","pr":54123,"merged_at":"2026-06-28T09:42:22+00:00"},"resolution":{"state":"resolved","by":"pr-54123"},"freshness":{"state":"verified","last_verified_at":"2026-06-28T09:42:22+00:00","is_stale":false},"grouping":{"backbone":"STRUCTURAL_SPANNING","link_density":0.6666666666666666},"fix_edges":[{"issue_number":54028,"pr_number":54123,"tier":"verified","basis":"closing_ref","confidence":0.95,"recoverable_from_timeline":true,"pr_merged_at":"2026-06-28T09:42:22+00:00"}],"members":[{"kind":"issue","number":54028,"title":"[Bug]: FD leak regression after PTY reconnect PRs (#52962 #53227)","url":null,"state":"closed"},{"kind":"pr","number":54047,"title":"fix(dashboard): race PTY reader against WS receive to prevent FD leak (#54028)","url":null,"state":"closed","close_reason":{"refs":[{"kind":"commit","value":"6d879d486b19716f8b09bd47bffb0b6e5b690431","number":0},{"kind":"pr","value":"#54123","number":54123},{"kind":"pr","value":"#54028","number":54028}],"category":"implemented_elsewhere","implication":"superseded"},"merged":false},{"kind":"pr","number":54123,"title":"fix(dashboard): close PTY WebSocket on child EOF to stop FD leak (#54028)","url":null,"state":"merged","close_reason":{"category":"merged"},"merged":true,"is_fix_pr":true,"fix_tier":"verified","files_changed":["hermes_cli/web_server.py","infographic/pr-54028-pty-fd-leak/infographic.png","tests/hermes_cli/test_web_server_pty_reconnect.py"],"fix_hunks":[{"file":"hermes_cli/web_server.py","hunks":["@@ -12188,26 +12188,44 @@ async def pty_ws(ws: WebSocket) -> None:\n \n     # --- reader task: PTY master → WebSocket ----------------------------\n     async def pump_pty_to_ws() -> None:\n-        while True:\n-            chunk = await loop.run_in_executor(\n-                None, bridge.read, _PTY_READ_CHUNK_TIMEOUT\n-            )\n-            if chunk is None:  # EOF\n-                return\n-            if not chunk:  # no data this tick; yield control and retry\n-                await asyncio.sleep(0)\n-                continue\n+        try:\n+            while True:\n+                chunk = await loop.run_in_executor(\n+                    None, bridge.read, _PTY_READ_CHUNK_TIMEOUT\n+                )\n+                if chunk is None:  # EOF\n+                    return\n+                if not chunk:  # no data this tick; yield control and retry\n+                    await asyncio.sleep(0)\n+                    continue\n+                try:\n+                    await ws.send_bytes(chunk)\n+                except Exception:\n+                    return\n+        finally:\n+            # The child has exited (EOF) or the send side broke.  Close the\n+            # WebSocket so the writer loop's ``ws.receive()`` returns instead\n+            # of blocking forever — otherwise, when the browser's socket is\n+            # half-open (no FIN delivered, common on macOS/launchd) the\n+            # handler never reaches its ``finally`` and the PTY's fds leak.\n+            # With dashboard auto-reconnect (#52962) every dropped socket then\n+            # stacks a fresh PTY on top of the orphaned one, exhausting fds.\n             try:\n-                await ws.send_bytes(chunk)\n+                await ws.close()\n             except Exception:\n-                return\n+                pass\n \n     reader_task = asyncio.create_task(pump_pty_to_ws())\n \n     # --- writer loop: WebSocket → PTY master ----------------------------\n     try:\n         while True:\n-            msg = await ws.receive()\n+            try:\n+                msg = await ws.receive()\n+            except RuntimeError:\n+                # Raised when ws.receive() is called after the socket is\n+                # already disconnected (e.g. closed by the reader task above).\n+                break\n             msg_type = msg.get(\"type\")\n             if msg_type == \"websocket.disconnect\":\n                 break"]},{"file":"tests/hermes_cli/test_web_server_pty_reconnect.py","hunks":["@@ -16,6 +16,7 @@\n class _OneFrameBridge:\n     def __init__(self):\n         self._sent = False\n+        self.closed = False\n \n     @classmethod\n     def spawn(cls, *args, **kwargs):","@@ -34,7 +35,7 @@ def write(self, raw):\n         pass\n \n     def close(self):\n-        pass\n+        self.closed = True\n \n \n @pytest.fixture","@@ -128,3 +129,40 @@ def fake_resolve(resume=None, sidecar_url=None, profile=None, active_session_fil\n     assert captured[\"resume\"] is None\n     assert captured[\"active_session_file\"] == str(active_file)\n     assert not active_file.exists()\n+\n+\n+def test_child_eof_closes_socket_and_bridge(pty_client, monkeypatch):\n+    \"\"\"Child EOF must close the WS server-side and reap the PTY.\n+\n+    Regression for the FD leak (#54028): the reader task hits EOF when the\n+    PTY child exits, but if the browser's socket is half-open (no FIN), the\n+    writer loop's ``ws.receive()`` would block forever and the PTY fds would\n+    never be closed. The reader now closes the WebSocket on EOF so the\n+    handler's ``finally`` runs ``bridge.close()``.\n+    \"\"\"\n+    ws, client, token = [redacted:secret-assignment]\n+    bridges = []\n+\n+    class _RecordingBridge(_OneFrameBridge):\n+        @classmethod\n+        def spawn(cls, *args, **kwargs):\n+            b = cls()\n+            bridges.append(b)\n+            return b\n+\n+    monkeypatch.setattr(ws.PtyBridge, \"spawn\", _RecordingBridge.spawn)\n+    monkeypatch.setattr(\n+        ws, \"_resolve_chat_argv\", lambda **kw: ([\"fake-hermes-tui\"], None, None)\n+    )\n+\n+    # The client never sends a disconnect of its own — it only reads the one\n+    # frame then the server side must tear everything down on child EOF.\n+    with client.websocket_connect(_url(token, channel=\"eof-chan\")) as conn:\n+        assert conn.receive_bytes() == b\"ready\"\n+        # Server closes the socket after the child EOFs; receiving again\n+        # surfaces the close rather than hanging.\n+        with pytest.raises(Exception):\n+            conn.receive_bytes()\n+\n+    assert len(bridges) == 1\n+    assert bridges[0].closed is True\n"]}]}],"trust":{"default_tier":"verified","includes_suggested":false}}