Skip to content

Prevent workflow stream subscriptions from hiding cancellation - #1805

Open
1fanwang wants to merge 2 commits into
temporalio:mainfrom
1fanwang:1fannnw/workflow-stream-cancellation
Open

Prevent workflow stream subscriptions from hiding cancellation#1805
1fanwang wants to merge 2 commits into
temporalio:mainfrom
1fanwang:1fannnw/workflow-stream-cancellation

Conversation

@1fanwang

@1fanwang 1fanwang commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

When an activity blocks in WorkflowStreamClient.subscribe and its workflow
cancels it, the subscription currently ends like a normal iterator. The activity
can then return success even though Temporal requested cancellation. This change
propagates the cancellation to the activity.

The subscription now rethrows direct task cancellation and cancellation wrapped
by WorkflowUpdateRPCTimeoutOrCancelledError. RPC timeouts and server-side RPC
cancellation keep their existing continue-as-new and terminal-workflow handling.

Testing

The regression test starts a real Temporal dev server, waits until a heartbeating
activity is polling a workflow stream, and then cancels that activity. The
activity catches CancelledError directly around the subscription and returns a
distinct sentinel, so an error added later by the activity runtime cannot satisfy
the assertion.

Before
$ git checkout upstream/main -- temporalio/contrib/workflow_streams/_client.py
$ uv run pytest tests/contrib/workflow_streams/test_workflow_streams.py::test_activity_subscription_propagates_cancellation -q --no-header
E           AssertionError: assert 'subscription-ended' == 'subscription-cancelled'
Results (3.30s):
         1 failed
After
$ git checkout HEAD -- temporalio/contrib/workflow_streams/_client.py
$ uv run pytest tests/contrib/workflow_streams/test_workflow_streams.py::test_activity_subscription_propagates_cancellation -q --no-header
.                                                                        [100%]
Results (2.95s):
         1 passed

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang requested review from a team as code owners September 2, 2026 07:58
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