Skip to content

Making raise on cancellation the default #935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions temporalio/worker/_workflow_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1620,16 +1620,14 @@ async def run_activity() -> Any:
# If an activity future completes at the same time as a cancellation is being processed, the cancellation would be swallowed
# _WorkflowLogicFlag.RAISE_ON_CANCELLING_COMPLETED_ACTIVITY will correctly reraise the exception
if handle._result_fut.done():
# TODO in next release, check sdk flag when not replaying instead of global override, remove the override, and set flag use
if (
(
not self._is_replaying
and _raise_on_cancelling_completed_activity_override
)
not self._is_replaying
or _WorkflowLogicFlag.RAISE_ON_CANCELLING_COMPLETED_ACTIVITY
in self._current_internal_flags
):
# self._current_completion.successful.used_internal_flags.append(WorkflowLogicFlag.RAISE_ON_CANCELLING_COMPLETED_ACTIVITY)
self._current_completion.successful.used_internal_flags.append(
_WorkflowLogicFlag.RAISE_ON_CANCELLING_COMPLETED_ACTIVITY
)
raise
# Send a cancel request to the activity
handle._apply_cancel_command(self._add_command())
Expand Down Expand Up @@ -3138,7 +3136,3 @@ class _WorkflowLogicFlag(IntEnum):
"""Flags that may be set on task/activation completion to differentiate new from old workflow behavior."""

RAISE_ON_CANCELLING_COMPLETED_ACTIVITY = 1


# Used by tests to validate behavior prior to SDK flag becoming default
_raise_on_cancelling_completed_activity_override = False
4 changes: 0 additions & 4 deletions tests/worker/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8005,8 +8005,6 @@ async def test_quick_activity_swallows_cancellation(client: Client):
activities=[short_activity_async],
activity_executor=concurrent.futures.ThreadPoolExecutor(max_workers=1),
) as worker:
temporalio.worker._workflow_instance._raise_on_cancelling_completed_activity_override = True

for i in range(10):
wf_duration = random.uniform(5.0, 15.0)
wf_handle = await client.start_workflow(
Expand All @@ -8028,8 +8026,6 @@ async def test_quick_activity_swallows_cancellation(client: Client):
assert isinstance(cause, CancelledError)
assert cause.message == "Workflow cancelled"

temporalio.worker._workflow_instance._raise_on_cancelling_completed_activity_override = False


async def test_workflow_logging_trace_identifier(client: Client):
with LogCapturer().logs_captured(
Expand Down