Files
firebase-ios-sdk/GeminiLanguageModel/Sources
Andrew Heard c2186eaa52 fix(ai): attach signature-only reasoning to a part with data (#16886)
Gemini 3.x models return the thought signature of a text response on a
trailing empty text part. The executor records this as a signature-only
`.reasoning` transcript entry, which `GeminiTranscriptTranslator` then
round-tripped on the next turn as a stand-alone `Part` containing only
`thought` and `thoughtSignature` and no `data`.

The Gemini Developer API tolerates a part with no data, but the Gemini
Enterprise Agent Platform rejects it nondeterministically with
`400 INVALID_ARGUMENT` ("Request contains an invalid argument."),
making any multi-turn session that follows a completed text response
flaky on that backend (e.g. `sessionRespondSequentialToolCalls`).

Never emit a signature-only reasoning entry as a data-less part:

- A signature preceding a response is attached to the response's text
  part.
- A signature following a response is attached to the last part of the
  current model turn, mirroring how the server originally sent it.
- If there is no model part to attach to, fall back to a thought part
  with empty text so the `data` oneof is always populated.

Replace the unit test that asserted the data-less shape with coverage
for all three cases.
2026-10-09 21:51:04 -07:00
..