Skip to content

Session socket drops a message sent to a running conversation #6708

Closed

Description

@enyst

Problem

A session socket (/sockets/session/{id}) opened on a conversation whose agent is running reads no client frame until the current step ends. session_socket awaits event_service.subscribe_to_events() before starting _inbound_loop. Subscribing builds the initial-state snapshot under the conversation's state lock (_create_initial_state_sync), and LocalConversation.run holds that lock for the whole agent step.

So for the length of a step (40 s in the case below) the socket sends nothing back and reads nothing in. If the client leaves meanwhile, the writer's close wins the race in _inbound_loop, and the person's message frame is dropped: no MessageEvent is saved.

Seen live

During a Projects demo, two messages sent to running worker conversations never arrived. The browser log shows the socket open, 2 frames sent (the first frame plus the message), 0 frames received for about 40 s, and then a close. An identical send to an idle conversation was delivered.

Expected

A message the client sent is saved and runs once the step ends, even if the client leaves first. A frame that arrives together with the close is still handled.

Acceptance criteria

  • Inbound frames are read from connect, not only after the snapshot.
  • A message already taken is saved even when the socket closes before the state lock frees.
  • Tests cover both cases, and they fail without the fix.

OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

Verified in the code: session_socket awaits event_service.subscribe_to_events() before starting _inbound_loop, and subscribing builds the initial-state snapshot under the conversation's state lock (_create_initial_state_sync); LocalConversation.run/arun holds that lock across the whole agent step apart from its LLM-call release windows, so a client frame sent during a step is not read until the step ends. Separately, _inbound_loop discards a frame that completes together with the writer's close, and a send_message already in flight is abandoned when the loop returns on close, so the message is lost.

The live Projects-demo incident in this report (two messages sent to running conversations never arrived; an identical send to an idle conversation was delivered) is a real user-facing failure with unrecoverable message loss, so this is prioritized high.

Scope: the agent-server session-socket inbound path only. The fix must keep using the existing _inbound_loop/_ConnectionWriter plumbing and the existing event_service.send_message path, including its current run/rerun semantics for a message sent mid-step — no parallel inbound mechanism.

Non-goals: no changes to the legacy /sockets/events/{id} endpoint; no change to LocalConversation state-lock or agent-step semantics; no change to the session-socket frame protocol, snapshot behavior, or after_seq resume semantics; no TypeScript-client or Canvas changes.

Acceptance Criteria

  • While an agent step is running on the conversation (state lock held), a client that opens /sockets/session/{id} and sends a message frame has that frame read from the socket immediately: an automated test asserts the frame is consumed while the lock is still held, not after the step completes. (This currently fails: reading waits for the snapshot behind subscribe_to_events.)
  • When the client closes the socket after sending that frame — the close racing or preceding the lock release — the message is still persisted as a MessageEvent in the conversation's event log, and the conversation processes it (a run picks it up) once the current step ends.
  • A message frame that completes together with the writer close in _inbound_loop (both observed in the same wait) is validated and persisted, not discarded.
  • Existing inbound behavior is preserved: malformed frames still produce an ErrorFrame and keep the connection open, auth control messages are still ignored, and the session-socket suites in tests/agent_server/test_session_socket.py and tests/agent_server/test_agent_server_wsproto.py pass.

Activity

  1. added
    priority:high
    ready-for-dev
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:highready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions