Skip to content

[Bug]: SSE client drops the last event when the stream ends without a blank line #1213

Closed

Description

@anxkhn

What happened?

parse_sse_stream in src/a2a/client/transports/http_helpers.py only yields an event when it sees a blank line. If the peer closes the connection after data: {...} with no trailing blank line, leftover payload_chunks are thrown away.

WHATWG SSE says a pending event must be dispatched when the connection closes. JsonRpcTransport and RestTransport both use this parser, so a completed Task/Message can vanish and the client sits there as if the stream is still open.

Repro

  1. Feed parse_sse_stream a response whose last lines are data: {"task":{...}} with no following empty line.
  2. Exhaust the generator.

Observed: zero events.
Expected: one ("message", "{...}") event.

Existing tests always send a trailing \n, so this path is untested.

Relevant log output

n/a. Unit-reproducible in tests/client/transports/test_http_helpers.py.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. self-assigned this
    on Aug 28, 2026
  2. added theissue type on Aug 28, 2026
  3. added
    component: client
    on Aug 29, 2026
  4. rohityan commented on Aug 29, 2026

    @rohityan

    Hi @anxkhn , Thanks for opening both the issue and contributing towards the fix. Until the PR gets reviewed you could on Server-Side
    ensure the streaming endpoint explicitly appends a final blank line after the last data: frame before terminating the HTTP response.
    If consuming third-party streams on the client side you can wrap the raw byte/line stream before passing it to the SSE parser to inject an artificial trailing newline when the connection closes. This forces the parser to flush and yield the final buffered event before exiting.

    Assigning the issue to you till the PR gets reviewed.

  5. assigned and unassigned on Aug 29, 2026
  6. mykytanetipa commented on Aug 30, 2026

    @mykytanetipa
    Collaborator

    @anxkhn The rationale is inverted. WHATWG SSE (9.2.6, https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation) requires the opposite: "Once the end of the file is reached, any pending data must be discarded. (If the file ends in the middle of an event, before the final empty line, the incomplete event is not dispatched.)"

    So the parser is already correct, the client should discard an unterminated trailing event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

component: client

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions