Description
CustomDurationDeserializer in JsonSerializable only parses whole-second Duration values (Long.parseLong), but the Gemini Live API server streams fractional-second Durations (e.g. "7.280s", "1.600s", "0.360s"). The parse throws NumberFormatException, which surfaces as:
SEVERE: Error deserializing message
com.google.genai.errors.GenAiIOException: Failed to deserialize the JSON node.
Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException:
Cannot deserialize value of type `java.time.Duration` from String "7.280s":
Cannot parse duration from string: 7.280s. Expected format 'Xs'.
Because this happens inside the Live WebSocket read path, the entire server message is dropped. When that message carries the model turn / a function call, the turn is lost — in a voice-agent app the assistant cuts off mid-sentence and no tool call fires.
Impact
Production voice-reception app on gemini-3.1-flash-live-preview (Vertex): ~700 of these errors in 24h across ~190 calls (~3–4 per call). Most calls survive because the read loop resumes on the next message, but an intermittent few break at the worst moment (mid first response / on the transfer tool call).
Root cause
src/main/java/com/google/genai/JsonSerializable.java, CustomDurationDeserializer:
long seconds = Long.parseLong(secondsPart); // rejects "7.280"
return java.time.Duration.ofSeconds(seconds);
Suggested fix
Parse decimal seconds and keep sub-second precision:
double seconds = Double.parseDouble(secondsPart);
return java.time.Duration.ofNanos(Math.round(seconds * 1_000_000_000.0));
(Protobuf google.protobuf.Duration is routinely JSON-encoded with fractional seconds, so this is the expected wire format.)
Versions
- google-genai 1.61.0 (also present in 1.62.0 —
JsonSerializable unchanged)
- Model:
gemini-3.1-flash-live-preview, Vertex AI, Live API (BidiGenerateContent)
- Java 25
Description
CustomDurationDeserializerinJsonSerializableonly parses whole-secondDurationvalues (Long.parseLong), but the Gemini Live API server streams fractional-second Durations (e.g."7.280s","1.600s","0.360s"). The parse throwsNumberFormatException, which surfaces as:Because this happens inside the Live WebSocket read path, the entire server message is dropped. When that message carries the model turn / a function call, the turn is lost — in a voice-agent app the assistant cuts off mid-sentence and no tool call fires.
Impact
Production voice-reception app on
gemini-3.1-flash-live-preview(Vertex): ~700 of these errors in 24h across ~190 calls (~3–4 per call). Most calls survive because the read loop resumes on the next message, but an intermittent few break at the worst moment (mid first response / on the transfer tool call).Root cause
src/main/java/com/google/genai/JsonSerializable.java,CustomDurationDeserializer:Suggested fix
Parse decimal seconds and keep sub-second precision:
(Protobuf
google.protobuf.Durationis routinely JSON-encoded with fractional seconds, so this is the expected wire format.)Versions
JsonSerializableunchanged)gemini-3.1-flash-live-preview, Vertex AI, Live API (BidiGenerateContent)