Skip to content

Conversation

dandavison
Copy link
Contributor

@dandavison dandavison commented Aug 13, 2025

Fixes #911

Handle new events NexusOperationCancelRequestCompleted and NexusOperationCancelRequestFailed.

These events are written by the caller server when it receives the result of the nexus op cancel request. The only cancellation type that is sensitive to these is WaitRequested. From lang's point of view, under WaitRequested, those events cause the nexus operation handle future to be resolved as cancelled / failed respectively. Thus lang can choose to see the cancellation when the cancel handler has successfully returned, but prior to any cancellation of the operation itself. In the case of cancel handler failure, that failure will be thrown out of the operation handle future and the user will not be able to use the handle to access any terminal state that the operation might reach.

Also modifies the fsm! macro to allow the same union type to be constructed twice, since Started -> Started|Cancelled is now caused by two different inputs.

The real test coverage for this PR is coming in temporalio/sdk-python#981 [Draft].

Before
image
After
image

@dandavison dandavison force-pushed the dan-9999-python-nexus-cancellation-types branch 3 times, most recently from 9c84979 to a08a316 Compare August 15, 2025 22:53
@dandavison dandavison marked this pull request as ready for review August 15, 2025 22:53
@dandavison dandavison requested a review from a team as a code owner August 15, 2025 22:53
@dandavison dandavison changed the title Nexus cancellation types: NexusOperationCancelRequestCompleted & WAIT_REQUESTED Nexus cancellation types: handle NexusOperationCancelRequestCompleted, NexusOperationCancelRequestFailed Aug 15, 2025
TimedOut --(NexusOperationCancelRequestCompleted(NexusOperationCancelRequestCompletedEventAttributes))--> TimedOut;
Completed --(NexusOperationCancelRequestFailed(NexusOperationCancelRequestFailedEventAttributes))--> Completed;
Failed --(NexusOperationCancelRequestFailed(NexusOperationCancelRequestFailedEventAttributes))--> Failed;
TimedOut --(NexusOperationCancelRequestFailed(NexusOperationCancelRequestFailedEventAttributes))--> TimedOut;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[I haven't yet proved that I can make these transitions happen in tests.]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine. Some of these "if it happens just ignore" transitions can be like that.

Copy link
Member

@Sushisource Sushisource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, though may want a more explicit test or two.

TimedOut --(NexusOperationCancelRequestCompleted(NexusOperationCancelRequestCompletedEventAttributes))--> TimedOut;
Completed --(NexusOperationCancelRequestFailed(NexusOperationCancelRequestFailedEventAttributes))--> Completed;
Failed --(NexusOperationCancelRequestFailed(NexusOperationCancelRequestFailedEventAttributes))--> Failed;
TimedOut --(NexusOperationCancelRequestFailed(NexusOperationCancelRequestFailedEventAttributes))--> TimedOut;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine. Some of these "if it happens just ignore" transitions can be like that.

These events are written by the caller server on receiving a response
from the nexus cancel handler. The only cancellation type that is
sensitive to them is WaitRequested: when that is in effect, these
events cause an activation job to be emitted that resolves the nexus
operation future.

The fsm macro is modified to allow the same union type to be
constructed twice, since Started -> Started|Cancelled is now caused by
two different inputs.
@dandavison dandavison force-pushed the dan-9999-python-nexus-cancellation-types branch 3 times, most recently from 580864c to 90791f3 Compare August 20, 2025 18:08
@dandavison dandavison force-pushed the dan-9999-python-nexus-cancellation-types branch from 90791f3 to c98db3a Compare August 20, 2025 18:10
@dandavison dandavison merged commit 199880d into master Aug 20, 2025
30 of 32 checks passed
@dandavison dandavison deleted the dan-9999-python-nexus-cancellation-types branch August 20, 2025 19:08
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.

[Feature Request] Support Nexus operation cancellation types

2 participants