OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

Allow the agent to continue to work in background for N minutes even after websocket closes

Open diwu-sf opened this issue 1 year ago • 0 comments

What problem or use case are you trying to solve? If the websocket connection to the UI is closed or broken, the agent session is closed, and controller is closed. The Agent no longer continues to work on the task.

In order for the agent to be able to work autonomously on the task, it should be possible to configure the session to "keep running" for up to N minutes even if the websocket is disconnected.

Describe the UX of the solution you'd like

  • A configuration that allows the agent to continue working autonomously even without a UI websocket attached
  • Reconnecting with the same session ID (stored in local storage) will attach a new websocket to the already running agent runtime
  • The exit project / start new project button explicitly terminates the agent session & runtime

Do you have thoughts on the technical implementation?

  • On websocket close, don't call close on the session, just unsubscribe from the event stream
  • Session has a detach() method in addition to a close() method, detach just disconnects the websocket
  • Add a similar attach() method that can swap the "main" websocket connection
  • To keep things simple in case a websocket is already attached to a session, we can either introduce the idea of read-only observer websockets, or just reject more than 1 websocket attach to an already attached session

The observer websocket is useful if multiple people on the same team wants to watch the agent work on a specific task.

Describe alternatives you've considered Refactoring a lot of this to just decouple websocket completely from the Session. Session writes into a durable message log, all websockets just read from that message log (attach just replay messages from beginning of session).

Additional context Devin can work independently on a task, without relying on browser tab being open. OpenHands should be able to work independently for some time too.

diwu-sf avatar Nov 15 '24 06:11 diwu-sf