Repository navigation
fix(google): never emit empty or malformed content parts (#420) - #430
snowyukitty wants to merge 2 commits into
Conversation
Antigravity translates Gemini contents into Anthropic messages for Claude
models, and Anthropic rejects text blocks whose text is empty or absent.
messagesToGeminiFormat could emit an empty text part, a bare {} part from a
missing/non-string text, or a parts: [] model turn, each of which 400s with
messages.N.content.M.text.text: Field required.
Guarantee every turn has at least one part and every text part a non-empty
string, mirroring the Anthropic adapter's existing empty-block guard.
📝 WalkthroughWalkthroughThe Google adapter now filters empty or malformed Gemini content, inserts placeholders for empty user and tool results, omits assistant turns without representable parts, and adds comprehensive serialization tests. ChangesGoogle content serialization
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/adapters/google.ts`:
- Line 181: Update the functionResponse construction in src/adapters/google.ts
at lines 181-181 to call contentPartsToText only when msg.content contains
non-empty text or image content; otherwise use
GEMINI_EMPTY_TOOL_OUTPUT_PLACEHOLDER. Add coverage in
tests/google-empty-content.test.ts at lines 107-117 for an empty content array
and arrays containing only empty text parts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 9de3e692-3e47-496e-92a6-619424f0a58b
📒 Files selected for processing (2)
src/adapters/google.tstests/google-empty-content.test.ts
contentPartsToText collapses an empty array, or one holding only empty text, to its "[image]" marker, so the previous guard never reached the placeholder for array content and claimed an image the turn does not carry (toolResultImageParts adds none). Gate the conversion on representable text or image content. Addresses CodeRabbit review feedback on lidge-jun#430.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/adapters/google.ts`:
- Around line 113-116: Update geminiToolResultText to count an image only when
toolResultImageParts can emit it, excluding malformed or remote image URLs from
hasContent and allowing GEMINI_EMPTY_TOOL_OUTPUT_PLACEHOLDER when no text or
supported images remain. Add a regression test covering an invalid or remote
image URL and verify the result uses the placeholder without an emitted image
part.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: d315fd31-7b4c-4f38-9751-32c5a9f7d072
📒 Files selected for processing (2)
src/adapters/google.tstests/google-empty-content.test.ts
🔒 Maintainer integration in progress — please hold off on merging@lidge-jun (maintainer) is actively integrating this PR into What is happening This PR is being integrated on the maintainer branch What this means for you
This PR will be closed with a merge receipt (integration commit SHA, verification output, Integration tracker: |
PR #430 (head 8704ab7, author snowyukitty)을 통합하고 회귀 테스트 2건을 추가한다. Antigravity가 Gemini contents를 Anthropic messages로 변환할 때 빈 text 블록은 messages.N.content.M.text.text: Field required 400을 유발한다. user/developer의 빈 문자열과 빈 파트 배열은 placeholder로, assistant의 빈 text 파트는 drop하고 방출할 파트가 없는 turn은 생략하며, 빈 tool result는 전용 placeholder를 쓴다. 추가한 회귀 2건: - 빈 developer message가 user role로 변환되며 동일 placeholder를 방출 - assistant text 배열이 전부 빈 경우 turn 자체가 생략됨 Co-authored-by: snowyukitty <[email protected]>
✅ Integrated into
|
|
Closing: integrated into |
PR lidge-jun#430 (head 8704ab7, author snowyukitty)을 통합하고 회귀 테스트 2건을 추가한다. Antigravity가 Gemini contents를 Anthropic messages로 변환할 때 빈 text 블록은 messages.N.content.M.text.text: Field required 400을 유발한다. user/developer의 빈 문자열과 빈 파트 배열은 placeholder로, assistant의 빈 text 파트는 drop하고 방출할 파트가 없는 turn은 생략하며, 빈 tool result는 전용 placeholder를 쓴다. 추가한 회귀 2건: - 빈 developer message가 user role로 변환되며 동일 placeholder를 방출 - assistant text 배열이 전부 빈 경우 turn 자체가 생략됨 Co-authored-by: snowyukitty <[email protected]>
Closes #420.
Problem
google-antigravityis registered withadapter: "google"(src/providers/registry.ts), soopencodex sends Gemini
contentsand Antigravity translates them into AnthropicmessagesforClaude models. The
req_vrtx_...id in the report is a Vertex Anthropic request, so the 400 israised after that translation — the issue attributes the block to
messagesToAnthropicFormat, butthe producer is the Google serializer.
messagesToGeminiFormat(src/adapters/google.ts) had no empty-content guard, so four shapes couldreach the wire:
content: ""{ text: "" }{"type":"text"}→content.N.text.text: Field requiredtext: ""{ text: "" }text{}(bare part){ role: "model", parts: [] }contentarray → 400The bare
{}is reachable from ordinary input:src/responses/parser.tsbuilds{ type: "text", text: (block as { text: string }).text }without validating the cast, so aResponses
input_textblock with notextkey becomes{ text: undefined }, whichJSON.stringifydrops entirely.That Anthropic rejects empty text blocks is already established in this repo by
7ff4c7c("guard against empty text content blocks (400 rejection)"). Gemini accepts all four shapes,
which is why this only surfaces on Claude-on-Antigravity, and why the reproduction needs a long
tool-heavy session — more turns, more chances for one empty part.
Fix
All in
messagesToGeminiFormat(src/adapters/google.ts). Every emitted turn now has at least onepart, and every text part a non-empty string
text:"(empty)"placeholder.geminiTextPart()helper; a user turnleft with nothing falls back to the
"(empty)"placeholder.parts: [], matching what the Anthropic adapter already does for its own empty assistant content(
src/adapters/anthropic.ts)."(empty tool output)"placeholder.Placeholder strings are reused from the Anthropic adapter so the two adapters stay symmetric. Image
parts,
functionCall/functionResponseparts, thought signatures, and tool-call id pairing areuntouched.
The guard applies to every Google provider, not only Antigravity: an empty part carries no
information for Gemini either, and one code path keeps the same bug from reappearing on Vertex.
Tests
tests/google-empty-content.test.ts(new, 12 cases): one per malformed shape above, anassertNoEmptyTextPartsinvariant applied across the wholecontentsarray, the emptytool-result-array cases from review, and unchanged-passthrough controls. All 10 guard cases fail
without the source change; the controls pass either way.
vertex-stream, tool-schema, plus the new file: 118 passed across 8 files.
bun run typecheckandbun run privacy:scanpass.pre-existing on this Windows machine and reproduce on a clean
devcheckout:ci-workflows(2) —Bun.spawnSync(["bun", …])resolvesbunfromPATH, which this machinedoes not have; the file passes 10/10 once
bunis onPATH.codex-catalogrouted-normalization (1) — cross-file state pollution; the identical 12-filegroup produces the identical failures on clean
dev(222 pass / 3 fail both sides).openai-provider-option-e2espine (1) — same cross-file effect; the identical file set gives137 pass / 1 fail on clean
devtoo, and the file passes 1/1 alone.No test makes a live provider request.
A note on how the full suite was run: a single
bun testprocess hangs on this machine partwaythrough the anthropic e2e files, and that hang reproduces on a clean
devcheckout with nochanges applied, so it is environmental rather than something this PR introduces. To get real
coverage anyway I ran the suite in 27 batches; the one batch that hit the hang was then re-run
file-by-file (120 passed, 0 failed). The batched run was performed at the pre-rebase commit; the
rebase since then only pulled in the CI/issue-bot commits (
#423), which touch nosrc/path inthis diff's neighbourhood, and the Google suites, typecheck, and privacy scan were re-run after the
rebase. CI remains the authority here.
Notes
src/responses/parser.tsinstead. The serializer is the rightplace: it is the last point that knows what the wire accepts, it has to hold for content arriving
from the Claude ingress, sidecars, and replayed history too, and it keeps the Google and Anthropic
adapters symmetric. Happy to send parser-side hardening separately if you want it.
userturns. The previousparts: []shape was itself rejected upstream, so this is not a regression, and the Anthropic adapter already
skips empty assistant content the same way — flagging it as the one behavioral change beyond
dropping empties.
Review follow-up (CodeRabbit, #430)
contentPartsToTextcollapses an empty array — or one holding only empty text — to its"[image]"marker, so the first commit's
|| placeholderwas unreachable for array content and the tool resultclaimed an image the turn does not carry (
toolResultImagePartscontributes none). Fixed in8704ab7bwith ageminiToolResultText()helper gated on representable text or image content, plusthree cases: empty array, all-empty-text array, and an image-only control that must still report
[image]. The two guard cases fail against the pre-fix source; the control passes either way.Summary by CodeRabbit