Distributed DurableWorkflowEngine on litestar-queues DynamicWorkflow DAG waves execute across worker replicas via DurableWorkflowEngine, persisting write-once NodeRecord and monotonic WorkflowRun documents in WorkflowStore (litestar_mcp_workflows), using forever-unique wf-node:{run_id}:{node} reservations with reset_task_identity on retry and per-run wf-watchdog:{run_id}:{tick} recovery. 1. DynamicWorkflow DAG engine.start(name, ...) Topological wave validation Agent nodes & Python step nodes Dynamic StepResult(next_nodes) Captures PrincipalSnapshot Returns run_id immediately 2. WorkflowStore litestar_mcp_workflows Write-once NodeRecord per node Eliminates sibling fan-in races Monotonic WorkflowRun status Completed outputs never lost engine.snapshot(run_id) 3. Forever-Unique Queue wf-node:{run_id}:{node} Deduplicates concurrent fan-in Rehydrates Dishka Scope.REQUEST On transient error: releases key via service.reset_task_identity() Enqueues ready downstream wave 4. Watchdog wf-watchdog:{id}:{t} Per-run self-rearming Checks ready_nodes() Heals crashed workers Stops on terminal state Zero orphan DAG runs Parallel Wave Fan-Out & Conflict-Free Fan-In Wave 0: [extract] -> Wave 1: [enrich_a, enrich_b] (parallel workers) -> Wave 2: [aggregate] (forever-unique gate)
In-Process WorkflowEngine Execution In-process WorkflowEngine executes DynamicWorkflow topological waves concurrently using AnyIO task groups within a single request or background coroutine. 1. Workflow Definition DynamicWorkflow(name="...") WorkflowNode(name, agent=... | fn=...) depends_on=["upstream_a", ...] Validates acyclic dependency graph Supports runtime graph mutation workflow.add_node(...) in step 2. AnyIO Wave Scheduler WorkflowEngine.run(context) Computes ready nodes per wave Runs sibling wave nodes in TaskGroup Passes WorkflowContext(inputs, state) Records ctx.node_outputs[node] Enforces max_steps ceiling 3. Dynamic Branching & Output StepResult & WorkflowContext StepResult(output=..., next_nodes=[...]) Prunes unselected conditional branches Returns completed WorkflowContext Same DynamicWorkflow runs on both WorkflowEngine & DurableWorkflowEngine Portable DAG Definition Across In-Process and Distributed Engines Author DynamicWorkflow once -> test with WorkflowEngine in unit tests -> deploy on DurableWorkflowEngine