Skip to content

fix: flush the last SSE event when the stream ends without a blank line - #1216

Open
anxkhn wants to merge 1 commit into
a2aproject:mainfrom
anxkhn:fix/sse-stream-flush-eof
Open

fix: flush the last SSE event when the stream ends without a blank line#1216
anxkhn wants to merge 1 commit into
a2aproject:mainfrom
anxkhn:fix/sse-stream-flush-eof

Conversation

@anxkhn

@anxkhn anxkhn commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Description

  • Follow the CONTRIBUTING Guide
  • Conventional Commits title
  • Tests and linter pass
  • Docs updated if necessary

Fixes #1213

Summary

parse_sse_stream only yields on a blank line. If the peer closes after data: {...} with no trailing blank line, leftover payload is dropped.

WHATWG SSE requires dispatching a pending event when the connection closes. JsonRpcTransport and RestTransport both use this parser, so a completed Task or Message can vanish and the client waits as if the stream is still open.

After the aiter_lines loop, if payload_chunks is non-empty, the pending event is now yielded the same way a blank line would. Existing tests already send a trailing newline and stay green.

Testing

Added test_parse_sse_stream_flushes_last_event_without_blank_line in tests/client/transports/test_http_helpers.py.

uv run pytest tests/client/transports/test_http_helpers.py -q

4 passed.

Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
@anxkhn
anxkhn requested a review from a team as a code owner August 27, 2026 21:10
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

Base PR Delta
src/a2a/client/transports/http_helpers.py 95.54% 95.69% 🟢 +0.15%
Total 93.12% 93.12% ⚪️ 0.00%

Generated by coverage-comment.yml

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant