Repository navigation
Cancel a started child or Nexus operation on start cancellation with flag 4 - #2192
Merged
Conversation
With flag 4, a start that resolves in the same activation as a cancellation raises CancelledError. The caller gets no handle, so the SDK now sends the cancel request to the child or operation before it raises. Flag 2 behavior does not change. Refs SDK-604. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With flag 4, the start cancel path can run after the child result resolved in the same activation. Core fails the task on a cancel for a terminated child, so skip the cancel when the result is known. Also address review findings in the start cancellation tests: - Use one worker for the child test, with a short task timeout. - Add a case where the child terminates in the same activation. - Skip the child test on the Java test server. - Run the Nexus test on time-skipping V2, and reuse WaitForCancelWorkflow. Refs SDK-604. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Dec 2, 2026
Name the flag 2 and flag 4 attributes after their flags, and name the start parameter after what the caller awaits. Move the decision that a cancellation wins over a resolved operation into its own helper, so _await_temporal_operation has one branch for resolved operations. Refs SDK-604. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs SDK-604. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VegetarianOrc
deleted the
alexmazzeo/sdk-604-flag-4-send-a-cancel-request-to-a-child
branch
December 3, 2026 00:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was changed
With workflow logic flag 4 (
APPLY_ACTIVATION_JOBS_BEFORE_RUNNING_TASKS), a child workflow start or a Nexus operation start can resolve in the same activation as a workflow cancellation. The caller then getsCancelledErrorand no handle. The SDK now sendscancel_child_workflow_executionorrequest_cancel_nexus_operationbefore it raises, as it does without a flag.If the child result resolved in the same activation, the SDK sends no cancel. Core fails the workflow task on a cancel for a terminated child.
Flag 2 behavior does not change. The no-flag path does not change.
Why?
Before this change, flag 4 raised without a cancel request. The child or operation kept running, and the caller had no handle to cancel it. With the default
TERMINATEparent close policy, the child was terminated, not cancelled, so its cleanup code did not run.Checklist
Refs SDK-604. Stacked on Add activation batching flag with task-local cancellation #2149.
How was this tested:
test_workflow_cancel_and_child_start_in_same_activation: no flag, flag 2, flag 4, and flag 4 with the child terminated in the same activation. Without the fix, the flag 4 case fails. Without the resolved-child check, the terminated case fails with a nondeterminism error.test_workflow_cancel_and_operation_start_in_same_activation(new filetests/nexus/test_workflow_caller_cancel_in_same_activation.py): no flag, flag 2, flag 4. Without the fix, the flag 4 case fails.poe lintpassed.Any docs updates needed? No. Flag 4 now acts as the default does for this case.
Known issue, not in this PR: without any flag, a cancel for a child that terminated in the same activation fails every workflow task with a nondeterminism error. Core's child state machine has no
Canceltransition fromTerminated.🤖 Generated with Claude Code