[AI] Fix crash caused by unhandled goAway server message in LiveSession #7649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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