Skip to content

Add ctx.ScheduleNewWorkflow for detached workflows#100

Open
acroca wants to merge 4 commits into
dapr:mainfrom
acroca:detached-workflows
Open

Add ctx.ScheduleNewWorkflow for detached workflows#100
acroca wants to merge 4 commits into
dapr:mainfrom
acroca:detached-workflows

Conversation

@acroca
Copy link
Copy Markdown
Member

@acroca acroca commented May 6, 2026

Ref: dapr/dapr#9261

Summary

Adds first-class support for spawning a fully decoupled workflow from within another workflow, replacing the prior pattern of wrapping a WorkflowClient.ScheduleNewWorkflow call inside an activity.

What this does

  • New orchestrator-context method: WorkflowContext.ScheduleNewWorkflow(workflow, opts...) (api.InstanceID, error). Returns the new instance ID synchronously — there is no awaitable Task because the spawned workflow is fire-and-forget.
  • Wrapper-layer mirror in workflow/.
  • Runtime applier branch that, on CreateDetachedWorkflowAction:
    • Appends a single DetachedWorkflowInstanceCreatedEvent to the caller's history (event id == action id).
    • Emits an ExecutionStartedEvent for the new instance with ParentInstance == nil, propagating Name, Input, Tags, ScheduledStartTimestamp, ParentTraceContext (action's, with fallback to current trace context), and ExecutionId (mints a UUID when absent, matching the client API).
    • Mints a fresh, target-only routing envelope on the spawned StartEvent (no SourceAppID back-reference) so the new workflow looks like a freshly client-scheduled top-level workflow.
  • Version is intentionally NOT propagated to the spawned StartEvent, matching the existing CreateChildWorkflow precedent.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds first-class “detached workflow” scheduling from inside an orchestrator via WorkflowContext.ScheduleNewWorkflow, enabling fire-and-forget spawning without parent linkage (so completion/failure does not flow back to the caller).

Changes:

  • Introduces task.WorkflowContext.ScheduleNewWorkflow (plus workflow/ wrapper) with deterministic default instance ID generation when no instance ID is provided.
  • Extends the runtime applier to handle CreateDetachedWorkflowAction by recording a DetachedWorkflowInstanceCreated event in the caller and emitting an ExecutionStarted event for the spawned instance with no parent linkage and target-only routing.
  • Adds unit/integration tests covering detached workflow scheduling, determinism across replay, routing behavior, and execution ID minting.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
workflow/workflow.go Adds wrapper-level ScheduleNewWorkflow and detached workflow option helpers.
task/orchestrator.go Implements ScheduleNewWorkflow orchestration API, options, and replay retirement logic.
backend/runtimestate/applier.go Applies CreateDetachedWorkflowAction by recording caller history + emitting spawned start message with no parent linkage.
tests/runtimestate_test.go Adds applier-focused tests for detached workflow history/message shaping and routing/execution ID behavior.
tests/orchestrations_test.go Adds end-to-end tests for detached workflow lifecycle, default IDs, non-propagation of failure, and replay determinism.
task/detached_workflow_test.go Adds orchestrator-context unit tests for emitted actions/options and replay retirement behavior.
api/protos/orchestrator_actions.pb.go Updates generated protos to include CreateDetachedWorkflowAction and wiring in WorkflowAction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread workflow/workflow.go Outdated
Comment thread workflow/workflow.go Outdated
Comment thread task/orchestrator.go Outdated
Signed-off-by: Albert Callarisa <albert@diagrid.io>
@acroca acroca force-pushed the detached-workflows branch from f4b60dc to fbc9eb4 Compare May 7, 2026 11:57
@acroca acroca marked this pull request as ready for review May 7, 2026 11:57
@acroca acroca requested a review from a team as a code owner May 7, 2026 11:57
Comment thread backend/runtimestate/applier.go
Comment thread task/orchestrator.go Outdated
Comment thread workflow/workflow.go Outdated
Comment thread workflow/workflow.go Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread tests/orchestrations_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Albert Callarisa <albert@acroca.com>
JoshVanL

This comment was marked as resolved.

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.

4 participants