Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
r14dd
force-pushed
the
fix/7973-stream-error-code
branch
from
November 10, 2026 13:15
0691eb0 to
8c5157d
Compare
r14dd
marked this pull request as ready for review
November 10, 2026 13:23
r14dd
force-pushed
the
fix/7973-stream-error-code
branch
from
November 25, 2026 16:43
8c5157d to
3510bfd
Compare
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
StreamingResponseAggregator.close()setserror_codeanderror_messagefromfinish_reasonfor every non-STOP finish reason, even when the aggregated response has content.LlmResponse.create(non-streaming) sets them only when there is no content. So the same MAX_TOKENS reply with text is an error underStreamingMode.SSEand not underStreamingMode.NONE.Solution:
In both
close()branches (progressive SSE and the old path), clearerror_codeanderror_messagewhen the aggregated content has parts and there is a candidate. This matchesLlmResponse.create, which sets an error only when the candidate has no content. An empty reply with a non-STOP finish reason still returns the error, andfinish_reasonis kept on the response.Behaviour change for streaming callers: a caller that reads
error_codeto detect a non-STOP finish (MAX_TOKENS, SAFETY, RECITATION, ...) on a response that has content must readfinish_reasoninstead, as non-streaming callers already do.Scope, as agreed on #7973:
ReflectAndRetryModelPluginis untouched and still needserror_code, so truncated text is not retried in either mode.ReflectAndRetryModelPlugin) is a separate PR and not included.error_codeon any non-STOP finish even with content, so Gemini and LiteLlm still differ. Out of scope here; related: LiteLlm finalizes a stream cut off mid-answer as finish_reason STOP with no error #7693 (LiteLlm finish_reason on a stream cut off mid-answer).Testing Plan
Unit Tests:
I have added or updated unit tests for my change.
All unit tests pass locally.
New
test_close_error_matches_llm_response_create(tests/unittests/utils/test_streaming_utils.py): the same response goes throughLlmResponse.createand the aggregator, in both progressive and non-progressive mode, for STOP, MAX_TOKENS, SAFETY, RECITATION and OTHER, with text and with no parts. It compareserror_code,error_messageandfinish_reason.Four existing tests pinned the old SSE behaviour and are updated to the
createbehaviour (finish_reasonkept,error_codeanderror_messagecleared):test_close_with_error,test_generate_content_async_stream_aggregated_content_regardless_of_finish_reason,test_generate_content_async_stream_with_thought_and_text_error_handling,test_generate_content_async_stream_error_info_set_for_non_stop_finish_reason.With the
close()change reverted, the new parity test andtest_close_with_errorfail (9 failures across the two).Manual End-to-End (E2E) Tests:
I ran the same MAX_TOKENS-with-text response through
InMemoryRunnerin both modes (details in this comment on #7973), on main70e1cbdwith the same rule applied inclose():error_code=Noneerror_code=MAX_TOKENSerror_code=Noneerror_code=NoneAn empty MAX_TOKENS reply still comes back as an error in both modes.
Checklist
Additional context
Direction picked by the triager on #7973 (streaming change only, full
createrule rather than MAX_TOKENS only).