fix: fix athrow() RuntimeError on streaming responses#912
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
🧪 Code Coverage (vs
|
| 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
sokoliva
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the server sends a
Messageevent in the SSE stream,_process_streamdoes an early return abandoning the generator chain while the SSE connection is still open.send_http_stream_requestyields insideasync with aconnect_sse(...).aconnect_sse(from httpx-sse) is an@asynccontextmanager.During event loop shutdown,
shutdown_asyncgenstries to finalize all tracked generators independently - twoathrow()calls hit the same chain, producing theRuntimeError.Replace
aconnect_ssewith_SSEEventSource- a class-based async context manager that callshttpx_client.send(..., stream=True)directly andresponse.aclose()in__aexit__.Added test fails without a fix: https://github.com/a2aproject/a2a-python/actions/runs/23648762100/job/68887648853.
Fixes #911