Skip to content

Add Standalone Activities to Temporal Nexus Operation Handler#2918

Open
Quinn-With-Two-Ns wants to merge 4 commits into
temporalio:mainfrom
Quinn-With-Two-Ns:NEXUS-383
Open

Add Standalone Activities to Temporal Nexus Operation Handler#2918
Quinn-With-Two-Ns wants to merge 4 commits into
temporalio:mainfrom
Quinn-With-Two-Ns:NEXUS-383

Conversation

@Quinn-With-Two-Ns

@Quinn-With-Two-Ns Quinn-With-Two-Ns commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

What was changed

Why?

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?

Note

Medium Risk
Touches Nexus completion callbacks, operation tokens, and activity scheduling RPCs with subtle pre/post-RPC token differences; behavior is largely patterned on the existing workflow Nexus path but the new surface is large and marked experimental.

Overview
Nexus operation handlers can now back async operations with standalone activity executions, parallel to the existing workflow-run path. TemporalNexusClient gains typed and untyped startActivity overloads that return an activity-execution operation token; the same one-async-operation-per-handler guard applies across workflow and activity starts.

The activity path routes StartActivityInput through ActivityClientInternal.getInvoker() so interceptors and metrics stay intact. RootActivityClientInvoker reads NexusOperationMetadata from thread-local Nexus context to set the Nexus request ID, inbound links, completion callbacks (via shared InternalUtils.buildNexusCallback), and a pre-RPC activity operation token in callback headers; it also records StartActivityExecutionResponse links on the operation context. The token returned to the Nexus caller is regenerated with run ID after the start RPC, while the callback header token omits run ID.

OperationTokenType.ACTIVITY_EXECUTION (t:4) and aid/rid fields support cancel dispatch: TemporalOperationHandler defaults to ActivityClient cancel via overridable cancelActivityExecution. LinkConverter adds activity link URL round-trips. Nexus callback header injection for workflows is refactored into buildNexusCallback without behavior change.

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

* activity is scheduled from a Nexus operation handler.
*/
@Experimental
final class CompletionCallback {

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.

Need to think if this is the right way to propogate this information

@Quinn-With-Two-Ns
Quinn-With-Two-Ns marked this pull request as ready for review July 23, 2026 16:11
@Quinn-With-Two-Ns
Quinn-With-Two-Ns requested a review from a team as a code owner July 23, 2026 16:11

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 441ee33b6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

activityType,
args,
options,
Header.empty(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Propagate client context headers to Nexus-backed activities

When a Nexus handler starts an activity through this new path, any ContextPropagators configured on the surrounding WorkflowClient are lost because the StartActivityInput is always built with Header.empty(). Standalone ActivityClient.start normally serializes those propagators into the header before reaching the invoker, so callers relying on MDC/tracing/auth context propagation will see backing activities started from Nexus run without that context; build the header from client.getOptions().getContextPropagators() or route through the public ActivityClient.start path instead.

Useful? React with 👍 / 👎.

@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 good to me overall. Just want to make sure we get the token type enum aligned with the other SDKs and to confirm if we want the response link in this PR.

Comment on lines +58 to +61
// TODO: Attach activity-event link when server-side activity link support is available.
// No StartActivityResponseLink analog exists and there is no verified activity-event link path
// in LinkConverter. Do NOT copy the synthetic workflow-event link fabrication from
// NexusStartWorkflowHelper; Nexus operations function correctly without diagnostic links.

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.

Comment on lines +9 to +10
// Values 2 and 3 are reserved for future token types (e.g. update-workflow, get-workflow-result).
ACTIVITY_EXECUTION(4);

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.

Activity should be 2 and workflow update should be 3

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.

Super minor nit: This test file now contains tests for more than just WorkflowRunToken

}

@Test
public void testActivityOperationTokenRoundTrip() throws Exception {

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.

This test looks like it might be duplicated in the WorkflowRunTokenTest file?

@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 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 4706130. Configure here.

WORKFLOW_RUN(1);
WORKFLOW_RUN(1),
// Values 2 and 3 are reserved for future token types (e.g. update-workflow, get-workflow-result).
ACTIVITY_EXECUTION(4);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wrong activity token type

High Severity

ACTIVITY_EXECUTION is assigned numeric type 4, while the intended cross-SDK discriminator for standalone activity tokens is 2. Tokens emitted by this SDK won’t match other Temporal Nexus implementations or cancel dispatch that expects type 2.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4706130. Configure here.

nexusOperationMetadata.callbackHeaders,
nexusOperationMetadata.operationToken,
protoLinks);
request.addCompletionCallbacks(cb);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty callback still registered

Medium Severity

When Nexus operation metadata is present, startActivity always attaches a Nexus completion callback, even if callbackUrl is empty. The workflow start path only registers callbacks when the URL is non-empty, so this can send invalid completion callbacks on StartActivityExecution.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4706130. Configure here.

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