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 (Calls reset_task_identity() before each wave enqueue) and per-run wf-watchdog:{run_id}:{tick} recovery. DynamicWorkflow DAG engine.start(name, ...) Topological wave validation Agent nodes & Python step nodes Conditional & dynamic DAG edges Persists initial_state in WorkflowStore Returns run_id immediately 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) Forever-Unique Queue wf-node:{run_id}:{node} Deduplicates concurrent fan-in Rehydrates Dishka Scope.REQUEST Calls reset_task_identity() before each wave enqueue Enqueues ready downstream wave Watchdog wf-watchdog:{id}:{t} Per-run self-rearming Checks get_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. Workflow Definition DynamicWorkflow(name="...") WorkflowNode(name, handler=... | agent=...) depends_on=["upstream_a", ...] Validates acyclic dependency graph Conditional edge predicates workflow.add_node(...) & add_edge(...) AnyIO Wave Scheduler WorkflowEngine.run(workflow, initial_state) Computes ready nodes per wave Runs sibling wave nodes in TaskGroup Passes WorkflowContext(run_id, state) Records ctx.node_outputs[node] Propagates failed StepResult.error Dynamic Branching & Output StepResult & WorkflowContext StepResult(node_name, output, status, error) 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