Skip to content

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

Closed

Description

@ghchinoy

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%[email protected] to omit empty model turns (if (contents[contents.length - 1].parts.length === 0) contents.pop()).

However, @ai-sdk/[email protected] has its own dependency on @ai-sdk/[email protected] in bun.lock. Because package.json's patchedDependencies only targeted @ai-sdk/[email protected], the serializer copy in @ai-sdk/[email protected] 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/[email protected], 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions