Repository navigation
Conversation
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>
There was a problem hiding this comment.
🟡 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
| 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>
There was a problem hiding this comment.
🟡 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
| 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 Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|


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.