Repository navigation
fix(core): ensure all model turns with function calls receive thought signatures - #29828
Conversation
|
📊 PR Size: size/M
|
There was a problem hiding this comment.
Code Review
This pull request updates ensureActiveLoopHasThoughtSignatures in GeminiChat to apply thoughtSignature (using SYNTHETIC_THOUGHT_SIGNATURE) to the first function call of every model turn across the entire conversation history, rather than limiting it to the active loop. This prevents 400 Bad Request errors from the Gemini API, which validates all historical function calls. Corresponding unit tests and reproduction test cases have been updated and added to verify this behavior. I have no further feedback to provide as the changes are clean and well-tested.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates ensureActiveLoopHasThoughtSignatures in geminiChat.ts to ensure that the first function call in every model turn across the entire conversation history has a thoughtSignature property, resolving potential 400 Bad Request errors from the Gemini API. It also adds comprehensive unit and reproduction tests to verify this behavior. The review feedback recommends defining a local interface for the undocumented thoughtSignature property and adding a detailed comment explaining the rationale for using this internal SDK property to maintain type safety and document the workaround.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the ensureActiveLoopHasThoughtSignatures method in GeminiChat to apply a synthetic thoughtSignature to the first function call of all model turns across the entire conversation history, rather than restricting it to the active loop, preventing 400 Bad Request errors from the Gemini API. Corresponding unit and reproduction tests have been updated and added. The review feedback correctly identifies a performance optimization opportunity to avoid redundant array and object allocations by lazily copying the history and parts arrays only when modifications are actually required.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates ensureActiveLoopHasThoughtSignatures in geminiChat.ts to ensure that the first function call in every model turn across the entire conversation history has a thoughtSignature property, preventing 400 Bad Request errors from the Gemini API. It also optimizes the method to lazily clone arrays only when modifications are needed, and adds comprehensive unit tests to verify this behavior. The feedback suggests defensively checking if part is defined before accessing its properties to prevent potential runtime TypeError crashes.
…reActiveLoopHasThoughtSignatures
There was a problem hiding this comment.
Code Review
This pull request updates the ensureActiveLoopHasThoughtSignatures method in GeminiChat to apply synthetic thought signatures to the first function call of every model turn across the entire conversation history, rather than limiting it to the active loop. This change prevents HTTP 400 Bad Request errors from the Gemini API, which validates all historical function calls. Additionally, the implementation has been optimized to lazily clone the history array only when modifications are necessary, returning the original reference otherwise. Comprehensive unit tests and reproduction cases have been added to verify this behavior. There are no review comments to address, and the changes look solid.
Head branch was pushed to by a user without write access
c690b9d

Summary
Fixes an issue where multi-turn agent conversations fail with HTTP 400 Bad Request (
Function call is missing a thought_signature in functionCall parts) when historical model tool calls precede subsequent user prompts.Details
Root Cause
In
GeminiChat.ensureActiveLoopHasThoughtSignatures, thought signature enforcement was only applied to turns beginning atactiveLoopStartIndex(the most recent user text prompt). Any historical model turn containing a function call prior toactiveLoopStartIndex(such as a tool invoked earlier in a coding session, e.g. at position 58) was forwarded to the Gemini API without athoughtSignature.The Gemini API requires that every model turn containing function calls in the
contentshistory payload must have athought_signatureon its firstfunctionCallpart. Consequently, once a session progressed past the initial tool turn, the Gemini API rejected the subsequent request with HTTP 400INVALID_ARGUMENT.Fix
ensureActiveLoopHasThoughtSignaturesinpackages/core/src/core/geminiChat.tsto iterate across all model turns inrequestContentsrather than restricting toactiveLoopStartIndex.functionCallpart of every model turn in history has athoughtSignature(SYNTHETIC_THOUGHT_SIGNATUREif not already present).packages/core/src/core/geminiChat.test.ts.How to Validate
Run the targeted unit and regression tests in
@google/gemini-cli-core:npm test -w @google/gemini-cli-core -- src/core/geminiChat.test.tsExpected result: All 134 tests pass.
Run
a2a-servertest suite:npm test -w @google/gemini-cli-a2a-serverExpected result: All 16 test files pass (177 tests).
Run workspace typecheck and linter:
Expected result: 0 errors, 0 warnings.
Manual verification across 8 cases:
Pre-Merge Checklist