Skip to content

Add Temporal Nexus Operation Handler - #2842

Merged
Quinn-With-Two-Ns merged 13 commits into
temporalio:masterfrom
Quinn-With-Two-Ns:temporal-nexus-operation-handler
Jun 11, 2026
Merged

Add Temporal Nexus Operation Handler#2842
Quinn-With-Two-Ns merged 13 commits into
temporalio:masterfrom
Quinn-With-Two-Ns:temporal-nexus-operation-handler

Conversation

@Quinn-With-Two-Ns

@Quinn-With-Two-Ns Quinn-With-Two-Ns commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Add TemporalOperationHandler for generic Nexus operations

Goal

Provide a new base to make it easy to expose more Temporal actions as Nexus Operations

Summary

  • Adds TemporalOperationHandler, a generic OperationHandler implementation that maps Nexus operations to Temporal workflows via a composable StartFunction
  • Adds TemporalNexusClient for starting workflows (typed and untyped) from within Nexus operation handlers
  • Supports subclassing TemporalOperationHandler to customize cancel behavior by overriding cancelWorkflowRun
  • Extracts shared workflow start logic into NexusStartWorkflowHelper, reused by both WorkflowRunOperation and the new handler

Test plan

  • GenericHandlerTypedStartWorkflowTest — typed workflow with return value
  • GenericHandlerTypedProcTest — typed void workflow
  • GenericHandlerUntypedStartWorkflowTest — untyped workflow start
  • GenericHandlerSyncResultTest — synchronous result path
  • GenericHandlerCancelTest — cancel with default and custom behavior

Note

Medium Risk
Touches Nexus operation start/cancel and workflow lifecycle from handlers; behavior changes are mostly additive behind experimental APIs, but refactors WorkflowRunOperationImpl and token parsing used on cancel paths.

Overview
Adds TemporalOperationHandler, a composable Nexus OperationHandler that wires a user-defined start lambda to Temporal via TemporalNexusClient (typed/untyped startWorkflow overloads) and TemporalOperationResult (sync vs async operation token). Cancel paths parse tokens with a generalized OperationToken / loadOperationToken, dispatch workflow-run cancels through overridable cancelWorkflowRun, and default behavior cancels the backing workflow.

Shared “start workflow + attach Nexus links” logic moves into NexusStartWorkflowHelper, which WorkflowRunOperationImpl now uses instead of inlined code. TemporalNexusClientImpl enforces one async start per handler invocation (extra starts fail with BAD_REQUEST; the guard resets if start fails).

All new public Nexus APIs are marked @Experimental. Integration tests cover typed/untyped starts, void workflows, sync results, cancel, and double-start rejection.

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

@Quinn-With-Two-Ns
Quinn-With-Two-Ns marked this pull request as ready for review April 14, 2026 22:33
@Quinn-With-Two-Ns
Quinn-With-Two-Ns requested a review from a team as a code owner April 14, 2026 22:33
@Quinn-With-Two-Ns
Quinn-With-Two-Ns force-pushed the temporal-nexus-operation-handler branch from a33ff01 to 7e61dab Compare May 8, 2026 14:14
Comment thread temporal-sdk/src/main/java/io/temporal/nexus/TemporalNexusClientImpl.java Outdated
@Quinn-With-Two-Ns
Quinn-With-Two-Ns force-pushed the temporal-nexus-operation-handler branch from 7e61dab to f2c65fc Compare May 15, 2026 23:04
Comment thread temporal-sdk/src/main/java/io/temporal/nexus/TemporalNexusClientImpl.java Outdated
@bergundy
bergundy removed their request for review May 20, 2026 19:14

@VegetarianOrc VegetarianOrc 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.

Looks great. Couple small questions mostly for my learning!

Comment on lines 34 to +35
if (Strings.isNullOrEmpty(token.getWorkflowId())) {
throw new IllegalArgumentException("Invalid workflow run token: missing workflow ID (wid)");
throw new IllegalArgumentException("Invalid operation token: missing workflow ID (wid)");

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.

Should this check be moved into loadWorkflowRunOperationToken?

Comment on lines +63 to +81
/**
* Returns the synchronous result value, or null if this is an async result.
*
* @return the sync result value, or null
*/
@Nullable
public R getSyncResult() {
return syncResult;
}

/**
* Returns the async operation token, or null if this is a sync result.
*
* @return the operation token, or null
*/
@Nullable
public String getAsyncOperationToken() {
return asyncOperationToken;
}

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.

Just a style question to familiarize myself with Java a bit more: Should these throw if invoked on the wrong type of result? i.e. should getAsyncOperationToken throw if isSync == true?

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.

Agreed, it would be more idiomatic to check and throw. We can then remove @Nullable annotations from the methods too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!


public WorkflowRunOperationToken(String namespace, String workflowId) {
this.type = OperationTokenType.WORKFLOW_RUN;
public OperationToken(OperationTokenType type, String namespace, String workflowId) {

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.

With more types of tokens upcoming, should we favor something like static constructors for this like OperationToken.NewWorkflowRunToken() that takes the required fields for the workflow run type?

I guess this is a bit like what OperationTokenUtil provides so feel free to dismiss this!

@maciejdudko maciejdudko 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.

Looks good, only a few small changes needed.

Comment thread temporal-sdk/src/main/java/io/temporal/nexus/TemporalOperationHandler.java Outdated
Comment on lines +63 to +81
/**
* Returns the synchronous result value, or null if this is an async result.
*
* @return the sync result value, or null
*/
@Nullable
public R getSyncResult() {
return syncResult;
}

/**
* Returns the async operation token, or null if this is a sync result.
*
* @return the operation token, or null
*/
@Nullable
public String getAsyncOperationToken() {
return asyncOperationToken;
}

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.

Agreed, it would be more idiomatic to check and throw. We can then remove @Nullable annotations from the methods too.

@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 10a94e4. Configure here.

@Quinn-With-Two-Ns
Quinn-With-Two-Ns force-pushed the temporal-nexus-operation-handler branch from 10a94e4 to 71ab56f Compare June 11, 2026 15:30
@Quinn-With-Two-Ns
Quinn-With-Two-Ns merged commit 27cfa7d into temporalio:master Jun 11, 2026
18 checks passed
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.

3 participants