runLive passes partial events to appendEvent and never aggregates text chunks, unlike ADK Python
Maintainers usually reply within 1 day
@hemasekhar-p is already working on this.
Since Oct 12, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
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.
Written by the indexing model from the issue text.
Description
🔴 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:
runLivepasses partial events to the session service.Runner.runAsyncskips partial events beforeappendEvent(Runner.java:865-872, added in #1307), butRunner.runLivepasses every event toappendEvent(Runner.java:1462-1464).- The live path never aggregates text.
GeminiLlmConnectionturns theserverContentof each server message into oneLlmResponse(GeminiLlmConnection.java:129-191), andBaseLlmFlowmakes each response with content its own event (BaseLlmFlow.java:668-681). A response is partial only if its message carriesturnComplete: false(GeminiLlmConnection.java:185). Nothing produces a full-text event for the turn.
The session services handle partial events differently:
InMemorySessionServicedrops them. It calls the defaultappendEvent(InMemorySessionService.java:351), which returns early for partial events (BaseSessionService.java:232-235).FirestoreSessionServicewrites them like any other event. ItsappendEventhas no partial check (FirestoreSessionService.java:634-739), and the file never reads or writespartial, so a chunk comes back as an ordinary event on reload.VertexAiSessionServicecalls the defaultappendEventand then sends the event to the API anyway (VertexAiSessionService.java:320-331).partialis written to the event metadata and restored on reload (SessionJsonConverter.java:131,:527), butContentsnever reads it. I only read this code; I did not run it against Vertex AI.
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:
- Check out
mainat189d463a, where I ran the tests. The code cited above is the same in 1.11.0; the links point tomain. - Add the first test below to
RunnerTest, next torunAsync_partialEvent_streamedButNotPassedToSessionService(RunnerTest.java:3469-3500), and run it. It reusesRecordingSessionService, the session service that test uses. The test model returns two text chunks and a turn-complete response, built the wayGeminiLlmConnectionbuilds them in case (a) and in case (b). - Add the second test to
FirestoreSessionServiceTestand 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):
mainat189d463a, where I ran the tests below (plusgoogle-adk-firestore-session-servicefor the Firestore part); the cited code is the same ingoogle-adk1.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:
- 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 ofBaseLlmFlow. - Skip partial events in
runLiveasrunAsyncdoes. A live counterpart ofrunAsync_partialEvent_streamedButNotPassedToSessionServicewould 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
InMemorySessionServicedoes today. Step 1 alone would leave Firestore and Vertex AI storing the chunks next to the full text. - 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
-
A smaller, independent alignment:
FirestoreSessionService.appendEventcould 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 withpartial: true, butContentsdoes 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, andFirestoreSessionServicewrites them without the audio. -
To tell (a) from (b),
GeminiLlmConnectionlogs every server message at debug level (GeminiLlmConnection.java:118). TheserverContentcases inGeminiLlmConnectionTestalways setturnComplete, and I did not find a recorded server message in the repository. -
Does aggregating in the live path and then skipping partial events in
runLivematch 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.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 433
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 43
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/adk-java
-
GeminiUtil placeholder user turn ("Continue output. DO NOT look at this line ...") is flagged by prompt injection filtersPossibly taken @hemasekhar-p claimed this 4 days ago. Openneeds review
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
google/adk-java#1628 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
[spring-ai] Streaming responses ending with CJK punctuation (。!?) are misclassified as partial and never persisted to the sessionPossibly taken @hirematha claimed this 7 days ago. Openneeds review
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
google/adk-java#1608 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Maintainers usually reply within 1 day
-
FirestoreSessionService compares event timestamps as text, reordering or skipping same-second eventsPossibly taken @hemasekhar-p claimed this today. Openwaiting on reporter
Difficulty 3/5 1-2 days Newbie friendliness 50/100
google/adk-java#1646 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
FirestoreSessionService ignores `app:` / `user:` state prefixes, so app and user state are never shared across sessionsPossibly taken @hemasekhar-p claimed this 1 day ago. Openwaiting on reporter
Difficulty 4/5 3-5 days Newbie friendliness 45/100
google/adk-java#1645 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
[BUG] 增量 SSE 解析器未识别单独 CR 换行,导致事件无法及时交付Possibly taken @king-wwwhhh claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
langchain4j/langchain4j#6669 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OpenAPITools/openapi-generator#25237 ·
Maintainers usually reply within 1 day
-
needs-area-label
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
quelea-projection/Quelea#711 ·
-
bug pdd
Difficulty 2/5 Under an hour Newbie friendliness 67/100
objectionary/eo#9450 ·
Maintainers usually reply within 1 day