Skip to content

Add scheduleNewDetachedWorkflow to WorkflowContext - #1931

Open
JoshVanL wants to merge 2 commits into
dapr:masterfrom
JoshVanL:detached-rerun-replay
Open

JoshVanL wants to merge 2 commits into
dapr:masterfrom
JoshVanL:detached-rerun-replay

Conversation

@JoshVanL

@JoshVanL JoshVanL commented Dec 4, 2026

Copy link
Copy Markdown
Member

A workflow can now schedule a detached workflow: a new top-level instance with no parent link. The call returns the instance ID immediately, there is no task to await, and neither the result nor a failure flows back.

When no instance ID is passed, a deterministic one of the form "-" is generated. An app ID in WorkflowTaskOptions routes the spawn to another app. Retry and history propagation options are rejected.

On replay, the Nth call returns the instance ID that history recorded for the Nth detached workflow, even when a different ID is passed. A rerun of the caller executes under a new instance ID, so without this it would compute a different ID and schedule the detached workflow a second time.

Adds an example under examples/workflows/detached and an sdk-tests integration test that reruns a workflow past a detached workflow.

A DetachedWorkflowInstanceCreated event that does not match a scheduled detached workflow fails the workflow as non-deterministic. This failure is raised through Task.await() as well, where other non-determinism errors are currently swallowed.

Bumps the durabletask protos to v0.8.0, which record the workflow name on the DetachedWorkflowInstanceCreated event. When that name is present and differs from the name the replayed call schedules, the workflow fails as non-deterministic.

A workflow whose last step schedules a detached workflow still completes: a pending detached workflow no longer holds back the implicit completion.

A workflow can now schedule a detached workflow: a new top-level instance
with no parent link. The call returns the instance ID immediately, there
is no task to await, and neither the result nor a failure flows back.

When no instance ID is passed, a deterministic one of the form
"<caller instance ID>-<n>" is generated. An app ID in WorkflowTaskOptions
routes the spawn to another app. Retry and history propagation options
are rejected.

On replay, the Nth call returns the instance ID that history recorded for
the Nth detached workflow, even when a different ID is passed. A rerun of
the caller executes under a new instance ID, so without this it would
compute a different ID and schedule the detached workflow a second time.

Adds an example under examples/workflows/detached and an sdk-tests
integration test that reruns a workflow past a detached workflow.

A DetachedWorkflowInstanceCreated event that does not match a scheduled
detached workflow fails the workflow as non-deterministic. This failure
is raised through Task.await() as well, where other non-determinism
errors are currently swallowed.

Bumps the durabletask protos to v0.8.0, which record the workflow name on
the DetachedWorkflowInstanceCreated event. When that name is present and
differs from the name the replayed call schedules, the workflow fails as
non-deterministic.

A workflow whose last step schedules a detached workflow still completes:
a pending detached workflow no longer holds back the implicit completion.

Signed-off-by: joshvanl <me@joshvanl.dev>
@JoshVanL
JoshVanL requested review from a team as code owners December 4, 2026 19:26
Copilot AI balanced review requested due to automatic review settings December 4, 2026 19:26

Copilot AI 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.

🟡 Changes recommended

Detached workflow IDs can collide across continueAsNew generations, and replay mismatches after explicit completion can throw instead of returning a failed-workflow response.

2 open issues
What changed in this PR

Adds fire-and-forget detached workflows to the Java workflow SDK, with replay-aware instance IDs and cross-app routing.

Changes:

  • Adds scheduling APIs and replay validation.
  • Updates durable-task protos to v0.8.0.
  • Adds unit tests, rerun integration coverage, and a runnable example.
File Description
sdk-workflows/​src/​test/​java/​io/​dapr/​workflows/​task/​internal/​DetachedWorkflowTest.java Tests scheduling, replay, routing, and validation.
sdk-workflows/​src/​main/​java/​io/​dapr/​workflows/​WorkflowContext.java Defines detached-workflow APIs and contracts.
sdk-workflows/​src/​main/​java/​io/​dapr/​workflows/​task/​internal/​TaskOrchestrationExecutor.java Implements scheduling and replay handling.
sdk-tests/​src/​test/​java/​io/​dapr/​it/​testcontainers/​workflows/​TestWorkflowsConfiguration.java Registers integration-test components.
sdk-tests/​src/​test/​java/​io/​dapr/​it/​testcontainers/​workflows/​FailsOnceAfterDetachedActivity.java Triggers failure for rerun testing.
sdk-tests/​src/​test/​java/​io/​dapr/​it/​testcontainers/​workflows/​DetachedTargetWorkflow.java Tracks detached instances.
sdk-tests/​src/​test/​java/​io/​dapr/​it/​testcontainers/​workflows/​DetachedRerunWorkflow.java Exercises spawning before failure.
sdk-tests/​src/​test/​java/​io/​dapr/​it/​testcontainers/​workflows/​DaprWorkflowsIT.java Checks reruns avoid duplicate spawns.
pom.xml Updates durable-task proto version.
examples/​src/​main/​java/​io/​dapr/​examples/​workflows/​README.md Documents and runs the detached example.
examples/​src/​main/​java/​io/​dapr/​examples/​workflows/​detached/​DemoParentWorkflow.java Demonstrates detached scheduling.
examples/​src/​main/​java/​io/​dapr/​examples/​workflows/​detached/​DemoDetachedWorkflowWorker.java Hosts example workflows.
examples/​src/​main/​java/​io/​dapr/​examples/​workflows/​detached/​DemoDetachedWorkflowClient.java Starts and observes example instances.
examples/​src/​main/​java/​io/​dapr/​examples/​workflows/​detached/​DemoDetachedWorkflow.java Implements the detached example workload.

Review effort: Balanced

Comment on lines +702 to +704
if (instanceId == null) {
instanceId = this.instanceId + "-" + this.defaultDetachedWorkflowCounter++;
}
A recorded detached workflow is only handed to a call whose sequence number
has reached the event's ID, and a repeated event ID counts once. A call
whose event is missing from history stays a new call.

A detached workflow mismatch found after the workflow already completed now
replaces that completion with the failure.

The detached example uses gRPC port 50008. Port 50005 is taken by the
placement service.

Signed-off-by: joshvanl <me@joshvanl.dev>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 20:06

Copilot AI 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.

🟡 Changes recommended

Detached workflow IDs can collide across continue-as-new generations, while out-of-order spawn history can be discarded and trigger false non-determinism failures.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment on lines +259 to +268
for (HistoryEvents.HistoryEvent e : pastEvents) {
// A repeated event ID is a duplicate left by a worker that sent the spawn twice. Only the first
// one stands for a call.
if (e.hasDetachedWorkflowInstanceCreated()
&& (this.recordedDetachedEvents.isEmpty()
|| this.recordedDetachedEvents.get(this.recordedDetachedEvents.size() - 1).getEventId()
< e.getEventId())) {
this.recordedDetachedEvents.add(e);
}
}
@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.41758% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.00%. Comparing base (c47d51b) to head (e63d044).

Files with missing lines Patch % Lines
...flows/task/internal/TaskOrchestrationExecutor.java 82.75% 5 Missing and 10 partials ⚠️
...c/main/java/io/dapr/workflows/WorkflowContext.java 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1931      +/-   ##
============================================
+ Coverage     82.97%   83.00%   +0.03%     
- Complexity     3985     3992       +7     
============================================
  Files           361      361              
  Lines         11978    12070      +92     
  Branches       1339     1370      +31     
============================================
+ Hits           9939    10019      +80     
- Misses         1537     1540       +3     
- Partials        502      511       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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