Repository navigation
fix(a2a): end cancelled executions, apply blocking timeouts and close the transport pool - #3993
Merged
jujn merged 2 commits intoNov 5, 2026
Conversation
… 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.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
jujn
approved these changes
Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
2.1.0-SNAPSHOT (main)
Description
接替已关闭的 #3578,基于 A2A 1.0(#3590 合入后)的 main 重做,只保留下面三处修复。
问题
AgentScopeAgentExecutor.cancel()取消的是doOnSubscribe拿到的上游订阅。上游停了,下游却收不到任何结束信号,blockLast()也没有超时,于是执行线程一直卡着,doFinally也不会运行。每取消一个流式任务(或returnImmediately=true的任务)就漏一个线程。A2aHttpEndToEndTest.interruptCancelsRemoteTask正是因为这个原因被@Disabled。agentscope.a2a.server下的agent-completion-timeout-seconds、consumption-completion-timeout-seconds能绑定,但没有任何代码读取;AgentScopeA2aRequestHandler里写死了 60 / 10 秒。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本机没跑。mvn -B -T1C clean verify99 个模块全部通过(12,096 个测试,0 失败,224 跳过)。补丁覆盖率:改动的可执行行 53/53,分支 10/10。Follow-up to #3546, supersedes #3578
Checklist
mvn spotless:applymvn -B -T1C clean verify)Part of #3990