fix(google-genai): preserve Gemini tool-call thought signature and trailing user text order - #2914
fix(google-genai): preserve Gemini tool-call thought signature and trailing user text order#2914SeleneXX wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 42604a9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b998a4dd5b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
b998a4d to
ee17407
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee17407925
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
ee17407 to
0182df5
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0182df5567
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
0182df5 to
6b860e9
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b860e95e9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
6b860e9 to
2d4cd78
Compare
2d4cd78 to
42604a9
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Related Issue
Resolve #2913
Problem
Gemini (
google-genai, e.g.gemini-3.7-flashthinking model) tool-calling sessions fail on the follow-up request with one of two upstream 400 errors:Function call is missing a thought_signature in functionCall parts. ...— the v2 engine'stool.callloop event dropsToolCall.extras(thought_signature_b64), so the fold-rebuilt assistant message cannot echothoughtSignatureon the outbound functionCall part.Requests ending with a model turn are not supported.—mergeConsecutiveUserMessagesmerges a trailing plain user message into the preceding tool-result Content as[functionResponse, text]; Gemini 3.x rejects a request whose last Content starts withfunctionResponsefollowed by text.Error #1 masks #2; after fixing #1, long tool-calling sessions then hit #2.
What changed
packages/agent-core-v2/src/agent/loop/loopService.ts: passextras(looked up fromresponse.message.toolCalls) into thetool.callloop event, matching what the v1 engine already does. The event type and the fold already supported the field.packages/kosong/src/providers/google-genai.tsandpackages/agent-core-v2/.../google-genai.ts: when merging a tool-result Content with a following text-only user Content, keep the text part first ([text, functionResponse]), which the upstream accepts.Validation
packages/agent-core-v2/test/agent/loop/loop.test.ts(extras survive tool.call → fold → context); reverting the fix makes it fail withexpected undefined to deeply equal {thought_signature_b64}.packages/kosong/test/google-genai.test.ts.[text, functionResponse, text], accepted by the upstream (200); the pre-fix[functionResponse, text]reproduced the exact 400.kosong85 tests + agent-core-v2 loop 49 tests pass; both packages typecheck.Checklist
gen-changesetsskill, or this PR needs no changeset. (changeset included:.changeset/fix-gemini-thought-signature.md)gen-docsskill, or this PR needs no doc update. (no user-facing doc change)