Skip to content

Wait helpers ignore event: error and duplicate the stream parser #20

Open

Description

@burgaard

What's wrong

run_streaming_agent_and_wait() (sync and async) has its own copy of the SSE parser, separate from run_streaming_agent(). The copies have drifted, and the wait helpers mishandle several stream endings:

  • event: error and event: timeout are ignored. The server sends error when the stream fails internally, and timeout after 600s, then closes the stream. The wait helper treats that as an early end: by default it returns the unfinished init snapshot with no error. With raise_on_incomplete=True it raises a generic "stream ended" error, and the server's message is lost.
  • A cut connection discards an event that was already read. In the default mode, a done or result whose lines arrived before an httpx transport error is dropped, and the raw error is raised instead.
  • No plain-JSON fallback. A JSON reply yields nothing from run_streaming_agent(), and the wait helper raises with no snapshot. The JS, Go and C# SDKs handle this.

Why it matters

A run that failed on the server can come back looking like an unfinished success, with no error. The two other bugs share the same cause: each fix has to land in four parser copies.

Done when

  • The wait helpers are built on the same parser as run_streaming_agent() (one parser for sync, one for async).
  • event: error raises SeclaiStreamingError with the server's message and the latest snapshot in run.
  • event: timeout raises SeclaiStreamingError with the latest snapshot in run.
  • Each case above has a test.

Out of scope

Changing what the default mode returns for a stream that ends without done. That stays as released until raise_on_incomplete becomes the default in the next major version.

Found in the review of #19.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions