Skip to content

Add support for setting ActivityID - #3044

Open
Quinn-With-Two-Ns wants to merge 1 commit into
temporalio:mainfrom
Quinn-With-Two-Ns:SDK-853
Open

Quinn-With-Two-Ns wants to merge 1 commit into
temporalio:mainfrom
Quinn-With-Two-Ns:SDK-853

Conversation

@Quinn-With-Two-Ns

@Quinn-With-Two-Ns Quinn-With-Two-Ns commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

What was changed

Add support for setting ActivityID

Why?

Add support for setting ActivityID, for manual completion or deduplication.

Checklist

  1. Closes Support passing activityId to an activity invocation #86

  2. How was this tested:

  1. Any docs updates needed?

Note

Medium Risk
Changes activity scheduling and interceptor inputs on the workflow execution path; incorrect ID handling could break replay determinism or duplicate open activities, though defaults preserve prior behavior.

Overview
Adds per-invocation Activity options so workflows can supply an optional Activity ID when scheduling remote or local activities (for deduplication, manual completion, and stable identity), without putting that ID on reusable stubs.

Introduces experimental ActivityInvocationOptions and many Workflow.executeActivity / executeActivityAsync overloads (sync, async, void, typed method references). Untyped ActivityStub gains matching execute / executeAsync overloads. ActivityInvocationInternal uses a thread-local to apply options to exactly one stub call inside the wrapped lambda.

The optional ID is carried through WorkflowOutboundCallsInterceptor.ActivityInput / LocalActivityInput into SyncWorkflowContext, which sets activity_id on scheduled activity commands (and preserves it across local-activity retries). Existing call paths pass null so the SDK still generates IDs. Package docs and integration tests cover history, concurrency, generics, local activities, and replay when the explicit ID changes.

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

@Quinn-With-Two-Ns
Quinn-With-Two-Ns requested a review from a team as a code owner August 28, 2026 16:01

@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: 01d272538a

ℹ️ 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".

Comment on lines +23 to +25
try {
invocationFunction.apply();
return state.getResult();

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 Preserve transformations performed by activity lambdas

When the supplied function is a lambda that transforms the activity result, such as () -> activities.getNumber() + 1, the proxy captures the underlying Activity Promise but returns a default value to the lambda; this call then discards the lambda's computed result and returns the captured promise unchecked. Consequently the example resolves to the raw Activity value rather than the incremented value, and lambdas that dereference object results can throw NullPointerException. Either preserve the function's result semantics or reject anything other than a direct Activity invocation.

Useful? React with 👍 / 👎.

@sangkyoonnam

Copy link
Copy Markdown
Contributor

Been running this cherry-picked on 1.38.0 in our dev environment for a few weeks. Same use case as #86: setting the activityId to a domain id lets an external consumer complete a doNotCompleteOnReturn activity with just workflowId + activityId, no task token to pass around.

On the replay concern from review: the workflow that uses it is covered by a golden-history replay test, and we haven't seen any non-determinism from setting the activityId.

Any chance this lands in a release soon? Would let us drop the custom build.

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

Comment thread temporal-sdk/src/main/java/io/temporal/workflow/Workflow.java 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.

Support passing activityId to an activity invocation

3 participants