Repository navigation
Conversation
A non-streaming action halted through ``astream_result`` never starts a stream, so ``pre_start_stream`` is not called for it. The exception handler nevertheless called ``post_end_stream`` unconditionally. Adapters that keep per-stream state -- such as the local tracking client, whose ``post_end_stream`` looks the entry up in ``stream_state`` -- raised a ``KeyError`` from inside the handler, replacing the action's exception with an unrelated one. Track whether ``pre_start_stream`` completed and fan out ``post_end_stream`` only for streams that actually started. Cleanup for streams that did start is unchanged. Fixes apache#999
This was referenced Nov 1, 2026
Member
|
This makes the same source change as #1000, which was opened on Oct 27 for the same issue (#999): a I applied both on current |
This branch has not been deployed
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.
Why are these changes needed?
Application.astream_result()ends a stream in two places: the success path and the exception handler. The exception handler calledpost_end_streamunconditionally, butpre_start_streamonly runs for streaming actions. A non-streaming action that raises therefore fans outpost_end_streamfor a stream that was never started.Adapters that keep per-stream state blow up there.
LocalTrackingClient.post_end_streamlooks the stream up instream_state-- which onlypre_start_streampopulates -- so it raisedKeyErrorfrom inside the handler and replaced the action's own exception with an unrelated one. Because the handler runs while the original exception is in flight, users saw a bareKeyErrorwith no trace of the real failure, even when their application code raised something perfectly readable.This tracks whether
pre_start_streamcompleted and only fans outpost_end_streamwhen it did. Streams that did start are cleaned up exactly as before, sostream_statebookkeeping is unchanged for the streaming path.Fixes #999
Related issue number
#999
Checks
make lint && make test(see notes below on the local equivalent)Verification details:
tests/core/test_application.py-- 143 passedtests/tracking/test_local_tracking_client.py-- 17 passed, 1 skippedtests/core-- 426 passed; the 9 failures are all intest_graphviz_display.pyand come from the optionalgraphvizpackage being absent in this environment, unrelated to this changeblack --line-length 100 --checkpassesTwo regression tests were added:
test_astream_result_non_streaming_exception_skips_post_end_stream(core): asserts the lifecycle hook is not invoked when the action is not streamingtest_astream_result_preserves_non_streaming_action_exception(tracking): asserts the action'sValueErrorreaches the caller with the built-in local tracker attached