fix(streamable-http): surface transport faults to callers and message_handler - #3318
Open
functionxX wants to merge 4 commits into
Open
fix(streamable-http): surface transport faults to callers and message_handler#3318functionxX wants to merge 4 commits into
functionxX wants to merge 4 commits into
Conversation
…_handler When a streamable-http response stream dies with a transport error, the exception was swallowed: the pending request got a generic CONNECTION_CLOSED error and the fault never reached message_handler. Forward the exception into the read stream as an Exception item and carry it into the synthesized error messages on both the immediate and reconnect-exhausted paths.
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.
Fixes #1401
What changed
When a streamable-http response stream dies with a transport error (e.g.
httpx.ReadTimeoutfromsse_read_timeout), the original exception wasswallowed:
CONNECTION_CLOSEDerror("SSE stream ended without a response" / "reconnection attempts were
exhausted"), hiding the root cause from user code.
message_handler, even though theIncomingMessagecontract says transport-level exceptions are delivered there.
Now:
_handle_sse_responsecaptures the stream exception and forwards it into theread stream as an
Exceptionitem, so the session'smessage_handlerobserves the fault (custom handlers, like the one the reporter built as a
workaround, now receive it). The synthesized error keeps code
CONNECTION_CLOSEDand carries the exception in its message._handle_reconnectioncarries the latest failure through the retry loop andincludes it in the exhausted-budget error message.
_forward_stream_faulthelper, best-effort like_resolve_abandoned_request.How verified
test_a_non_resumable_sse_drop_resolves_the_request_with_an_errorand
test_exhausted_reconnection_attempts_resolve_the_request_with_an_errorto assert the fault item and the exception in the error message.
test_an_id_bearing_stream_that_dies_surfaces_the_fault_and_resolves_the_requestcovering the reconnect-exhausted path end to end.
pytest tests/client: 703 passed, 8 skipped, 1 xfailed; one unrelatedpre-existing failure in
test_transport_stream_cleanup.py(also fails onclean main on this machine).
ruff check,ruff format, andpyrightclean.Disclosure: this contribution was written with AI assistance and personally reviewed and tested by me.