Skip to content

fix(translator): backfill empty functionResponse.name to prevent Gemini API 400 errors#2103

Open
jveko wants to merge 1 commit intorouter-for-me:mainfrom
jveko:fix/empty-function-response-name
Open

fix(translator): backfill empty functionResponse.name to prevent Gemini API 400 errors#2103
jveko wants to merge 1 commit intorouter-for-me:mainfrom
jveko:fix/empty-function-response-name

Conversation

@jveko
Copy link

@jveko jveko commented Mar 12, 2026

Fixes #2104

Problem

When proxying requests to Google's Gemini API via the antigravity translator, functionResponse parts were sent with empty name fields, causing 400 errors:

GenerateContentRequest.contents[].parts[].function_response.name: Name cannot be empty.

This affected clients like Amp that send functionResponse parts without populating the name field.

Root Cause

Incoming requests include functionResponse parts without a name field (or with an empty name). The proxy forwarded them as-is to Gemini without resolving the name from the corresponding functionCall in the preceding model content.

Fix

antigravity_gemini_request.go

  • fixCLIToolResponse now collects functionCall names positionally from model content parts into FunctionCallGroup.CallNames
  • parseFunctionResponseRaw accepts a backfillName parameter and guarantees a non-empty functionResponse.name across all code paths (backfillName → "unknown" fallback)

gemini_openai-responses_request.go

  • Pre-builds a callID→name map from normalized function_call items instead of scanning the raw input array (matching the proven tcID2Name pattern from chat-completions)

Testing

  • All existing tests pass (51 passed in 4 packages)
  • Verified end-to-end with Amp's finder subagent through the proxy — previously failing requests now succeed

…ni API 400 errors

When proxying requests to Google's Gemini API via the antigravity translator,
functionResponse parts were sent with empty name fields, causing 400 errors:
'GenerateContentRequest.contents[].parts[].function_response.name: Name cannot be empty.'

Root cause: incoming requests from clients (e.g. Amp) include functionResponse
parts without a name field. The proxy forwarded them as-is without resolving
the name from the corresponding functionCall.

Changes:
- antigravity_gemini_request.go: Collect functionCall names positionally from
  model content in fixCLIToolResponse and pass them to parseFunctionResponseRaw
  for backfilling. All code paths now guarantee a non-empty name (backfillName
  -> 'unknown' fallback).
- gemini_openai-responses_request.go: Pre-build a callID->name map from
  normalized function_call items instead of scanning the raw input array,
  matching the proven tcID2Name pattern from chat-completions.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue where requests proxied to the Google Gemini API were failing with 400 errors because functionResponse parts lacked a required name field. The changes ensure that these name fields are consistently populated, either by deriving them from corresponding functionCall parts or by assigning a default value. This enhancement significantly improves the robustness and compatibility of the translator with clients that send functionResponse parts without pre-populating the name field.

Highlights

  • Problem Resolution: Fixed Gemini API 400 errors caused by empty functionResponse.name fields when proxying requests.
  • Function Name Backfilling: Implemented logic in antigravity_gemini_request.go to backfill empty functionResponse.name fields using names from preceding functionCall parts, defaulting to "unknown" if no name is found.
  • Optimized Name Resolution: Refactored gemini_openai-responses_request.go to pre-build a callID -> name map, improving efficiency in resolving function call names for function_call_output items.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • internal/translator/antigravity/gemini/antigravity_gemini_request.go
    • Added CallNames slice to FunctionCallGroup to store ordered function call names.
    • Modified parseFunctionResponseRaw to accept a backfillName parameter and ensure the functionResponse.name field is always populated, using "unknown" as a fallback.
    • Updated fixCLIToolResponse to collect function call names from model content and pass them to parseFunctionResponseRaw for backfilling.
  • internal/translator/gemini/openai/responses/gemini_openai-responses_request.go
    • Introduced a callID2Name map to store function call names indexed by their call_id for quick lookup.
    • Refactored the logic for resolving function_call_output names to use this pre-built map, replacing the previous iterative search through the input array.
Activity
  • All existing tests passed (51 tests in 4 packages).
  • End-to-end verification confirmed that previously failing requests from Amp's finder subagent now succeed through the proxy.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request refactors function call name handling in the translation logic. Specifically, antigravity_gemini_request.go now stores ordered function call names within FunctionCallGroup and uses them to backfill missing function response names in parseFunctionResponseRaw. Concurrently, gemini_openai-responses_request.go optimizes function call name resolution for function_call_output by pre-building a call_id to name map, replacing an inefficient iterative search. A review comment suggests refactoring a series of if statements in parseFunctionResponseRaw into a nested if-else block for improved clarity and minor efficiency in its fallback name assignment.

Comment on lines +165 to +170
if name == "" {
name = backfillName
}
if name == "" {
name = "unknown"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This series of if statements to determine the fallback name can be structured more clearly as a nested if-else block. This would make the fallback logic more explicit and slightly more efficient by avoiding a second check on name.

Suggested change
if name == "" {
name = backfillName
}
if name == "" {
name = "unknown"
}
if name == "" {
if backfillName != "" {
name = backfillName
} else {
name = "unknown"
}
}

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.

Gemini API 400: functionResponse.name cannot be empty when proxying via antigravity

1 participant