Skip to content

fix(session): count a final error event as a final response - #2285

Merged
jjsasha63 merged 2 commits into
google:mainfrom
jjsasha63:fix/session-final-error
Nov 12, 2026
Merged

jjsasha63 merged 2 commits into
google:mainfrom
jjsasha63:fix/session-final-error

Conversation

@jjsasha63

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Linked issue

None.

2. Describe the change:

Problem:
Event.IsFinalResponse ignores ErrorCode. 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-empty ErrorCode that 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 ErrorCode set, Partial false, no function calls, and a function response or a trailing code execution result in its content now reports IsFinalResponse() == true. Before this change it reported flase. Effects for code on the current release:

  • The LLM flow ends the turn on such an event instead of calling the model again.
  • Every other IsFinalResponse reader treats it as final too: OutputKey saving in llmagent, MessageAsOutput in workflow agent nodes, the console launcher and the logging plugin.
  • The BigQuery agent analytics plugin now writes an AGENT_RESPONSE row for such an event when it has visible text. adk-python's analytics plugin logs the same row for an agent's MAX_TOKENS error event whose content is text followed by a code execution result. It gates on is_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.go already lists that difference for AGENT_RESPONSE.

Events without an error code, partial events and events with function calls behave as befroe.

Testing Plan

Unit Tests:

  • All unit tests pass locally.

I added TestIsFinalResponseErrorEvent in session/event_test.go, a table test with these cases:

  • error with a function response is final
  • error with a trailing code execution result is final
  • error without content is final
  • error with a function call is not final
  • partial error is not final
  • function response without error is not final

No existing tests needed new expectations.

Results:

  • go build ./... succeeds.
  • go test -race -count=1 passes 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 -diff prints nothing.

With your source change reverted and your tests kept, which test fails?

  • TestIsFinalResponseErrorEvent/error_with_a_function_response_is_final
  • TestIsFinalResponseErrorEvent/error_with_a_trailing_code_execution_result_is_final

I also removed each condition of the new clause in turn. Dropping !Partial fails partial_error_is_not_final. Dropping !hasFunctionCalls fails error_with_a_function_call_is_not_final. Dropping the ErrorCode check fails function_response_without_error_is_not_final and three TestIsFinalResponseNilParts cases.

Parity:

  • I read 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.
  • adk-go's existing compaction check still runs first, so a compaction event that carries an error code stays not final. adk-python has no compaction clause in this method.
  • Nothing is left unported in this method.

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 cases test_is_final_response_error_event_with_function_call_is_not_final and test_is_final_response_partial_error_event_is_not_final.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

None.

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.
@jjsasha63 jjsasha63 self-assigned this Nov 12, 2026
@jjsasha63
jjsasha63 requested a review from wojtas000 November 12, 2026 14:37

@wojtas000 wojtas000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread session/event_test.go Resolved
@jjsasha63
jjsasha63 merged commit d9ecb34 into google:main Nov 12, 2026
15 checks passed
@jjsasha63
jjsasha63 deleted the fix/session-final-error branch November 12, 2026 15:24
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants