Skip to content

Generic Temporal Nexus Operation Handler - #690

Merged
jmaeagle99 merged 10 commits into
temporalio:mainfrom
Quinn-With-Two-Ns:nexus-generic-handler
Jun 3, 2026
Merged

jmaeagle99 merged 10 commits into
temporalio:mainfrom
Quinn-With-Two-Ns:nexus-generic-handler

Conversation

@Quinn-With-Two-Ns

@Quinn-With-Two-Ns Quinn-With-Two-Ns commented May 13, 2026

Copy link
Copy Markdown
Contributor

What was changed

Added a generic Nexus operation handler that consolidates the common pattern of "either return a synchronous
result or start a workflow as an async operation."

Why?

The existing WorkflowRun / SyncOperation split forces users to pick the operation shape up front, which is awkward when:

  • The start handler decides at runtime whether to respond sync or async.
  • The handler needs access to the Temporal client.
  • The user wants a custom cancel implementation (e.g. terminate instead of cancel).
  • Difficult to extend as we add new operations

The new TemporalOperation unifies these cases behind one API and makes the common path much shorter.

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?

Note

Medium Risk
Changes experimental Nexus operation start/cancel and callback token wiring shared by old and new handlers; mistakes could break async completion or cancel the wrong workflow, though coverage is broad.

Overview
Adds a unified experimental Nexus API (TemporalOperationHandler.FromHandleFactory) so one handler can return either a sync result or an async workflow-run token, with ITemporalNexusClient / TemporalNexusClient for starting workflows and accessing TemporalClient for signals and similar work.

Shared workflow-start behavior (links, completion callbacks, Nexus-Operation-Token header with case-insensitive dedup, UseExisting conflict options, outbound links) moves into NexusWorkflowStartHelper; WorkflowRunOperationContext now delegates there instead of inlining that logic.

Operation tokens gain ParseToken, an OperationToken record, and a WorkflowRunOperationTokenType constant; cancel on the generic handler validates namespace and token type, then calls overridable CancelWorkflowRunAsync (default: cancel workflow by ID). Unit and worker integration tests cover tokens, sync/async paths, cancel, links, and conflict policy.

Reviewed by Cursor Bugbot for commit c354d2a. Bugbot is set up for automated code reviews on this repo. Configure here.

@Quinn-With-Two-Ns Quinn-With-Two-Ns changed the title Nexus generic handler Generic Temporal Nexus Operation Handler May 13, 2026
@Quinn-With-Two-Ns
Quinn-With-Two-Ns marked this pull request as ready for review May 13, 2026 23:46
@Quinn-With-Two-Ns
Quinn-With-Two-Ns requested a review from a team as a code owner May 13, 2026 23:46

@jmaeagle99 jmaeagle99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Still reviewing but wanted to leave my initial comments.

Comment thread src/Temporalio/Nexus/TemporalNexusOperationHandler.cs Outdated
Comment thread src/Temporalio/Nexus/NexusWorkflowStartHelper.cs
Comment thread src/Temporalio/Nexus/TemporalNexusClient.cs Outdated
Comment thread src/Temporalio/Nexus/TemporalNexusOperationHandler.cs Outdated
Comment thread src/Temporalio/Nexus/TemporalNexusClient.cs Outdated
Comment thread src/Temporalio/Nexus/TemporalOperationResult.cs Outdated
Comment thread src/Temporalio/Nexus/TemporalOperationResult.cs Outdated
Comment thread src/Temporalio/Nexus/TemporalOperationResult.cs Outdated
Comment thread src/Temporalio/Nexus/TemporalNexusOperationHandler.cs Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 9eb951c. Configure here.

Comment thread tests/Temporalio.Tests/Nexus/NexusWorkflowStartHelperTests.cs Outdated
Comment thread src/Temporalio/Nexus/NexusWorkflowStartHelper.cs Outdated
{
/// <summary>
/// Context used to create workflow run handles. This is passed to functions passed to
/// <c>FromHandleFactory</c> on <see cref="WorkflowRunOperationHandler"/>.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to guide customers to use TemporalNexusOperationHandler instead of WorkflowRunOperationHandler? Obsoleting would be a forcing function. If not that, maybe update the comments on WorkflowRunOperationHandler and related types to recommend using the new types.

Comment thread src/Temporalio/Nexus/NexusWorkflowStartHelper.cs Outdated
Comment thread tests/Temporalio.Tests/Worker/NexusWorkerTests.cs Outdated
Comment thread tests/Temporalio.Tests/Worker/NexusWorkerTests.cs Outdated
Comment thread tests/Temporalio.Tests/Worker/NexusWorkerTests.cs Outdated
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.

2 participants