fix(translator): backfill empty functionResponse.name to prevent Gemini API 400 errors#2103
fix(translator): backfill empty functionResponse.name to prevent Gemini API 400 errors#2103jveko wants to merge 1 commit intorouter-for-me:mainfrom
Conversation
…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.
Summary of ChangesHello, 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
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| if name == "" { | ||
| name = backfillName | ||
| } | ||
| if name == "" { | ||
| name = "unknown" | ||
| } |
There was a problem hiding this comment.
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.
| if name == "" { | |
| name = backfillName | |
| } | |
| if name == "" { | |
| name = "unknown" | |
| } | |
| if name == "" { | |
| if backfillName != "" { | |
| name = backfillName | |
| } else { | |
| name = "unknown" | |
| } | |
| } |
Fixes #2104
Problem
When proxying requests to Google's Gemini API via the antigravity translator,
functionResponseparts were sent with emptynamefields, causing 400 errors:This affected clients like Amp that send
functionResponseparts without populating thenamefield.Root Cause
Incoming requests include
functionResponseparts without anamefield (or with an empty name). The proxy forwarded them as-is to Gemini without resolving the name from the correspondingfunctionCallin the preceding model content.Fix
antigravity_gemini_request.gofixCLIToolResponsenow collectsfunctionCallnames positionally from model content parts intoFunctionCallGroup.CallNamesparseFunctionResponseRawaccepts abackfillNameparameter and guarantees a non-emptyfunctionResponse.nameacross all code paths (backfillName →"unknown"fallback)gemini_openai-responses_request.gocallID→namemap from normalizedfunction_callitems instead of scanning the raw input array (matching the proventcID2Namepattern from chat-completions)Testing
51 passed in 4 packages)