google-vertex: Gemini 4 Carbon 400s on merged functionResponse+text user turns and historical unsigned tool calls
What happened?
Using google-vertex/gemini-4-carbon (senpi 2026.11.9-2, verified on main @ b8fe5e0) hits two 400 INVALID_ARGUMENT errors in packages/ai/src/api/google-shared.ts:
-
Requests ending with a model turn are not supported.whenfunctionResponseandtextshare the finaluserturn:appendContent()(google-shared.ts:214-220) folds any adjacentrole: "user"entry into the precedingfunctionResponseuser turn (parts: [{ functionResponse }, { text }]). Whenever a user prompt, reminder, or aborted-turn retry lands right aftertoolResultat the end ofcontents, Vertex AIgemini-4-carbonrejects the request with400 Requests ending with a model turn are not supported.. KeepingfunctionResponseparts and plaintextparts in separaterole: "user"entries (prevHasFn === currHasFn) returns200 OK. -
Function call is missing a thought_signatureon cross-model session resume:convertMessages()(google-shared.ts:309-310) gates unsigned tool-call text replay behindisCurrentTurn:requiresThoughtSignatureReplay(model.id) && isCurrentTurn && !hasValidFirstSignatureWhen resuming a session (-c) containing historical tool calls from non-Gemini models, Vertex AIgemini-4-carbonrejects unsignedfunctionCallparts in earlier turns as well, not only the current turn.
Steps to reproduce
- Run
GOOGLE_CLOUD_PROJECT=<proj> GOOGLE_CLOUD_LOCATION=global senpi -ne --provider google-vertex --model gemini-4-carbon. - Trigger a tool call whose
toolResultis followed by a user/custom text message before the next completed assistant turn (or resume-ca session containing prior Claude/OpenAI tool calls). - Observe Vertex
400 INVALID_ARGUMENT(Requests ending with a model turn are not supported./Function call is missing a thought_signature).
Expected behavior
appendContent()does not mergefunctionResponseuser turns with plaintextuser turns (prevHasFn === currHasFn).replayUnsignedToolCallsAsTextreplays unsigned historicaltoolCall+ pairedtoolResultentries as text across all turns whenrequiresThoughtSignatureReplay(model.id)is true.
Version
2026.11.9-2 (main @ b8fe5e0)
[AI-assisted disclosure per CONTRIBUTING.md] Drafted with Gemini 4 Carbon on macOS arm64 after reproducing against live Vertex AI gemini-4-carbon (senpi 2026.11.9-2) and verifying the local patch.
Thanks @yiminhale, this is a precise report with code locations, which makes it easy to act on. The first symptom (a user turn that folds functionResponse and text together gets a 400) looks like the same root cause as the open #3633, so I've linked them. The unsigned historical tool-call part reads as new. It's passed to the provider owners, and we'll follow up here.
Current main leaves unsigned historical functionCall parts in the Gemini 4 request: 8 new regression cases fail and 23 pass at dc5c9f1a7ae2b72a79fa5a47f4bc825c276aa23d. The reproduction resumes Claude Opus tool history into gemini-4-neon through google-generative-ai, google-vertex, and a vendor-prefixed model ID. Each cross-model case finds a structured call in the older turn, and the #3633 ordering case emits [functionResponse, text].
I'm carrying #4337's functionResponse-last ordering into this fix, extending the existing text replay to every unsigned historical step, and including #7414's prefix matching. The RED command was bun run --cwd packages/ai test test/google-shared-gemini3-unsigned-tool-call.test.ts test/google-shared-role-alternation.test.ts.
The same two regression files now pass all 32 cases. convertMessages replays an unsigned tool-call step and its paired result as text regardless of turn age, preserves a same-model step whose first call has a valid signature, recognizes vendor-prefixed model IDs, and keeps functionResponse parts last for Gemini 3+ while retaining Gemini 2's legacy ordering.
This supersedes #4337's partial-turn guard and includes the behavior proposed by #7414. Next are the wider Google suites and a live session with prior Opus tool history.
Milestone: proposed fix is up as #7825 (fix/gemini-historical-thought-signatures), head 5d1a6e5.
Root cause: the existing guard only text-replayed an unsigned first functionCall in the current turn. Gemini 3/4 applies the thought-signature rule to every replayed step, so a historical or cross-provider step still reached the API as an unsigned functionCall.
What the PR changes:
- Every unsigned tool-call step is replayed as text (call plus paired result) for Gemini 3+, including historical turns and sessions resumed after a provider switch.
- Vendor- and path-prefixed model ids are recognized (
google-gemini-4-neon,models/gemini-3-pro-preview), absorbing #7414. - For Gemini 3+ only,
functionResponseparts remain last when user text is merged with tool results, covering #3633's ordering 400. Gemini 2 keeps the legacy order.
Request-shape proof at base 5f05f4e: the focused RED run had 8 failed / 24 passed; the fixed head has 32/32 passing, and the Google provider sweep is 140 passed / 9 skipped. The build exits 0.
Live QA: an Opus tool-call turn followed by google/gemini-4-neon completed three consecutive bash calls with no 400. The live run used the Google API-key path; the reported Vertex gemini-4-carbon 400 could not be reproduced without a Vertex credential, so the unit-level serialized-request assertions carry the request-shape proof. The full local suite is still running; I'll report its result with the merge evidence.