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

[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

Aperta
#1,618 6 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@hemasekhar-p ci sta già lavorando.

Dal 6/10/2026.

  • #1621 di @sangkyoonnam — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

needs review
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
  1. Serve an agent behind SSE; start a streaming run with a slow/long model response (or a multi-round tool loop).
  2. Disconnect the SSE client mid-generation and dispose the event-flow subscription.
  3. 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):

  1. 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
  2. Expose a first-class cancellation handle per run/invocation, and document that model loops should check it at chunk/round boundaries (cooperative cancellation), or
  3. 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

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.