[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
Los mantenedores suelen responder en 1 día
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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.
- Lenguaje dominante
- Java
- Estrellas
- 1.7k
- Forks
- 433
- Merge medio
- 3 d 11 h
- PR fusionados (30 d)
- 50
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de google/adk-java
-
GeminiUtil placeholder user turn ("Continue output. DO NOT look at this line ...") is flagged by prompt injection filtersPosiblemente ocupada @hemasekhar-p la tomó hace 1 día. Abiertoneeds review
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
google/adk-java#1628 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[spring-ai] ToolConverter silently drops enum and items from tool parameter schemasPosiblemente ocupada @hirematha la tomó hace 4 días. Abiertoneeds review
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
google/adk-java#1609 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[spring-ai] Streaming responses ending with CJK punctuation (。!?) are misclassified as partial and never persisted to the sessionPosiblemente ocupada @hirematha la tomó hace 4 días. Abiertoneeds review
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
google/adk-java#1608 · 3 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Claude model throws UnsupportedOperationException("Not supported yet.") on thinking blocks from Claude 5 modelsPosiblemente ocupada @hemasekhar-p la tomó hace 1 día. Abiertoneeds review
google/adk-java#1630 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[spring-ai] Bridge drops reasoning_content (thinking) — surface it as partial events and/or persist itPosiblemente ocupada @hemasekhar-p la tomó hace 3 días. Abiertoneeds review
google/adk-java#1616 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de google/adk-java
Issues similares
-
[Bug] AI unread message badge counts a batch of new bubbles as one messagePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
apache/rocketmq-dashboard#5784 ·
Los mantenedores suelen responder en 3 días
-
[i18n] 安装实例完成后的成功提示未正确本地化Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
PCL-Community/PCL-CE#3658 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
apache/skywalking#14127 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Team/Identity Server Core Type/Improvement U2
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
wso2/product-is#28553 ·
Los mantenedores suelen responder en 1 día