fix(firebaseai): keep LiveSession.receive() open after an unparseable message - #18752
Seungpyo1007 wants to merge 1 commit into
Conversation
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 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 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. |
Description
LiveSession.receive()is anasync*generator overawait for (final result in _messageController.stream). When the server sends a message thatparseServerResponsedoesn't know, for example thevoiceActivitymessage fromgemini-3.8-live,_listenToWebSocketadds aFirebaseAISdkExceptionto the controller.await forthen rethrows it inside the generator, so the listener getsonErrorand thenonDone, even though the WebSocket and the controller are still open and the model keeps answering.This switches the loop to
yield* _messageController.stream.yield*forwards the error as an error event and keeps listening, so one unparseable frame becomes a single error event instead of ending the stream. The doc comment onreceive()now says so.This doesn't add a type for
voiceActivityitself. I asked about that on the issue, since it would be new public API.Related Issues
Fixes #18749
Checklist
///).melos run analyze) does not report any problems on my PR. (ranflutter analyzeonfirebase_ai)Breaking Change
The new test in
live_session_test.dartsends a valid message, avoiceActivitymessage and another valid message, then checks that the listener gets data, an error and data, with noonDone. It fails onmainand passes with this change. The fullfirebase_aisuite passes (353 tests), andflutter analyzeis clean for the package.