Skip to content

fix: fix athrow() RuntimeError on streaming responses#912

Merged
sokoliva merged 8 commits into1.0-devfrom
ishymko/generators
Mar 27, 2026
Merged

fix: fix athrow() RuntimeError on streaming responses#912
sokoliva merged 8 commits into1.0-devfrom
ishymko/generators

Conversation

@ishymko
Copy link
Copy Markdown
Member

@ishymko ishymko commented Mar 27, 2026

When the server sends a Message event in the SSE stream, _process_stream does an early return abandoning the generator chain while the SSE connection is still open.

send_http_stream_request yields inside async with aconnect_sse(...). aconnect_sse (from httpx-sse) is an @asynccontextmanager .

During event loop shutdown, shutdown_asyncgens tries to finalize all tracked generators independently - two athrow() calls hit the same chain, producing the RuntimeError.

Replace aconnect_sse with _SSEEventSource - a class-based async context manager that calls httpx_client.send(..., stream=True) directly and response.aclose() in __aexit__.

Added test fails without a fix: https://github.com/a2aproject/a2a-python/actions/runs/23648762100/job/68887648853.

Fixes #911

@ishymko ishymko requested a review from a team as a code owner March 27, 2026 13:18
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the aconnect_sse utility with a custom _SSEEventSource class to prevent async generator leaks and associated RuntimeError during event-loop shutdown. An integration test has been added to ensure proper cleanup. Reviewer feedback recommends using httpx.Headers for more robust header management and updating a placeholder issue reference in the test file.

ishymko and others added 2 commits March 27, 2026 13:22
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ishymko ishymko marked this pull request as draft March 27, 2026 13:24
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

🧪 Code Coverage (vs 1.0-dev)

⬇️ Download Full Report

Base PR Delta
src/a2a/client/transports/http_helpers.py 94.64% 94.44% 🔴 -0.20%
src/a2a/server/tasks/task_manager.py 97.44% 98.29% 🟢 +0.85%
Total 91.57% 91.59% 🟢 +0.02%

Generated by coverage-comment.yml

@ishymko ishymko marked this pull request as ready for review March 27, 2026 13:37
@sokoliva sokoliva merged commit ca7edc3 into 1.0-dev Mar 27, 2026
18 checks passed
@sokoliva sokoliva deleted the ishymko/generators branch March 27, 2026 14:48
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.

2 participants