Skip to content

fix(harness): acknowledge background task termination#2180

Open
guslegend0510 wants to merge 3 commits into
agentscope-ai:mainfrom
guslegend0510:fix/2162-task-cancellation-ack
Open

fix(harness): acknowledge background task termination#2180
guslegend0510 wants to merge 3 commits into
agentscope-ai:mainfrom
guslegend0510:fix/2162-task-cancellation-ack

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

Summary

Fixes #2162.

Background task cancellation previously updated the persisted task state to
CANCELLED without providing authoritative acknowledgement that the underlying
local or remote execution had actually stopped.

This change introduces a typed cancellation contract that separates cancellation
request state from execution termination state.

Changes

  • Add TaskCancellation with typed:
    • cancellation request status;
    • execution identity and execution kind;
    • termination status;
    • asynchronous termination signal;
    • caller-bounded awaitTermination(Duration) API.
  • Preserve compatibility with the existing boolean TaskRepository.cancelTask(...)
    API.
  • Track local execution lifecycle separately from CompletableFuture cancellation.
  • Confirm local termination only after the supplier execution actually exits.
  • Interrupt local execution cooperatively without treating interruption delivery as
    stop acknowledgement.
  • Report adopted executions as detached when the repository cannot observe their
    underlying execution.
  • Propagate remote cancellation failures through the typed termination result.
  • Poll remote task status after the cancel request and acknowledge termination only
    after the remote protocol reports a terminal state.
  • Make repeated cancellation requests idempotent and reuse the same termination
    signal.
  • Update task_cancel output to distinguish request status from stop status.

Behavior

TaskStatus.CANCELLED continues to represent the durable repository state and
cancellation intent.

It no longer implies that the child execution has stopped. Callers that need to
perform workspace cleanup or parent shutdown can wait for the termination signal
with their own timeout.

Java does not provide a safe forced thread-stop mechanism. A local supplier that
ignores interruption therefore returns TIMED_OUT to bounded waiters until the
supplier actually exits.

Tests

Added coverage for:

  • a local supplier that continues after interruption;
  • cooperative local execution termination;
  • caller-provided termination timeout;
  • idempotent repeated cancellation;
  • missing tasks;
  • adopted/detached execution;
  • remote cancellation confirmation;
  • authoritative remote cancellation failure.

Validation completed successfully:

mvn -pl agentscope-harness -am test
mvn -pl agentscope-harness spotless:check

Branch: fix/2162-task-cancellation-ack
Commit: 5764d98

@guslegend0510 guslegend0510 requested a review from a team July 13, 2026 13:43
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.08163% with 88 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...s/agent/subagent/task/WorkspaceTaskRepository.java 51.12% 61 Missing and 26 partials ⚠️
.../harness/agent/subagent/task/TaskCancellation.java 97.95% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/harness agentscope-harness (test/runtime support) labels Jul 14, 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

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Background task cancellation lacks execution-stop acknowledgement

2 participants