Skip to content

Cancel a started child or Nexus operation on start cancellation with flag 4 - #2192

Merged
VegetarianOrc merged 4 commits into
amazzeo/workflow-wait-condition-cancellationfrom
alexmazzeo/sdk-604-flag-4-send-a-cancel-request-to-a-child
Dec 3, 2026
Merged

VegetarianOrc merged 4 commits into
amazzeo/workflow-wait-condition-cancellationfrom
alexmazzeo/sdk-604-flag-4-send-a-cancel-request-to-a-child

Conversation

@VegetarianOrc

@VegetarianOrc VegetarianOrc commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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 gets CancelledError and no handle. The SDK now sends cancel_child_workflow_execution or request_cancel_nexus_operation before 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 TERMINATE parent close policy, the child was terminated, not cancelled, so its cleanup code did not run.

Checklist

  1. Refs SDK-604. Stacked on Add activation batching flag with task-local cancellation #2149.

  2. 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 file tests/nexus/test_workflow_caller_cancel_in_same_activation.py): no flag, flag 2, flag 4. Without the fix, the flag 4 case fails.
    • The new tests pass on the local dev server and on time-skipping V2. poe lint passed.
  3. 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 Cancel transition from Terminated.

🤖 Generated with Claude Code

VegetarianOrc and others added 2 commits December 2, 2026 11:57
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>
@VegetarianOrc
VegetarianOrc added this pull request to stack #2196 December 2, 2026 23:39
@VegetarianOrc VegetarianOrc changed the title alexmazzeo/sdk 604 flag 4 send a cancel request to a child Cancel a started child or Nexus operation on start cancellation with flag 4 Dec 2, 2026
VegetarianOrc and others added 2 commits December 2, 2026 16:10
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
VegetarianOrc merged commit 9925e45 into main Dec 3, 2026
18 of 19 checks passed
@VegetarianOrc
VegetarianOrc deleted the alexmazzeo/sdk-604-flag-4-send-a-cancel-request-to-a-child branch December 3, 2026 00:17
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.

1 participant