Skip to content

Commit

Permalink
WS
Browse files Browse the repository at this point in the history
  • Loading branch information
tofarr committed Nov 18, 2024
1 parent 6698b15 commit b10b8fe
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 26 deletions.
10 changes: 0 additions & 10 deletions frontend/src/context/ws-client-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion openhands/server/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions openhands/server/session/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import time
from dataclasses import dataclass, field

from fastapi import WebSocket
import socketio

from openhands.core.config import AppConfig
Expand Down Expand Up @@ -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
Expand Down
16 changes: 3 additions & 13 deletions openhands/server/session/session.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import time

from fastapi import WebSocket, WebSocketDisconnect
import socketio

from openhands.controller.agent import Agent
Expand Down Expand Up @@ -29,7 +28,6 @@

class Session:
sid: str
websocket: WebSocket | None
sio: socketio.AsyncServer | None
connection_ids: set[str]
last_active_ts: int = 0
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit b10b8fe

Please sign in to comment.