Skip to content

SerializationException on "goAway" message in LiveSession #7648

@Kick-snare

Description

@Kick-snare

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general
question, need help debugging, or fall into some other category use one of these other channels:

  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the
    firebase-talk google group.
  • For help troubleshooting your application that does not fall under one of the above categories,
    reach out to the personalized Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: Otter
  • Firebase Component: Gemini Live / LiveSession
  • Component version: BOM 34.7.0 (firebase ai logics 17.7.0)
  • Device: Pixel 9
  • OS: Android 16 Beta QPR2
  • Compile/Target SDK: 36

[REQUIRED] Step 3: Describe the problem

Description:

I am experiencing a fatal crash when using LiveSession in the Firebase AI SDK. It appears that when the server decides to close the connection (likely due to timeout or session expiry), it sends a JSON message containing the key "goAway".

The LiveServerMessageSerializer does not recognize this key, resulting in a SerializationException. Since this exception occurs on the internal networkScope (inside processModelResponses), it cannot be caught by the caller's try-catch block around startAudioConversation, causing the entire application to crash (Force Close) unless a global UncaughtExceptionHandler is implemented.

(use vertexAI backend)

Stack Trace:

FATAL EXCEPTION: Firebase Blocking Thread #1
Process: com.android.ai.catalog, PID: 17127
com.google.firebase.ai.type.SerializationException: Unknown LiveServerMessage response type. Keys found: [goAway]
	at com.google.firebase.ai.type.LiveServerMessageSerializer.selectDeserializer(LiveServerMessage.kt:206)
	at kotlinx.serialization.json.JsonContentPolymorphicSerializer.deserialize(JsonContentPolymorphicSerializer.kt:93)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69)
	at kotlinx.serialization.json.Json.decodeFromString(Json.kt:165)
	at com.google.firebase.ai.type.LiveSession$receive$1$1.invokeSuspend(LiveSession.kt:687)
	at com.google.firebase.ai.type.LiveSession$receive$1$1.invoke(Unknown Source:8)
    ...
	at kotlinx.coroutines.flow.FlowKt__CollectKt$launchIn$1.invokeSuspend(Collect.kt:46)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1154)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:652)
	at java.lang.Thread.run(Thread.java:1563)

Steps to reproduce:

  1. Initialize GenerativeModel with liveModel backend.
  2. Connect to the session and start the conversation (session.startAudioConversation()).
  3. Keep the session open until the server initiates a disconnect (or simulate a server-side "goAway" message).
  4. The app crashes with the SerializationException on a background thread.

Relevant Code:

viewModelScope.launch {
    // Even with try-catch here, the crash cannot be caught because it happens on the SDK's internal networkScope
    try {
        val session = generativeModel.connect()
        session.startAudioConversation(functionCallHandler = ::handleFunctionCall) 
    } catch (e: Exception) {
        Log.e("Gemini", "This does not catch the crash", e)
    }
}

Additional Requests / Suggestions

Since this issue involves how the SDK handles server signals and media, I would like to propose the following improvements:

  • "goAway" Message Handling & Session Extension Instead of crashing, the SDK should handle the "goAway" message gracefully.
    • Feature Request: Expose this event to the client so we can handle session termination properly.
    • Feature Request: Provide a mechanism to extend the session upon receiving this warning, or allow seamless reconnection without losing context.

or just add goAwayHander param to LiveAudioConversationConfig constructor to handle goAway signal

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions