Repository navigation
fix(session): count a final error event as a final response - #2285
Merged
Merged
Conversation
Event.IsFinalResponse ignored the error code. An error event that carried a function response or a trailing code execution result was reported as not final. The LLM flow then called the model again instead of ending the turn on the errror. adk-python's Event.is_final_response treats an event with an error code as final when it is not partial and has no function calls. IsFinalResponse now applies the same rule. An error event with a function call or a partial error event is still not final.
wojtas000
approved these changes
Nov 12, 2026
wojtas000
left a comment
Contributor
There was a problem hiding this comment.
The new clause matches is_final_response in adk-python, and the function-response and trailing code-result cases fail on main and pass with this change. One optional nit inline, which doesn't block.
wolo-lab
added a commit
that referenced
this pull request
Nov 16, 2026
, #1919, #2189, #2285) (#2346) * fix(session/vertexai): drop temp: keys from the initial state on Create (#2100) (cherry picked from commit 0c109f7) * fix(session): keep in-memory Get from returning events before After (#2089) (cherry picked from commit 10395f0) * fix(session/database): lock app and user state rows in Create (#1930) (cherry picked from commit 2f3b2c2) * fix(session/database): delete a session's events explicitly in Delete (#1774) (cherry picked from commit 7af0f5f) * fix(session): define List order as last update time ascending (#1919) (cherry picked from commit 8be7e25) * fix(session): skip nil parts in IsFinalResponse classification (#2189) (cherry picked from commit 75ae920) * fix(session): count a final error event as a final response (#2285) (cherry picked from commit d9ecb34)
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.
Linked issue
None.
2. Describe the change:
Problem:
Event.IsFinalResponseignoresErrorCode. An error event that carries a function response or a trailing code execution result is reproted as not final. The LLM flow then calls the model again instead of ending the turn on the error. adk-python reports the same event as final.Solution:
Add adk-python's clause to
IsFinalResponse: an event with a non-emptyErrorCodethat is not partial and has no function calls is final. An error event with a function call, and a partial error event, stay not final. No public API changes.Behavior change
An event with
ErrorCodeset,Partialfalse, no function calls, and a function response or a trailing code execution result in its content now reportsIsFinalResponse() == true. Before this change it reported flase. Effects for code on the current release:IsFinalResponsereader treats it as final too:OutputKeysaving inllmagent,MessageAsOutputin workflow agent nodes, the console launcher and the logging plugin.AGENT_RESPONSErow for such an event when it has visible text. adk-python's analytics plugin logs the same row for an agent'sMAX_TOKENSerror event whose content is text followed by a code execution result. It gates onis_final_response()too (plugins/bigquery_agent_analytics_plugin.py, lines 8229-8248). For an error event that carries a function response next to visible text, Go now writes a row that adk-python does not. adk-python's plugin also skips events with function responses (line 8236), and Go's does not.plugin/agentanalytics/doc.goalready lists that difference forAGENT_RESPONSE.Events without an error code, partial events and events with function calls behave as befroe.
Testing Plan
Unit Tests:
I added
TestIsFinalResponseErrorEventinsession/event_test.go, a table test with these cases:No existing tests needed new expectations.
Results:
go build ./...succeeds.go test -race -count=1passes for./session/,./internal/llminternal/,./agent/llmagent/and./workflow/.go test -count=1 ./...passes in all 119 packages that have tests.golangci-lint run --new-from-rev=origin/main ./...reports 0 issues.go mod tidy -diffprints nothing.With your source change reverted and your tests kept, which test fails?
TestIsFinalResponseErrorEvent/error_with_a_function_response_is_finalTestIsFinalResponseErrorEvent/error_with_a_trailing_code_execution_result_is_finalI also removed each condition of the new clause in turn. Dropping
!Partialfailspartial_error_is_not_final. Dropping!hasFunctionCallsfailserror_with_a_function_call_is_not_final. Dropping theErrorCodecheck failsfunction_response_without_error_is_not_finaland threeTestIsFinalResponseNilPartscases.Parity:
src/google/adk/events/event.py(Event.is_final_response, lines 297 to 302 in adk-python 2.12.0). The new clause has the same three conditions in the same order, after the skip-summarization and long-running-tool check.Manual End-to-End (E2E) Tests:
I did not run a manual end-to-end test. adk-go now matches the adk-python unit test
tests/unittests/events/test_event.py::test_is_final_response_error_event_with_function_response_is_final. The Go table also covers the neighboring adk-python casestest_is_final_response_error_event_with_function_call_is_not_finalandtest_is_final_response_partial_error_event_is_not_final.Checklist
Additional context
None.