Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[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

未关闭
#1,618 6 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@hemasekhar-p 已经在做这个了。

开始于 2026年10月6日。

  • #1621 来自 @sangkyoonnam —— 未关闭

评估

这个 Issue 还没有评估数据。

描述

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.
主要语言
Java
星标
1.7k
派生
433
平均合并
3 天 9 小时
30 天内合并 PR
46

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/adk-java 的其他 Issue

查看 google/adk-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。