anomalyco / anomalyco/opencode

fix(vertex): @ai-sdk/google-vertex serializer emits empty model parts: [] on empty reasoning turns (missed by #30463)

Open
#47,863 0 comments 0 reactions 1 assignee View on GitHub

@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:

  1. convertToModelMessages splits on step-start, producing an assistant message with only { type: "reasoning", text: "" }.
  2. When serialized for Vertex AI via @ai-sdk/google@3.0.108, part.text.length === 0 is filtered to undefined, yielding parts: [].
  3. Without the contents.pop() guard, { role: "model", parts: [] } is sent to Vertex AI, which rejects it with HTTP 400.
  4. Additionally, message-v2.ts does not filter zero-length reasoning parts in toModelMessagesEffect when replaying history.
OpenCode version

1.18.28 / dev

Steps to reproduce
  1. Configure google-vertex provider with a thinking Gemini model (e.g. gemini-3.8-flash).
  2. Run a session where a turn starts with an empty reasoning chunk before tool execution (persisting a reasoning part with text: "").
  3. Send any subsequent prompt.
  4. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.