Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

runLive passes partial events to appendEvent and never aggregates text chunks, unlike ADK Python

Aperta
#1,648 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend, databases

Direzione di ricerca

Start with GeminiLlmConnection.java and the live event handling in BaseLlmFlow.java, then compare the partial event handling in Runner.runAsync and Runner.runLive. Check RunnerTest and FirestoreSessionServiceTest for the described reproductions. Done means live text chunks stream as partial events while each turn's accumulated text is stored once as a non-partial event across session services.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🔴 Required Information

Describe the Bug:

In live mode, the model text that a turn leaves in the session differs from ADK Python and depends on the session service. Two things combine:

  1. runLive passes partial events to the session service. Runner.runAsync skips partial events before appendEvent (Runner.java:865-872, added in #1307), but Runner.runLive passes every event to appendEvent (Runner.java:1462-1464).
  2. The live path never aggregates text. GeminiLlmConnection turns the serverContent of each server message into one LlmResponse (GeminiLlmConnection.java:129-191), and BaseLlmFlow makes each response with content its own event (BaseLlmFlow.java:668-681). A response is partial only if its message carries turnComplete: false (GeminiLlmConnection.java:185). Nothing produces a full-text event for the turn.

The session services handle partial events differently:

So what a live turn leaves in the session depends on whether the Live API's interim messages carry turnComplete: false, which I could not confirm:

Interim server messages InMemorySessionService FirestoreSessionService, VertexAiSessionService
(a) no turnComplete field one model event per chunk one model event per chunk
(b) turnComplete: false no model text one model event per chunk

In both cases, the message that completes the turn is also stored as an event of its own, even without content (BaseLlmFlow.java:746-762); ADK Python stores that event too. Case (b) assumes that this message carries no text; if it does, InMemorySessionService keeps only that last piece.

ADK Python stores one non-partial event with the full text either way. Its live connection marks every text chunk partial (gemini_llm_connection.py:404) and yields a separate non-partial response with the accumulated text when the turn completes or is interrupted, when a tool call arrives, or when a part that is neither text nor inline data arrives (:250-284, :407-410, :527-556, :600-627). Transcription chunks are likewise partial, followed by one non-partial transcription (:431-526). Its runner then skips partial events in live mode (runners.py:1556-1563), as the Java runAsync path does.

Stored chunks reach later requests. runLive sends the session history when it connects (BaseLlmFlow.java:587-592), and a later runAsync builds its request from the same events. Contents.java neither checks partial nor merges consecutive model events (it merges only function responses), so each stored chunk becomes its own model turn. I have not checked what the model does with that.

Steps to Reproduce:

  1. Check out main at 189d463a, where I ran the tests. The code cited above is the same in 1.11.0; the links point to main.
  2. Add the first test below to RunnerTest, next to runAsync_partialEvent_streamedButNotPassedToSessionService (RunnerTest.java:3469-3500), and run it. It reuses RecordingSessionService, the session service that test uses. The test model returns two text chunks and a turn-complete response, built the way GeminiLlmConnection builds them in case (a) and in case (b).
  3. Add the second test to FirestoreSessionServiceTest and run it. It appends one partial event using the class's mocks.

I did not run this against the Gemini Live API, Firestore or Vertex AI. TestLlm's live connection returns the responses it is given, so the first test shows what the runner and InMemorySessionService do with responses of that shape, not what the Live API sends.

Expected Behavior:

Partial chunks are streamed to the caller but not saved, and each live turn stores its full text in one non-partial event in every session service, as ADK Python does.

Observed Behavior:

The first test prints:

chunks partial = false
  passed to appendEvent: ["Hel", "lo", turnComplete ""]
  kept by InMemory:      ["Hel", "lo", turnComplete ""]
chunks partial = true
  passed to appendEvent: [partial "Hel", partial "lo", turnComplete ""]
  kept by InMemory:      [turnComplete ""]

The second prints the fields of the stored event document; partial is not among them:

stored fields: [appName, author, content, keywords, timestamp, userId]

Environment Details:

  • ADK Library Version (see maven dependency): main at 189d463a, where I ran the tests below (plus google-adk-firestore-session-service for the Firestore part); the cited code is the same in google-adk 1.11.0
  • OS: Windows 11 (not OS-specific)
  • TS Version (tsc --version): N/A (Java: Microsoft OpenJDK 17.0.19)

Model Information:

  • Which model is being used: N/A (no model was called; the affected path is GeminiLlmConnection, which Gemini Live API models use)

🟡 Optional Information

Regression:

No. The live path has never aggregated text. In 1.6.0, #1307 added the partial check to runAsync only, and #1333 made runLive subscribe to the Single that appendEvent returns. Before #1333, the work of FirestoreSessionService (inside Single.fromCallable) and the API call of VertexAiSessionService never ran from runLive, so those services stored nothing from live turns. Since 1.6.0 they store the chunks.

Additional Context:

  • A direction that matches ADK Python takes two steps, and each needs the other:

    1. Aggregate in the live path: keep streaming text and transcription chunks as partial events, and emit one non-partial event with the accumulated text where ADK Python does (turn complete, interruption, tool call). This could go in GeminiLlmConnection, as in Python, or in the live branch of BaseLlmFlow.
    2. Skip partial events in runLive as runAsync does. A live counterpart of runAsync_partialEvent_streamedButNotPassedToSessionService would cover it.

    Step 2 alone would change nothing in case (a), where the chunks are not partial, and in case (b) it would make every session service lose the live model text, as InMemorySessionService does today. Step 1 alone would leave Firestore and Vertex AI storing the chunks next to the full text.

  • A smaller, independent alignment: FirestoreSessionService.appendEvent could return early for partial events, like the default implementation and ADK Python's Firestore service (firestore_session_service.py:497-500). #1643 (for #1640) changes how events are stored, not which events are stored, so it does not change this: with #1643 a stored chunk would come back with partial: true, but Contents does not read the flag.

  • Live audio is a separate difference: ADK Python does not save live model audio events with inline data (runners.py:1469-1486). Java has no such check, so those events follow the same rules as the text chunks, and FirestoreSessionService writes them without the audio.

  • To tell (a) from (b), GeminiLlmConnection logs every server message at debug level (GeminiLlmConnection.java:118). The serverContent cases in GeminiLlmConnectionTest always set turnComplete, and I did not find a recorded server message in the repository.

  • Does aggregating in the live path and then skipping partial events in runLive match how you want live sessions to be stored? If so, I'm happy to send a PR and to follow your choice of where the aggregation should go.

Minimal Reproduction Code:

The first test goes into RunnerTest and uses its RecordingSessionService, createContent and imports:

  @Test
  public void runLive_textChunks_passedToSessionServiceUnaggregated() throws Exception {
    // GeminiLlmConnection makes one LlmResponse per serverContent and never aggregates text.
    // A chunk is partial only if its message carries turnComplete: false.
    for (boolean chunksArePartial : new boolean[] {false, true}) {
      TestLlm testLlm =
          new TestLlm(
              () ->
                  Flowable.just(
                      liveTextChunk("Hel", chunksArePartial),
                      liveTextChunk("lo", chunksArePartial),
                      LlmResponse.builder().partial(false).turnComplete(true).build()));
      RecordingSessionService sessionService = new RecordingSessionService();
      Runner runner =
          Runner.builder()
              .app(App.builder().name("test").rootAgent(createTestAgent(testLlm)).build())
              .sessionService(sessionService)
              .build();
      Session session = sessionService.createSession("test", "user").blockingGet();
      LiveRequestQueue liveRequestQueue = new LiveRequestQueue();

      TestSubscriber<Event> testSubscriber =
          runner.runLive(session, liveRequestQueue, RunConfig.builder().build()).test();
      liveRequestQueue.content(createContent("hi"));
      liveRequestQueue.close();
      testSubscriber.await();

      Session stored =
          sessionService.getSession("test", "user", session.id(), Optional.empty()).blockingGet();
      System.out.println("chunks partial = " + chunksArePartial);
      System.out.println("  passed to appendEvent: " + describe(sessionService.appendedEvents));
      System.out.println("  kept by InMemory:      " + describe(stored.events()));
    }
  }

  private static LlmResponse liveTextChunk(String text, boolean partial) {
    return LlmResponse.builder()
        .content(Content.builder().role("model").parts(Part.fromText(text)).build())
        .partial(partial)
        .turnComplete(false)
        .build();
  }

  private static List<String> describe(List<Event> events) {
    return events.stream()
        .map(
            e ->
                (e.partial().orElse(false) ? "partial " : "")
                    + (e.turnComplete().orElse(false) ? "turnComplete " : "")
                    + "\""
                    + e.content().map(Content::text).orElse("")
                    + "\"")
        .toList();
  }

The second goes into FirestoreSessionServiceTest and uses its mocks, constants and imports:

  @Test
  @SuppressWarnings("unchecked")
  void appendEvent_writesPartialEvent() {
    Session session =
        Session.builder(SESSION_ID)
            .appName(APP_NAME)
            .userId(USER_ID)
            .state(new ConcurrentHashMap<>())
            .build();
    when(mockSessionsCollection.document(SESSION_ID)).thenReturn(mockSessionDocRef);
    when(mockEventsCollection.document()).thenReturn(mockEventDocRef);
    when(mockEventDocRef.getId()).thenReturn(EVENT_ID);
    when(mockEventsCollection.document(EVENT_ID)).thenReturn(mockEventDocRef);
    Event chunk =
        Event.builder()
            .author("model")
            .partial(true)
            .content(Content.fromParts(Part.fromText("Hel")))
            .build();

    sessionService.appendEvent(session, chunk).blockingGet();

    // The partial event is written as an event document (verify passes).
    ArgumentCaptor<Map<String, Object>> saved = ArgumentCaptor.forClass(Map.class);
    verify(mockEventDocRef).set(saved.capture());
    System.out.println("stored fields: " + saved.getValue().keySet().stream().sorted().toList());
  }

How often has this issue occurred?:

  • Always (100%) in live mode. In case (a), every turn whose text arrives in more than one server message is affected; in case (b), every turn with model text.
Lingua principale
Java
Stelle
1.7k
Fork
433
Merge medio
2g 21h
PR unite (30g)
40

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google/adk-java

Tutte le issue di google/adk-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.