Summary
After a Live session is established, a caller has no way to be notified that it ended. When the server closes the session (e.g. after GoAway) or the WebSocket drops, AsyncLive.GenAiWebSocketClient only logs onClosed/onFailure nothing reaches the receive() message consumer or any future, so the application can't react. receive() itself returns an already-completed future (its Javadoc notes it only signals registration), so it can't carry the signal either.
Root cause
In AsyncLive.GenAiWebSocketClient, once sessionFuture is done (i.e. for the whole active session) these just log:
public void onClosed(WebSocket webSocket, int code, String reason) {
logger.log(Level.INFO, "Live session closed ...");
if (!sessionFuture.isDone()) { sessionFuture.completeExceptionally(...); } // else: only logged
}
public void onFailure(WebSocket webSocket, Throwable t, @Nullable Response response) {
logger.log(Level.SEVERE, "Error during live session", t);
if (!sessionFuture.isDone()) { sessionFuture.completeExceptionally(t); } // else: only logged
}
Impact
Found while building the Gemini Live API integration for langchain4j: the wrapper can't tell the application when a session ends. A listen-only voice agent is never notified that the connection dropped the only signal today is an exception on the next send.
Suggested fix
A backward-compatible overload of receive(...), with onError/onClose invoked from onFailure/onClosed after setup (terminal, mutually exclusive, nullable); the existing receive(Consumer) delegates to it:
public CompletableFuture<Void> receive(
Consumer<LiveServerMessage> onMessage, Consumer<Throwable> onError, Runnable onClose)
Open to a different shape (e.g. a listener interface) if you'd prefer.
Environment
com.google.genai:google-genai 1.62.0, and unchanged on current main (1.65.0-SNAPSHOT). Gemini Live API, Java.
Summary
After a Live session is established, a caller has no way to be notified that it ended. When the server closes the session (e.g. after
GoAway) or the WebSocket drops,AsyncLive.GenAiWebSocketClientonly logsonClosed/onFailurenothing reaches thereceive()message consumer or any future, so the application can't react.receive()itself returns an already-completed future (its Javadoc notes it only signals registration), so it can't carry the signal either.Root cause
In
AsyncLive.GenAiWebSocketClient, oncesessionFutureis done (i.e. for the whole active session) these just log:Impact
Found while building the Gemini Live API integration for langchain4j: the wrapper can't tell the application when a session ends. A listen-only voice agent is never notified that the connection dropped the only signal today is an exception on the next send.
Suggested fix
A backward-compatible overload of
receive(...), withonError/onCloseinvoked fromonFailure/onClosedafter setup (terminal, mutually exclusive, nullable); the existingreceive(Consumer)delegates to it:Open to a different shape (e.g. a listener interface) if you'd prefer.
Environment
com.google.genai:google-genai1.62.0, and unchanged on currentmain(1.65.0-SNAPSHOT). Gemini Live API, Java.