Skip to content

fix(live): handle goAway and voice activity notifications - #1878

Open
YuqiGuo105 wants to merge 1 commit into
google:mainfrom
YuqiGuo105:fix/issue-1872-live-control-messages
Open

YuqiGuo105 wants to merge 1 commit into
google:mainfrom
YuqiGuo105:fix/issue-1872-live-control-messages

Conversation

@YuqiGuo105

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

Closes #1872.

Problem

GeminiLlmConnection treats valid Live goAway, voiceActivity, and voiceActivityDetectionSignal messages as unknown-message errors. In particular, the goAway.timeLeft warning never reaches callers. Simply recognizing these messages in the connection is insufficient: the flow also discards contentless responses unless their metadata is explicitly preserved.

Solution

  • Add optional, typed goAway and voiceActivity fields to LlmResponse and Event, following ADK Python's response fields. Preserve them through the flow, JSON round-trips, builders, and event equality.
  • Forward goAway and voiceActivity notifications without reporting an error. Recognize the lower-level voiceActivityDetectionSignal without emitting an event, since it has no ADK event representation.
  • Keep control-only events from being classified as final answers. Notifications do not complete a turn, flush buffered text, or proactively close the connection.
  • Preserve existing handling of content, usage metadata, and genuinely unknown messages, including messages carrying multiple fields.

This change exposes the warning; it does not implement automatic reconnection/session resumption or address SDK-level wire parsing issues.

Testing Plan

Automated tests

  • Added 15 regression tests across GeminiLlmConnectionTest, LlmResponseTest, EventTest, BaseLlmFlowTest, and RunnerTest.
  • Confirmed that three reproducer tests fail against the original converter.
  • Verified payload preservation, optional/null fields, JSON round-trips, non-final notification events, mixed content/notification messages, uninterrupted text aggregation, and delivery through Runner.runLive.
  • Verified with a fake transport that goAway does not close the connection or prevent later responses.

Validation on the latest fetched main (dde4b23d), using Maven 3.9.16 and Temurin 25.0.3 (Java release 17):

mvn -o -B -pl core -am clean test

Both main core test executions (default-test and basic) report 4,177 tests, 0 failures, 0 errors, and 35 skipped. The additional configured Vertex AI/Apigee/tracking-header executions also pass. These are repeated/configured executions, not distinct-test counts to be added together.

The illegal-Optional-parameter check passes for all changed production files. Running that optional profile across all core sources previously reported 12 violations in seven unchanged files; those are outside this patch.

Manual End-to-End (E2E) Tests

Not performed against a real Gemini Live endpoint; automated tests use simulated messages and a fake transport/model. To verify manually:

  1. Start a BIDI Runner.runLive session and inspect emitted events.
  2. When the server sends a goAway warning, verify event.goAway() preserves timeLeft, with no unknown-message error and no immediate client-initiated close.
  3. In a session configured to emit voice activity notifications, speak and stop speaking; verify event.voiceActivity() carries the activity type without being classified as a final answer.

Checklist

  • I have read the contribution guide.
  • This pull request contains a single commit.
  • I have reviewed the changes and formatted only changed lines with google-java-format.
  • Regression tests cover the fix, and the core test suite passes locally.
  • I have manually tested against a real Gemini Live endpoint.

@hemasekhar-p hemasekhar-p self-assigned this Nov 26, 2026
@hemasekhar-p

Copy link
Copy Markdown
Contributor

Hi @YuqiGuo105, Thank you for your contribution and for taking the time to submit this pull request. Our team is currently reviewing your changes, and we will reach out if we need any further information.

Comment on lines +336 to +344
/** A Live server warning that the connection will close; does not complete the model turn. */
@JsonProperty("goAway")
public Optional<LiveServerGoAway> goAway() {
return Optional.ofNullable(goAway);
}

public void setGoAway(@Nullable LiveServerGoAway goAway) {
this.goAway = goAway;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DESIGN (HIGH): This exposes go-away as a public Event field that callers receive and the session stores. ADK Python consumes go_away in the live flow and reconnects (v1, main). ADK Kotlin does the same and has no goAway on Event. Once Java adds reconnection, this field will go unused or need removal.

In my live run, the server closed the socket 30 s after goAway, and runLive neither completed nor failed. For now, this event is the caller's only warning.

Handling goAway inside BaseLlmFlow is better alternative here

Comment on lines +463 to +464
&& goAway().isEmpty()
&& voiceActivity().isEmpty()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DESIGN (MEDIUM): Please drop this change to finalResponse(). ADK Python's is_final_response() and ADK Kotlin's isFinalResponse both return true for these events (google-adk 2.15.1: voice_activity=True go_away=True). Java's transcription-only and usage-only events stay final too. Nothing in the repo relies on this change: removing those two lines fails only the new assertions. It also affects events that carry content: a model response with text and voiceActivity makes runAsync loop until maxLlmCalls (500).

Comment on lines +201 to +202
// This lower-level VAD signal has no ADK event representation. Recognize it
// without treating it as an error or as the end of the model turn.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLEANUP (LOW): A one-line comment is enough here, for example: // No ADK event carries this signal; recognize it so it is not reported as unknown.

Comment on lines +118 to +178
public void event_liveControlFields_roundTripAndCopy_preservePayloads() {
LiveServerGoAway goAway = LiveServerGoAway.builder().timeLeft(Duration.ofMillis(30500)).build();
VoiceActivity voiceActivity =
VoiceActivity.builder()
.voiceActivityType("ACTIVITY_END")
.audioOffset(Duration.ofMillis(1250))
.build();
Event event = EVENT.toBuilder().goAway(goAway).voiceActivity(voiceActivity).build();

Event restored = Event.fromJson(event.toJson());
assertThat(restored).isEqualTo(event);
assertThat(restored.goAway()).hasValue(goAway);
assertThat(restored.voiceActivity()).hasValue(voiceActivity);
Event copied = event.toBuilder().build();
assertThat(copied).isEqualTo(event);
assertThat(copied.hashCode()).isEqualTo(event.hashCode());
assertThat(copied.toBuilder().goAway(null).voiceActivity(null).build()).isEqualTo(EVENT);
}

@Test
public void event_liveControlFields_defaultAndNull_areAbsent() {
for (String json : ImmutableList.of("{}", "{\"goAway\":null,\"voiceActivity\":null}")) {
Event event = Event.fromJson(json);
assertThat(event.goAway()).isEmpty();
assertThat(event.voiceActivity()).isEmpty();
assertThat(event.toJson()).doesNotContain("\"goAway\"");
assertThat(event.toJson()).doesNotContain("\"voiceActivity\"");

event.setGoAway(LiveServerGoAway.builder().build());
event.setVoiceActivity(VoiceActivity.builder().build());
assertThat(event.goAway()).isPresent();
assertThat(event.voiceActivity()).isPresent();
event.setGoAway(null);
event.setVoiceActivity(null);
assertThat(event.goAway()).isEmpty();
assertThat(event.voiceActivity()).isEmpty();
}
}

@Test
public void event_equals_distinguishesLiveControlFields() {
assertThat(EVENT.toBuilder().goAway(LiveServerGoAway.builder().build()).build())
.isNotEqualTo(EVENT);
assertThat(EVENT.toBuilder().voiceActivity(VoiceActivity.builder().build()).build())
.isNotEqualTo(EVENT);
}

@Test
public void event_finalResponse_liveNotifications_areNotFinalAnswers() {
assertThat(Event.builder().goAway(LiveServerGoAway.builder().build()).build().finalResponse())
.isFalse();
for (String type : ImmutableList.of("ACTIVITY_START", "ACTIVITY_END")) {
assertThat(
Event.builder()
.voiceActivity(VoiceActivity.builder().voiceActivityType(type).build())
.build()
.finalResponse())
.isFalse();
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLEANUP (LOW): Several new tests loop over cases or check multiple behaviors at once. For instance, event_liveControlFields_roundTripAndCopy_preservePayloads tests JSON, copying, equals, hashCode, and resetting to null. Please split these into one behavior per test, or parameterize them. Some tests also overlap: controlMessages_preserveEmptyPayloads duplicates controlsAlongsideContentAndUsage_preservesAllFields, and receive_goAway_doesNotCloseConnectionOrStopLaterResponses guards a close path the connection does not have.

@damianmomotgoogle damianmomotgoogle added waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. and removed needs review labels Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Live: goAway and voiceActivity messages are reported as "Unknown server message" errors

3 participants