Skip to content

fix(core): stream 取消时释放上游订阅#1615

Closed
guslegend0510 wants to merge 7 commits into
agentscope-ai:mainfrom
guslegend0510:fix/issue-1466-main
Closed

fix(core): stream 取消时释放上游订阅#1615
guslegend0510 wants to merge 7 commits into
agentscope-ai:mainfrom
guslegend0510:fix/issue-1466-main

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

变更说明

修复 AgentBasestream() 被下游取消时没有释放上游订阅的问题。
之前下游 Flux 取消后,上游 Mono 仍可能继续运行,导致执行资源无法及时释放,出现“鬼任务”或后续调用被阻塞的情况。

本次改动包括:

  • AgentBase#createEventStream 中将上游订阅绑定到 sink.onDispose(...)
  • 取消流时及时 dispose 上游订阅
  • 保持原有的流式输出行为不变
  • 补充 AgentBaseTest,覆盖“取消流后释放执行锁、后续可继续调用”的场景

另外,顺带修复了 ToolCallParam copy builder 的一个既有编译问题,保证当前分支可正常编译和测试。

验证

  • mvn -B -pl agentscope-core -am spotless:check
  • mvn -B -pl agentscope-core -am "-Dtest=AgentBaseTest,ToolCallParamTest" -DfailIfNoTests=false test
  • mvn -B -T1 clean verify
    其中失败点来自仓库里已有的外部依赖/环境相关测试,不是本次改动引入的

@guslegend0510 guslegend0510 requested a review from a team June 4, 2026 23:13
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan labels Jun 5, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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

Copy link
Copy Markdown
Member
image

@guslegend0510

Copy link
Copy Markdown
Contributor Author

@LearningGp 我已经解决了这个冲突,麻烦再审查一下,谢谢

@chickenlj

Copy link
Copy Markdown
Collaborator

Thanks. Please check #1796

@chickenlj chickenlj closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/agent Agent runtime, pipeline, hooks, plan bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants