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)