googleapis / googleapis/java-genai
Live API: no way to observe session close or connection errors after setup
- Dominant language
- Java
- Stars
- 397
- Forks
- 125
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 41
Description
## 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:
```java
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](https://github.com/langchain4j/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:
```java
public CompletableFuture receive(
Consumer onMessage, Consumer 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.
Contributor guide
Assessment
This issue has not been assessed yet.