[core] Client disconnects don't cancel the model stream (per-step flow is cached) — and there is no public API to cancel an in-flight run
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Describe the Bug
When a client disconnects while an agent is streaming (e.g. the SSE consumer cancels its subscription to Runner's event flow), the underlying model call keeps running to completion. Tokens continue to be billed with no consumer attached. In one production incident the model kept generating for 3+ minutes after the client went away (observed via gateway-side logs and token metering).
The cause appears to be BaseLlmFlow.java line 530 (main at the time of writing):
Flowable<Event> currentStepEvents = runOneStep(spanContext, invocationContext).cache();
With RxJava cache(), the upstream connection is only disposed when all subscribers of the cached flow cancel. As long as any subscriber attached by the framework itself (event handling/aggregation within the invocation) is alive, a user-side cancellation cannot reach the model stream.
On top of that, there is no public API to cancel an in-flight run: neither Runner nor InvocationContext nor the session exposes a "stop generating" handle. The only way to stop a long generation is to let it finish.
To Reproduce
- Serve an agent behind SSE; start a streaming run with a slow/long model response (or a multi-round tool loop).
- Disconnect the SSE client mid-generation and dispose the event-flow subscription.
- Observe on the model/gateway side (or via token metering) that generation continues until the model finishes naturally.
Expected behavior
Cancelling the downstream subscription (or any public cancellation entry point) must reach the model stream: the in-flight LLM request is disposed (or aborted at the next chunk/round boundary), and no further rounds are started.
Environment
- google/adk-java main (1.11.1-SNAPSHOT at the time of writing)
- Spring AI bridge + SSE transport, but the
cache()behavior is in core (BaseLlmFlow) and should affect any transport
Additional context
In production we could only implement "stop generating" with a cooperative cancellation protocol outside the framework: a per-run cancel flag (REST endpoint sets it) that the model-stream loop checks at every chunk and at tool-round boundaries, plus setCancellable hooks for the current round. It works, but it is entirely application-side — the framework neither propagates the cancellation nor offers a canonical way to express it.
Suggested directions (happy to discuss or contribute):
- Replace the unbounded
cache()with cancellation-propagating semantics (e.g.publish().refCount()-style sharing, or a scoped subscription that disposes the source when the invocation ends/cancels), or - Expose a first-class cancellation handle per run/invocation, and document that model loops should check it at chunk/round boundaries (cooperative cancellation), or
- At minimum, document the current behavior prominently — today it silently leaks billable model calls.
- Lingua principale
- Java
- Stelle
- 1.7k
- Fork
- 433
- Merge medio
- 3g 9h
- PR unite (30g)
- 46
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/adk-java
-
GeminiUtil placeholder user turn ("Continue output. DO NOT look at this line ...") is flagged by prompt injection filtersForse già presa @hemasekhar-p l’ha presa 2 giorni fa. Apertaneeds review
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
google/adk-java#1628 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[spring-ai] ToolConverter silently drops enum and items from tool parameter schemasForse già presa @hirematha l’ha presa 4 giorni fa. Apertaneeds review
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
google/adk-java#1609 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[spring-ai] Streaming responses ending with CJK punctuation (。!?) are misclassified as partial and never persisted to the sessionForse già presa @hirematha l’ha presa 4 giorni fa. Apertaneeds review
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
google/adk-java#1608 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
FirestoreSessionService loses event fields on reload, breaking later turns and tool confirmationsForse già presa @innoprej l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
I maintainer di solito rispondono entro 1 giorno
-
Claude model throws UnsupportedOperationException("Not supported yet.") on thinking blocks from Claude 5 modelsForse già presa @hemasekhar-p l’ha presa 2 giorni fa. Apertaneeds review
google/adk-java#1630 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di google/adk-java
Issue simili
-
`Processing lsp` never exits and leaves orphaned processesForse già presa @overcast302 l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
processing/processing4#1578 · 1 commento ·
-
ASM is not up-to-dateAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 60/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG] S3 CORS responses omit Access-Control-Allow-Credentials for matched originsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
floci-io/floci#5369 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
securityHeaders replaces a route's own Content-Security-Policy (0.9.9; weakens embedders' pages)Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
sqlcipher/sqlcipher-android#97 · 1 commento ·