[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
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
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.
- Vorherrschende Sprache
- Java
- Sterne
- 1.7k
- Forks
- 431
- Ø Merge
- 3 T. 2 Std.
- Gemergte PRs (30 T.)
- 46
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus google/adk-java
-
GeminiUtil placeholder user turn ("Continue output. DO NOT look at this line ...") is flagged by prompt injection filtersEvtl. vergeben @innoprej hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
[spring-ai] ToolConverter silently drops enum and items from tool parameter schemasEvtl. vergeben @hirematha hat das vor 2 Tagen übernommen. Offenneeds review
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
google/adk-java#1609 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
[spring-ai] Streaming responses ending with CJK punctuation (。!?) are misclassified as partial and never persisted to the sessionEvtl. vergeben @hirematha hat das vor 2 Tagen übernommen. Offenwaiting on reporter
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
google/adk-java#1608 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
[spring-ai] Bridge drops reasoning_content (thinking) — surface it as partial events and/or persist itEvtl. vergeben @hemasekhar-p hat das vor 2 Tagen übernommen. Offenneeds review
google/adk-java#1616 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
[FEATURE] Port bypass_multi_tools_limit for built-in search tools from adk-pythonEvtl. vergeben @hirematha hat das vor 2 Tagen übernommen. Offenneeds review
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
google/adk-java#1598 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in google/adk-java
Ähnliche Issues
-
Mend: dependency security vulnerability
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
opfab/operatorfabric-core#10653 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Broken links in the docsOffen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
salesforce/multicloudj#667 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 2 Tagen
-
bug documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
MetricsHub/winrm-java#202 ·
Maintainer antworten meist innerhalb von 1 Tag