Skip to content

Proactively cancel activities on workflow close (termination, timeout, etc)#10047

Open
rkannan82 wants to merge 15 commits into
mainfrom
kannan/cancel-activity-on-terminate
Open

Proactively cancel activities on workflow close (termination, timeout, etc)#10047
rkannan82 wants to merge 15 commits into
mainfrom
kannan/cancel-activity-on-terminate

Conversation

@rkannan82
Copy link
Copy Markdown
Contributor

@rkannan82 rkannan82 commented Apr 24, 2026

What

On workflow close, dispatch cancel-commands to workers for in-flight activities. Extends the mechanism from #9233 to cover all workflow close paths.

Cancel command generation lives in GenerateWorkflowCloseTasks, which is called from every close path (complete, fail, timeout, cancel, terminate, continue-as-new). Guarded by EnableCancelActivityWorkerCommand (disabled).

Why

Previously, workers only discovered workflow termination/timeout passively via heartbeat (NOT_FOUND) or when completing the activity. If heartbeat isn't enabled, activities run to completion uselessly.

How did you test it?

  • Unit tests covering filtering logic (control queue, started clock, feature flag) and multi-queue batching.
  • E2E tests for terminate, reset, CaN.

@rkannan82 rkannan82 force-pushed the kannan/cancel-activity-on-terminate branch from 3f50b28 to 2802499 Compare May 4, 2026 18:23
When a workflow is terminated or times out, dispatch cancel commands to
workers for in-flight activities that registered a control queue. Extends
the mechanism from #9233 to cover forceful workflow close scenarios
(including reset, which terminates the old run).

Guarded by EnableCancelActivityWorkerCommand. Disabled by default.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rkannan82 rkannan82 force-pushed the kannan/cancel-activity-on-terminate branch from 2802499 to 69daa0c Compare May 4, 2026 18:25
@rkannan82 rkannan82 requested a review from yycptt May 4, 2026 18:25
@rkannan82 rkannan82 marked this pull request as ready for review May 4, 2026 18:25
@rkannan82 rkannan82 requested review from a team as code owners May 4, 2026 18:25
rkannan82 and others added 3 commits May 4, 2026 11:29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread service/history/workflow/mutable_state_impl.go
Comment thread service/history/workflow/mutable_state_impl.go Outdated
rkannan82 and others added 5 commits May 12, 2026 14:31
Cancel commands for in-flight activities are now generated from
GenerateWorkflowCloseTasks instead of being called explicitly from
TerminateWorkflow and TimeoutWorkflow. This covers all workflow close
paths (complete, fail, timeout, cancel, terminate, continue-as-new)
with a single call site.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rkannan82 rkannan82 changed the title Proactively cancel activities on workflow termination and timeout Proactively cancel activities on workflow close (termination, timeout, etc) May 12, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rkannan82 rkannan82 requested a review from yycptt May 12, 2026 21:42
rkannan82 and others added 5 commits May 12, 2026 14:57
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cancel commands are best-effort and only dispatched on the active
cluster. Avoid creating tasks on standby that will be immediately
dropped by the outbound executor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment on lines +4549 to +4550
activeCluster := ms.clusterMetadata.ClusterNameForFailoverVersion(
ms.namespaceEntry.IsGlobalNamespace(), ms.GetCurrentVersion())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cc @michaely520 will this work in MCN world?

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.

2 participants