From a200955ef29f2cbdd699263cc805a1be2cbff15d Mon Sep 17 00:00:00 2001 From: Fusion Date: Thu, 21 May 2026 11:19:11 +0200 Subject: [PATCH] fix(terminal): remove duplicate WebSocket read loop, let terminal_manager handle I/O --- apps/api/src/api/terminal.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/apps/api/src/api/terminal.py b/apps/api/src/api/terminal.py index 86bf740..dba3f36 100644 --- a/apps/api/src/api/terminal.py +++ b/apps/api/src/api/terminal.py @@ -1,5 +1,6 @@ """WebSocket terminal endpoint for tool instances.""" +import asyncio import logging import uuid @@ -82,16 +83,10 @@ async def terminal_websocket( # Send connected status await websocket.send_json({"type": "status", "status": "connected"}) - # Keep connection alive until closed - while True: - try: - message = await websocket.receive() - if message["type"] == "websocket.disconnect": - break - except WebSocketDisconnect: - break - except RuntimeError: - break + # Keep connection alive until session ends + # The terminal_manager handles I/O loops, we just wait here + while session.is_alive() and not session._closed: + await asyncio.sleep(0.5) except Exception as exc: logger.error("Terminal session error for instance %s: %s", instance_id, str(exc), exc_info=True)