diff --git a/frontend/src/context/ws-client-provider.tsx b/frontend/src/context/ws-client-provider.tsx index ab700a1fed57..1c85d282b48a 100644 --- a/frontend/src/context/ws-client-provider.tsx +++ b/frontend/src/context/ws-client-provider.tsx @@ -147,16 +147,6 @@ export function WsClientProvider({ import.meta.env.VITE_BACKEND_BASE_URL || window?.location.host; sio = io(baseUrl, { transports: ["websocket"], - // We force a new connection, because the headers may have changed. - // forceNew: true, - - // Had to do this for now because reconnection actually starts a new session, - // which we don't want - The reconnect has the same headers as the original - // which don't include the original session id - // reconnection: true, - // reconnectionDelay: 1000, - // reconnectionDelayMax : 5000, - // reconnectionAttempts: 5 }); } sio.on("connect", handleConnect); diff --git a/openhands/server/listen.py b/openhands/server/listen.py index fa90e477beee..a804b4103fa4 100644 --- a/openhands/server/listen.py +++ b/openhands/server/listen.py @@ -838,7 +838,6 @@ async def get_response(self, path: str, scope): app.mount('/', SPAStaticFiles(directory='./frontend/build', html=True), name='dist') client_manager = None -# This is where we add the redis manager redis_host = os.environ.get('REDIS_HOST') if redis_host: client_manager = socketio.AsyncRedisManager(redis_host) diff --git a/openhands/server/session/manager.py b/openhands/server/session/manager.py index b3d41b603117..2d86d738f0c0 100644 --- a/openhands/server/session/manager.py +++ b/openhands/server/session/manager.py @@ -2,7 +2,6 @@ import time from dataclasses import dataclass, field -from fastapi import WebSocket import socketio from openhands.core.config import AppConfig @@ -46,7 +45,7 @@ async def init_or_join_local_session(self, sio: socketio.AsyncServer, sid: str, if not session: # I think we need to rehydrate here, but it does not seem to be working session = Session( - sid=sid, file_store=self.file_store, config=self.config, sio=sio, ws=None + sid=sid, file_store=self.file_store, config=self.config, sio=sio ) session.connect(connection_id) self.local_sessions_by_sid[sid] = session diff --git a/openhands/server/session/session.py b/openhands/server/session/session.py index 99d08e2814fe..7f1765c83a4e 100644 --- a/openhands/server/session/session.py +++ b/openhands/server/session/session.py @@ -1,7 +1,6 @@ import asyncio import time -from fastapi import WebSocket, WebSocketDisconnect import socketio from openhands.controller.agent import Agent @@ -29,7 +28,6 @@ class Session: sid: str - websocket: WebSocket | None sio: socketio.AsyncServer | None connection_ids: set[str] last_active_ts: int = 0 @@ -38,10 +36,9 @@ class Session: loop: asyncio.AbstractEventLoop def __init__( - self, sid: str, ws: WebSocket | None, config: AppConfig, file_store: FileStore, sio: socketio.AsyncServer | None + self, sid: str, config: AppConfig, file_store: FileStore, sio: socketio.AsyncServer | None ): self.sid = sid - self.websocket = ws self.sio = sio self.last_active_ts = int(time.time()) self.agent_session = AgentSession( @@ -63,12 +60,7 @@ def disconnect(self, connection_id: str) -> bool: def close(self): self.is_alive = False - try: - if self.websocket is not None: - asyncio.run_coroutine_threadsafe(self.websocket.close(), self.loop) - self.websocket = None - finally: - self.agent_session.close() + self.agent_session.close() async def initialize_agent(self, data: dict): self.agent_session.event_stream.add_event( @@ -173,8 +165,6 @@ async def send(self, data: dict[str, object]) -> bool: try: if not self.is_alive: return False - if self.websocket: - await self.websocket.send_json(data) if self.sio: await wait_all( self.sio.emit("oh_event", data, to=connection_id) @@ -183,7 +173,7 @@ async def send(self, data: dict[str, object]) -> bool: await asyncio.sleep(0.001) # This flushes the data to the client self.last_active_ts = int(time.time()) return True - except (RuntimeError, WebSocketDisconnect): + except RuntimeError: self.is_alive = False return False