Skip to content

fix(a2a): end cancelled executions, apply blocking timeouts and close the transport pool - #3993

Merged
jujn merged 2 commits into
agentscope-ai:mainfrom
guslegend0510:fix/a2a-server-cancel-release
Nov 5, 2026
Merged

jujn merged 2 commits into
agentscope-ai:mainfrom
guslegend0510:fix/a2a-server-cancel-release

Conversation

@guslegend0510

@guslegend0510 guslegend0510 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (main)

Description

接替已关闭的 #3578,基于 A2A 1.0(#3590 合入后)的 main 重做,只保留下面三处修复。

问题

  1. 取消任务后执行线程永远阻塞。 AgentScopeAgentExecutor.cancel() 取消的是 doOnSubscribe 拿到的上游订阅。上游停了,下游却收不到任何结束信号,blockLast() 也没有超时,于是执行线程一直卡着,doFinally 也不会运行。每取消一个流式任务(或 returnImmediately=true 的任务)就漏一个线程。A2aHttpEndToEndTest.interruptCancelsRemoteTask 正是因为这个原因被 @Disabled。
  2. Starter 的两个阻塞超时配置不生效。 agentscope.a2a.server 下的 agent-completion-timeout-seconds、consumption-completion-timeout-seconds 能绑定,但没有任何代码读取;AgentScopeA2aRequestHandler 里写死了 60 / 10 秒。
  3. 传输层线程池不会被关闭。 AgentScopeA2aServer 没有传入 executor 时会自己建一个 newCachedThreadPool,但 close() 只关了请求处理器。这个池还被存进了 builder,同一个 builder 下一次 build() 会共用它。

改动

  • AgentScopeAgentExecutor:每个执行登记一个取消信号,代替原来登记的订阅。流水线最后加 takeUntilOther(取消信号):取消时上游被切断,下游正常结束,blockLast() 返回。即使 agentRunner.stop() 抛错,取消信号也照样发出。登记和精确删除的方式与 fix(a2a): prevent task lifecycle races #3828 相同。
  • 超时:AgentExecuteProperties 新增两个超时字段(不设则保持 60 / 10 秒)。AgentScopeA2aServer 把它们传给 AgentScopeA2aRequestHandler.Builder 的新方法,Starter 再把这两个配置项接到 AgentExecuteProperties。
  • 线程池:AgentScopeA2aServer 在 build() 里、所有检查都通过之后才创建默认线程池,不再存进 builder,并在 close() 时 shutdownNow()。调用方通过 executor(...) 传入的执行器仍由调用方自己管理。
  • 文档:中英文 a2a.md 里 server.close() 的注释更新。

原 #3578 里「完成后再取消就拒绝(TaskNotCancelableError)」等语义变化,不在本 PR 范围内。

测试

  • AgentScopeAgentExecutorTest:新增 testCancelEndsExecution,流式和阻塞两种参数各一条。agent 一直在跑、stop() 也停不下它时,取消后执行线程要在 5 秒内结束,上游流要被取消。在 main 上确认先失败(执行线程没有结束),修复后通过。
  • A2aHttpEndToEndTest.interruptCancelsRemoteTask:去掉 @Disabled,通过。
  • AgentScopeA2aServerTest:close() 关掉自建的线程池;调用方传入的执行器不关;同一个 builder 两次 build() 各有各的线程池;失败后重试的 build() 拥有自己的线程池;配置的超时能传到请求处理器。
  • AgentScopeA2aRequestHandlerTest:默认超时 60 / 10 秒;配置值能生效。
  • AgentscopeA2aAutoConfigurationTest:Starter 的超时配置项能生效,应用上下文关闭时 server 也被关闭。
  • 把 AgentScopeA2aServer 换回 main 上的版本时,上面 server 的 5 条全部失败。其中超时那条是断言失败(期望 120,实际 60);线程池那 4 条是因为反射找不到新字段而报错。
  • 文档:node scripts/check-docs.mjs(432 个页面)和 node --test scripts/tests/*.test.mjs(13 条)通过;mint validate / broken-links 本机没跑。
  • 本地(JDK 17,macOS):mvn -B -T1C clean verify 99 个模块全部通过(12,096 个测试,0 失败,224 跳过)。补丁覆盖率:改动的可执行行 53/53,分支 10/10。

Follow-up to #3546, supersedes #3578

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn -B -T1C clean verify)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

Part of #3990

… the transport pool

- AgentScopeAgentExecutor ends a cancelled execution with a cancel
  signal applied by takeUntilOther, so blockLast() returns; cancelling
  only the upstream subscription left the execution thread blocked.
- The starter's agent-completion / consumption-completion timeouts reach
  the request handler through AgentExecuteProperties (default 60 / 10 s).
- AgentScopeA2aServer creates its default transport executor per build()
  and shuts it down on close(); an executor set by the caller is left
  alone.
- Re-enable A2aHttpEndToEndTest.interruptCancelsRemoteTask.

Supersedes agentscope-ai#3578.
@mintlify

mintlify Bot commented Nov 5, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit b191039.

Approve preview

@jujn
jujn merged commit 81b109c into agentscope-ai:main Nov 5, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants