Skip to content

fix(provider): patch empty Gemini replay messages for Vertex AI - #47864

Open
ghchinoy wants to merge 1 commit into
anomalyco:devfrom
ghchinoy:fix/vertex-empty-reasoning-parts
Open

fix(provider): patch empty Gemini replay messages for Vertex AI#47864
ghchinoy wants to merge 1 commit into
anomalyco:devfrom
ghchinoy:fix/vertex-empty-reasoning-parts

Conversation

@ghchinoy

@ghchinoy ghchinoy commented Sep 8, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #47863

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

PR #30463 patched @ai-sdk/google@3.0.73 to pop empty model turns (if (contents[contents.length - 1].parts.length === 0) contents.pop()). However, @ai-sdk/google-vertex depends on @ai-sdk/google@3.0.108 in bun.lock, which was not covered by the 3.0.73 patch rule. As a result, Gemini on Vertex AI (google-vertex) still emitted { role: "model", parts: [] } when an assistant turn contained only empty reasoning parts (text: ""), resulting in HTTP 400 (Unable to submit request because it must include at least one parts field).

This PR:

  1. Adds patches/@ai-sdk%2Fgoogle@3.0.108.patch to apply the same contents.pop() guard to @ai-sdk/google@3.0.108 used by @ai-sdk/google-vertex.
  2. Adds a guard in MessageV2.toModelMessagesEffect (packages/opencode/src/session/message-v2.ts) to skip zero-length reasoning parts when replaying history.
  3. Adds a unit test in packages/opencode/test/session/llm.test.ts covering google-vertex payload construction with empty reasoning parts.

How did you verify your code works?

  • Ran bun test test/session/llm.test.ts -t "sends Google": both google and google-vertex tests pass.
  • Verified typecheck with bun turbo typecheck (all 30 package tasks passed).

Screenshots / recordings

N/A (backend/protocol fix)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant