Skip to content

fix: ignore stale function responses#766

Open
gustafvh wants to merge 1 commit into
google:mainfrom
freda-ab:fix/tolerate-orphan-function-responses
Open

fix: ignore stale function responses#766
gustafvh wants to merge 1 commit into
google:mainfrom
freda-ab:fix/tolerate-orphan-function-responses

Conversation

@gustafvh
Copy link
Copy Markdown

Link to Issue or Description of Change

Problem

rearrangeEventsForLatestFunctionResponse returns an error when the latest event is a function response and no matching function-call event can be found in session history:

no function call event found for function responses ids: ...

That is appropriate for malformed history, but it also fires when a stale tool result is replayed after a retry, reconnect, or session restart. The dangling response could be safely ignored; failing the whole request prevents the next turn from continuing on otherwise valid history.

Solution

When the latest function-response event has no matching call in history, drop only that trailing event and continue with the remaining valid contents. Other validation errors, such as a response set partially matching the wrong call event, remain hard errors.

Testing Plan

  • Added coverage for a trailing orphaned function response after normal user history.
  • Added coverage for a trailing orphaned function response after a model text reply.
  • Ran focused unit tests locally.
go test ./internal/llminternal

Alignment with adk-python

This is specific to ADK Go's content-history rearrangement path. The shared behavior goal is that stale client retries should not make otherwise valid session history unusable.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the contents_processor to handle orphaned function response events by dropping them instead of returning an error. This change treats such events as stale (e.g., from retries or reconnections) to prevent failing the entire turn. Corresponding tests have been updated and expanded to verify this new behavior. I have no feedback to provide.

@radhus
Copy link
Copy Markdown

radhus commented Apr 28, 2026

@mazas-google tagging you here

@indurireddy-TF
Copy link
Copy Markdown
Contributor

Hi @radhus @gustafvh Could you please sync this PR with the latest changes from the base branch so we can review it? Thanks!

When the latest event is a function response whose IDs do not match any
function-call event in session history (stale client retry, reconnect,
session restart), drop only that trailing event and continue with the
remaining valid history instead of hard-failing content construction.

Fixes google#760
@radhus radhus force-pushed the fix/tolerate-orphan-function-responses branch from 866f976 to c8017fb Compare May 4, 2026 09:35
@radhus
Copy link
Copy Markdown

radhus commented May 4, 2026

Hi @radhus @gustafvh Could you please sync this PR with the latest changes from the base branch so we can review it? Thanks!

Just rebased 🙏

@indurireddy-TF
Copy link
Copy Markdown
Contributor

indurireddy-TF commented May 4, 2026

Hi @kdroste-google @baptmont Could you please review this PR, since all test cases are passing successfully?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale function responses can hard-fail content processing after retries or session restarts

3 participants