Skip to content

[AI] Handle GenerateContentResponse with only usageMetadata - #16171

Merged
andrewheard merged 6 commits into
mainfrom
ah/ai-response-decoding
May 19, 2026
Merged

[AI] Handle GenerateContentResponse with only usageMetadata#16171
andrewheard merged 6 commits into
mainfrom
ah/ai-response-decoding

Conversation

@andrewheard

Copy link
Copy Markdown
Contributor

Updated the Decodable implementation for GenerateContentResponse to handle cases where the only content is the usageMetadata. This sometimes occurs when streaming using Gemini 3.1 Flash Lite and may occur elsewhere.

#no-changelog

@gemini-code-assist

Copy link
Copy Markdown
Contributor
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 the 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 counterproductive. 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.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request addresses a decoding issue in the Firebase AI SDK where responses containing only usage metadata were causing failures. By updating the initialization logic and improving error diagnostics, the SDK now correctly handles these response types, allowing for the successful integration of newer Gemini models in streaming scenarios.

Highlights

  • Decoding Logic Update: Updated the Decodable implementation for GenerateContentResponse to accept responses containing only usageMetadata, preventing decoding errors during streaming.
  • Improved Error Reporting: Enhanced the decoding failure message to include the raw JSON response, aiding in debugging future serialization issues.
  • Integration Test Update: Switched the integration test model to gemini3_1_FlashLite, resolving the previously noted decoding failure.
New Features

🧠 You can now enable Memory (public preview) 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.

Activity
  • The pull request was created by andrewheard.
  • The gemini-code-assist bot provided documentation on how to use its features.
  • The author requested a summary of the pull request using the /gemini summary command.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates GenerateContentResponse to support decoding responses that only contain usageMetadata and improves error reporting by including the response content in the error description. Additionally, integration tests have been updated to use the gemini3_1_FlashLite model. Feedback suggests adding a unit test to verify the new decoding logic and refining the error message formatting to better handle optional values and provide more accurate codingPath information.

Comment thread FirebaseAI/Sources/GenerateContentResponse.swift
Comment thread FirebaseAI/Sources/GenerateContentResponse.swift Outdated
@andrewheard
andrewheard marked this pull request as ready for review May 19, 2026 04:12

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the GenerateContentResponse decoding logic to include usageMetadata as a valid top-level key and improves error reporting by including the response content in the DecodingError description. It also updates integration tests to use the gemini3_1_FlashLite model and adds corresponding unit tests. Feedback highlights that the string interpolation of JSONValue in the error message might be difficult to read and that attempting to decode a JSONValue after accessing a keyed container may fail depending on the Decoder implementation.

Comment thread FirebaseAI/Sources/GenerateContentResponse.swift Outdated

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the GenerateContentResponse decoding logic to include usageMetadata as a valid key and enhances error reporting by listing the keys found when decoding fails. Additionally, it updates integration tests to use the gemini3_1_FlashLite model and introduces unit tests for the new decoding scenarios. A review comment suggests sorting the keys in the error message to ensure deterministic output for better debugging.

Comment thread FirebaseAI/Sources/GenerateContentResponse.swift Outdated
@andrewheard
andrewheard merged commit 3dbf64a into main May 19, 2026
84 checks passed
@andrewheard
andrewheard deleted the ah/ai-response-decoding branch May 19, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants