Skip to content

Add turn-complete signal for session_update notifications #554

@simonrosenberg

Description

@simonrosenberg

Problem

After a prompt() call returns, there is no protocol-level signal indicating that all session_update notifications for that turn have been delivered. Clients that accumulate state from these notifications (e.g. streamed text chunks, usage updates) must resort to heuristic delays (asyncio.sleep) to wait for in-flight notifications to arrive before reading the accumulated result.

This is inherently racy — too short a delay misses late notifications, too long a delay adds unnecessary latency.

Current workaround

In OpenHands, we yield to the event loop and then sleep for a configurable duration (default 0.1s) after prompt() returns:

response = await conn.prompt(messages, session_id)
await asyncio.sleep(0)  # yield to let queued handlers run
await asyncio.sleep(0.1)  # wait for in-flight notifications

Proposed solution

Add a protocol-level mechanism that signals when all notifications for a given turn have been delivered. For example:

  • A dedicated turn_complete notification sent by the server after all session_update notifications for a prompt response
  • Or a field on the PromptResponse indicating whether all associated notifications have been flushed

This would let clients reliably synchronize without arbitrary delays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions