Repository navigation
Add activation batching flag with task-local cancellation - #2149
Draft
VegetarianOrc wants to merge 19 commits into
Draft
VegetarianOrc wants to merge 19 commits into
VegetarianOrc wants to merge 19 commits into
Conversation
VegetarianOrc
force-pushed
the
amazzeo/workflow-wait-condition-cancellation
branch
2 times, most recently
from
November 21, 2026 01:27
0c16a66 to
38e9237
Compare
VegetarianOrc
force-pushed
the
amazzeo/workflow-wait-condition-cancellation
branch
from
November 30, 2026 23:05
f7c9ba8 to
a2912e0
Compare
VegetarianOrc
changed the base branch from
amazzeo/workflow-activation-batch-only
to
main
December 1, 2026 00:14
This was referenced Dec 2, 2026
Flag 4 now applies all activation jobs before it runs workflow tasks, and sends cancellation only to the task that receives it. Remove flag 5. Batching alone changes which result wins when a cancellation arrives in the same workflow task, so one flag controls both behaviors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
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>
List the flag 4 effects that users can see but the fragment left out: external and child signals, handle cancel after a result, all_handlers_finished(), job failures during apply, Python 3.11 timeout rounding, and handler waits after cancellation. Also add a reminder to name the minimum replay version when flag 4 becomes a default. Refs SDK-605. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Address review findings on the flag 4 fragment: - Split the first entry into three entries. - Name the exact call or handler that each entry affects. - Add update handlers to the job failure entry. - Name asyncio.CancelledError. - Follow the existing flag reminder form in the TODO. Refs SDK-605. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The worker checked flag 2 before flag 4. A worker with flag 2 as a default then recorded flag 2 on a run whose history holds flag 4, and the run changed to flag 2 behavior. Check flag 4 first when history does not hold flag 2, and check flag 2 last. A new run on a worker with both flags as defaults now records flag 4. Refs SDK-606. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Address review findings on the flag precedence tests: - Start the handler wait on the second worker, so the result shows which flag the run uses. - Compare the full set of recorded flags. - Set both flags explicitly on each worker. - Remove cases that run the same code path. Refs SDK-606. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add tests that run with no flag, flag 2 and flag 4: - A Nexus operation result and a workflow cancellation in one activation. - An external signal and a workflow cancellation in one activation. - A signal handler wait after workflow cancellation on one worker. Also run the test for a flag first enabled on a later task with flag 4. The child start test now ends its hold when the cancellation arrives, so a regression fails instead of hanging. Refs SDK-607. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Address review findings on the new flag 4 tests: - Give each outcome different commands, so replay detects a wrong flag decision. - Use a condition and timeout race in the later task test, so the result shows that the flag takes effect there. - Compare only the two batching flags in recorded flag sets. - Name the Nexus helpers and handler workflow for their role. Refs SDK-607. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VegetarianOrc
force-pushed
the
amazzeo/workflow-wait-condition-cancellation
branch
from
December 3, 2026 00:22
9925e45 to
05dd78e
Compare
This branch has not been deployed
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
Add the internal workflow logic flag
APPLY_ACTIVATION_JOBS_BEFORE_RUNNING_TASKS(4). The flag is off by default. When the flag is on, the worker does these things:PROCESS_WORKFLOW_ACTIVATION_JOBS_AS_SINGLE_BATCH) does.workflow.wait_conditionawaits its future directly insideasyncio.timeout, so a shielded wait can finish after the workflow is cancelled.Histories that record flag 2 keep their current behavior. The worker does not check or record flag 4 for them. Otherwise the worker checks flag 4 before flag 2. A run whose history holds flag 4 never records flag 2. A new run on a worker with both flags as defaults records flag 4.
In
_WorkflowInstanceImpl, the flag attributes are now_single_batch_flag(flag 2) and_apply_jobs_first_flag(flag 4). Start awaits pass the newis_startparameter to_await_temporal_operation. A new helper,_cancellation_wins_over_result, decides whether a cancellation wins over a result that is ready.The changelog fragment
changelog/added/tumbling-job-basket.mdlists the effects of flag 4 that users can see. The flag 4 comment intemporalio/_workflow_context.pyhas a reminder for the release that enables flag 4 by default. That release must name the minimum SDK version that replays flag 4 histories.This PR replaces #2148. It includes the task-local
wait_conditionapproach from #2124, and it includes #2192, #2193, #2194 and #2195.Why?
Flag 2 checks for cancellation across the whole workflow. After the workflow is cancelled, that check also cancels waits that
asyncio.shieldprotects (#2116). Histories that 1.36.0 recorded with flag 2 need that behavior to replay, so the fix needs a new flag.Batching alone changes which result wins when a cancellation and a result arrive in the same workflow task. With separate flags, a worker could use batching without the task-local cancellation handling. One flag prevents that combination.
Without the cancel request on a start, a child or Nexus operation that started with the cancellation kept running. With the default
TERMINATEparent close policy, the child was terminated when the parent closed, not cancelled, so its cleanup code did not run.An older SDK can replay a flag 4 history with different results and no nondeterminism error. The release that enables flag 4 must therefore name the minimum SDK version.
Before the flag order changed, a worker with flag 2 as a default recorded flag 2 on a run whose history held flag 4. The run then changed to flag 2 behavior. Only the private test hook can make flag 2 a default today, so that change is defensive.
Checklist
Closes: N/A. Refs [Feature Request] Public worker option to keep the legacy activation order (workflow logic flag 2) #2116, SDK-456, SDK-604, SDK-605, SDK-606 and SDK-607.
How was this tested:
test_workflow_cancel_and_child_start_in_same_activationruns with no flag, flag 2 and flag 4. A fourth case uses flag 4 with the child terminated in the same workflow task.test_workflow_cancel_and_operation_start_in_same_activation(tests/nexus/test_workflow_caller_cancel_in_same_activation.py) runs with no flag, flag 2 and flag 4. Without the start fix, the flag 4 cases fail.test_workflow_cancel_and_operation_completion_in_same_activationandtest_workflow_cancel_and_external_signal_in_same_activationput a Nexus operation completion or an external signal result in the same workflow task as the cancellation.test_workflow_handler_wait_condition_after_cancelchecks that a signal handler wait can finish after cancellation under flag 4 and not under flag 2. Two of its cases change the worker defaults after the first task.test_workflow_logic_flag_enabled_after_replayruns for flag 2 and flag 4. Its result shows that a flag first enabled on a later task takes effect on that task.main, on Python 3.13.7:test_workflow.py,test_replayer.py,test_workflow_flags.pyandtests/nexus/: 707 passed, 2 skipped.poe testsuite passed, with 2,028 passed and 10 skipped.poe lintpassed.changelog-tool checkpassed.Any docs updates needed? No public API docs need updating. The changelog fragment describes the flag and the behavior changes.
Known issue, not in this PR: without any flag, the SDK can send a cancel for a child that terminated in the same workflow task. Core then fails every workflow task with a nondeterminism error. Core's child state machine has no
Canceltransition fromTerminated.🤖 Generated with Claude Code