fix(core): stream 取消时释放上游订阅#1615
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR correctly fixes the stream cancellation resource leak in AgentBase.createEventStream. Before this change, when a downstream subscriber cancelled the Flux returned by stream(), the upstream Mono subscription was orphaned — the execution lock was never released, blocking all subsequent agent calls. The fix uses Reactor's Disposable.Swap + sink.onDispose(...) to bind the upstream subscription lifetime to the downstream sink. The implementation is idiomatic Reactor. The test is well-designed using StepVerifier.thenCancel(). The secondary ToolCallParam copy-builder fix is a genuine compilation bugfix.
|
@LearningGp 我已经解决了这个冲突,麻烦再审查一下,谢谢 |
|
Thanks. Please check #1796 |

变更说明
修复
AgentBase在stream()被下游取消时没有释放上游订阅的问题。之前下游
Flux取消后,上游Mono仍可能继续运行,导致执行资源无法及时释放,出现“鬼任务”或后续调用被阻塞的情况。本次改动包括:
AgentBase#createEventStream中将上游订阅绑定到sink.onDispose(...)dispose上游订阅AgentBaseTest,覆盖“取消流后释放执行锁、后续可继续调用”的场景另外,顺带修复了
ToolCallParamcopy builder 的一个既有编译问题,保证当前分支可正常编译和测试。验证
mvn -B -pl agentscope-core -am spotless:checkmvn -B -pl agentscope-core -am "-Dtest=AgentBaseTest,ToolCallParamTest" -DfailIfNoTests=false testmvn -B -T1 clean verify其中失败点来自仓库里已有的外部依赖/环境相关测试,不是本次改动引入的