Skip to content

feat(firebaseai): live session resumption#18038

Open
cynthiajoan wants to merge 27 commits intomainfrom
firebaseai/live_session_resumption
Open

feat(firebaseai): live session resumption#18038
cynthiajoan wants to merge 27 commits intomainfrom
firebaseai/live_session_resumption

Conversation

@cynthiajoan
Copy link
Copy Markdown
Collaborator

Description

Replace this paragraph with a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change.

Related Issues

Replace this paragraph with a list of issues related to this PR from the issue database. Indicate, which of these issues are resolved or fixed by this PR. Note that you'll have to prefix the issue numbers with flutter/flutter#.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@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

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.

@cynthiajoan
Copy link
Copy Markdown
Collaborator Author

/gemini review

@cynthiajoan cynthiajoan marked this pull request as ready for review April 21, 2026 16:55
Copy link
Copy Markdown
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

This pull request refactors the Gemini Live implementation to support session resumption and context window compression. It introduces a BidiMediaManager and BidiSessionController to better separate hardware management, business logic, and UI concerns. Key feedback includes addressing a potential runtime error on Flutter Web when decoding WebSocket messages, restoring echo cancellation to prevent audio feedback loops, and correcting several JSON keys to use snake_case to align with the Gemini Live API. Additionally, a typo in a tool response key was identified that could prevent correct model interaction.

I am having trouble creating individual review comments. Click here to see my feedback.

packages/firebase_ai/firebase_ai/lib/src/live_session.dart (144)

critical

Calling utf8.decode(message) directly will cause a runtime error on Flutter Web because the message emitted by the WebSocketChannel is already a String on that platform. You should check the type of the message before decoding.

          final String jsonString = message is String ? message : utf8.decode(message as List<int>);

packages/firebase_ai/firebase_ai/example/lib/utils/audio_input.dart (113-114)

high

The removal of echoCancel and noiseSuppress from the RecordConfig is concerning for a bidirectional (Bidi) session. Without echo cancellation, the model's audio output played through the speakers will likely be picked up by the microphone and sent back to the model, creating a feedback loop or causing the model to 'hear' itself.

packages/firebase_ai/firebase_ai/lib/src/live_api.dart (558-561)

high

The keys used to parse the SessionResumptionUpdate message are in camelCase, but the Gemini Live API typically returns snake_case keys (e.g., new_handle, last_consumed_client_message_index). This will likely result in null values being parsed even when the data is present.

      newHandle: sessionResumptionUpdateJson['new_handle'] as String?,
      resumable: sessionResumptionUpdateJson['resumable'] as bool?,
      lastConsumedClientMessageIndex:
          sessionResumptionUpdateJson['last_consumed_client_message_index'] as int?,

packages/firebase_ai/firebase_ai/example/lib/pages/bidi_page.dart (511-512)

medium

The key 'colorTemprature' contains a typo. While the comment mentions preserving the original typo, the tool definition at line 545 uses the correct spelling 'colorTemperature'. To ensure the model correctly interprets the tool response, the key must match the definition exactly.

          'colorTemperature': color,

packages/firebase_ai/firebase_ai/lib/src/live_api.dart (94)

medium

The JSON key should use snake_case to align with the Gemini Live API naming conventions.

      {if (targetTokens case final targetTokens?) 'target_tokens': targetTokens};

packages/firebase_ai/firebase_ai/lib/src/live_api.dart (117-120)

medium

The JSON keys should use snake_case to align with the Gemini Live API naming conventions.

        if (triggerTokens case final triggerTokens?)
          'trigger_tokens': triggerTokens,
        if (slidingWindow case final slidingWindow?)
          'sliding_window': slidingWindow.toJson()

packages/firebase_ai/firebase_ai/lib/src/live_session.dart (126)

medium

The JSON key 'contextWindowCompression' should be 'context_window_compression' to maintain consistency with other snake_case keys in the setup message.

            'context_window_compression': contextWindowCompression.toJson()

Comment thread packages/firebase_ai/firebase_ai/example/lib/pages/bidi_page.dart
Comment thread packages/firebase_ai/firebase_ai/lib/src/live_model.dart
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.

2 participants