-
Notifications
You must be signed in to change notification settings - Fork 666
[AI] Fix crash caused by unhandled goAway server message in LiveSession #7649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[AI] Fix crash caused by unhandled goAway server message in LiveSession #7649
Conversation
Servers send goAway messages to gracefully disconnect sessions. The timeLeft field uses protobuf Duration string format.
Add exception handling and goAwayHandler support: - Add CoroutineExceptionHandler to prevent crashes - Handle LiveServerGoAway in processModelResponses - Add goAwayHandler to LiveAudioConversationConfig
Add unit tests for LiveServerGoAway message handling: - Duration parsing tests (protobuf format) - Deserialization tests - Serialization schema test
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. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
emilypgoogle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thanks for the PR, I've left some comments about changes we'd like to see and open questions for the contents and implementation choices made. Overall, once these are addressed, this general implementation seems well done to merge.
| * convert this to a [kotlin.time.Duration]. | ||
| */ | ||
| @PublicPreviewAPI | ||
| public class LiveServerGoAway(public val timeLeft: String?) : LiveServerMessage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SDK should convert this string into a public facing duration object and not expose the String.
| * | ||
| * @return The parsed duration, or null if [timeLeft] is null or cannot be parsed. | ||
| */ | ||
| public fun parseTimeLeft(): kotlin.time.Duration? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re the previous comment, this method should be removed and called implicitly on toPublic
|
|
||
| // Remove 's' suffix and parse as double | ||
| val secondsStr = trimmed.dropLast(1) | ||
| val seconds = secondsStr.toDoubleOrNull() ?: return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be rewritten as
secondsStr.toDoubleOrNull()?.seconds removing the lines below
| val seconds = secondsStr.toDoubleOrNull() ?: return null | ||
|
|
||
| seconds.seconds | ||
| } catch (e: Exception) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What could be throwing an exception here? Is there a more scoped type possible, or is this vestigial?
| * | ||
| * Logs the exception and attempts to clean up resources to prevent app crashes. | ||
| */ | ||
| private val exceptionHandler = CoroutineExceptionHandler { _, throwable -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary for this PR? Ideally PRs should be well scoped.
| ) | ||
| } catch (e: SerializationException) { | ||
| Log.w(TAG, "Failed to deserialize server message: ${e.message}") | ||
| null // Skip unknown messages instead of crashing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a notable behavior change, is avoiding crashes and skipping server messages actually the ideal behavior?
Description
Fixes #7648
This PR adds support for the
goAwayserver message type in LiveSession to prevent crashes when the server initiates a disconnect. Previously, when the server sent agoAwaymessage, the app would crash with aSerializationExceptionbecause the message type was not recognized byLiveServerMessageSerializer.Changes
1. Add LiveServerGoAway message type
LiveServerGoAwayclass to represent server-initiated disconnectiontimeLeft: String?field containing duration in protobuf format (e.g., "57s", "1.5s")parseTimeLeft()helper method to convert timeLeft string tokotlin.time.DurationgoAwaymessage inLiveServerMessageSerializer2. Robust Handling & API Update
CoroutineExceptionHandlertonetworkScopeandaudioScopeto act as a safety net against unhandled exceptions.processModelResponses()to recognizeGoAwaysignals and automatically close the session, preventing zombie connections or further crashes.goAwayHandlertoLiveAudioConversationConfig.timeLeftinformation to the application layer.3. Comprehensive unit tests
LiveServerMessageTests.ktwith 18 test cases covering:SerializationTests.ktUsage Example
Apps can now handle server disconnections gracefully using the
goAwayHandler:Testing
Related Issues
SerializationExceptionon "goAway" message in LiveSession #7648