Skip to content

fix(harness): cancel spawned agent on parent dispose - #2063

Closed
mroldx wants to merge 1 commit into
agentscope-ai:mainfrom
mroldx:agent-cancel
Closed

mroldx wants to merge 1 commit into
agentscope-ai:mainfrom
mroldx:agent-cancel

Conversation

@mroldx

@mroldx mroldx commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.0-RC5

Description

This PR fixes #2062.

AgentSpawnTool.execWithTimeoutPromotion() starts local sub-agent execution with an inner Reactor subscription. Previously, when the parent agent_spawn subscription was cancelled, the inner subscription was not disposed. As a result, the spawned local sub-agent could continue running after the parent no longer observed the result.

This change propagates parent cancellation to the in-flight local sub-agent execution by:

  • capturing the inner Disposable
  • disposing it from sink.onCancel(...)
  • interrupting local ReActAgent instances when the inner execution receives SignalType.CANCEL
  • avoiding post-cancel bridge callbacks from writing back to an already-cancelled sink

This only affects parent subscription cancellation. It does not change the normal async/background task path (timeout_seconds=0) or timeout promotion behavior where a task_id is returned.

Tests added:

  • AgentSpawnToolCancellationTest
    • verifies that cancelling agent_spawn cancels the in-flight local sub-agent Mono
    • verifies that ReActAgent.interrupt(RuntimeContext) is called

Tested with:

mvn -pl agentscope-harness test -Dtest=AgentSpawnToolCancellationTest -DfailIfNoTests=false
mvn -pl agentscope-harness test

@mroldx
mroldx requested a review from a team July 8, 2026 15:43
@CLAassistant

CLAassistant commented Jul 8, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../agentscope/harness/agent/tool/AgentSpawnTool.java 90.00% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@chickenlj

Copy link
Copy Markdown
Collaborator

Duplicate of #2064.

@chickenlj chickenlj closed this Jul 9, 2026
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.

[Bug]:AgentSpawnTool leaks orphan ReActAgent on parent subscription cancel

3 participants