anomalyco / anomalyco/opencode
fix(vertex): @ai-sdk/google-vertex serializer emits empty model parts: [] on empty reasoning turns (missed by #30463)
@rekram1-node is already working on this.
Since Sep 8, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
When using Google Gemini models on Vertex AI (google-vertex), requests intermittently fail with HTTP 400:
Unable to submit request because it must include at least one parts field, which describes the prompt input. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini
Once this happens, every subsequent prompt in that session fails because the stored history contains the empty-parts turn.
Root cause
PR #30463 added patches/@ai-sdk%2Fgoogle@3.0.73.patch to omit empty model turns (if (contents[contents.length - 1].parts.length === 0) contents.pop()).
However, @ai-sdk/google-vertex@4.0.181 has its own dependency on @ai-sdk/google@3.0.108 in bun.lock. Because package.json's patchedDependencies only targeted @ai-sdk/google@3.0.73, the serializer copy in @ai-sdk/google@3.0.108 was never patched.
When a Gemini model (such as gemini-3.8-flash) emits an initial step-start followed by an empty reasoning chunk (text: "") before another step-start or tool call:
convertToModelMessagessplits onstep-start, producing an assistant message with only{ type: "reasoning", text: "" }.- When serialized for Vertex AI via
@ai-sdk/google@3.0.108,part.text.length === 0is filtered toundefined, yieldingparts: []. - Without the
contents.pop()guard,{ role: "model", parts: [] }is sent to Vertex AI, which rejects it with HTTP 400. - Additionally,
message-v2.tsdoes not filter zero-length reasoning parts intoModelMessagesEffectwhen replaying history.
OpenCode version
1.18.28 / dev
Steps to reproduce
- Configure
google-vertexprovider with a thinking Gemini model (e.g.gemini-3.8-flash). - Run a session where a turn starts with an empty reasoning chunk before tool execution (persisting a reasoning part with
text: ""). - Send any subsequent prompt.
- Vertex AI rejects the request with HTTP 400 (
Unable to submit request because it must include at least one parts field).
Operating System
macOS
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.