Skip to content

DAG Engine Specification

Document ID: WF-004 Version: 1.0.0 Status: Draft Owner: Workflow Engine Team Last Updated: 2026-06-26


The DAG Engine transforms a validated Workflow Intermediate Representation (WIR) into an executable graph.

It is responsible for:

  • Graph construction
  • Dependency analysis
  • Execution planning
  • Parallel scheduling
  • Dynamic graph expansion
  • Cycle detection
  • Node activation
  • Execution ordering

The DAG Engine is independent of activity implementations.


The DAG Engine must provide:

  • Deterministic execution
  • Parallel scheduling
  • Efficient dependency resolution
  • Runtime graph expansion
  • Replay compatibility
  • Horizontal scalability

The execution graph consists of:

  • Nodes
  • Edges
  • Dependencies
  • Conditions
  • Execution metadata

Each workflow execution owns a graph instance.


Workflow Graph
┌──────────────┐
│ Start │
└──────┬───────┘
┌──────────┴──────────┐
▼ ▼
Validate Load Profile
│ │
└──────────┬──────────┘
AI Classification
┌────────┴────────┐
▼ ▼
Auto Approve Manager Review
│ │
└────────┬────────┘
Store
End

The graph must be acyclic after expansion.


Supported node categories:

TypeDescription
StartEntry point
EndTerminal node
ActivityExecutable task
DecisionConditional branch
MergeJoin parallel branches
SplitCreate parallel branches
EventWait for external event
TimerDelay execution
AILLM inference
HumanManual task
SubWorkflowNested workflow
DynamicRuntime-generated node

Edges define execution relationships.

Supported types:

  • Sequential
  • Conditional
  • Parallel
  • Event-triggered
  • Retry
  • Compensation

Each edge may contain activation rules.


Each node transitions through:

Created
Ready
Scheduled
Running
┌─┴──────────────┐
▼ ▼
Completed Failed
Retrying

Completed nodes never execute again unless replay explicitly requires it.


Construction steps:

  1. Parse WIR
  2. Create nodes
  3. Create edges
  4. Validate references
  5. Detect cycles
  6. Build adjacency lists
  7. Compute dependency counts
  8. Persist graph metadata

Recommended Rust structures:

pub struct Dag {
nodes: HashMap<NodeId, Node>,
edges: Vec<Edge>,
incoming: HashMap<NodeId, Vec<NodeId>>,
outgoing: HashMap<NodeId, Vec<NodeId>>,
}

The representation must support efficient traversal and updates.


The engine computes a topological order before execution.

Algorithm requirements:

  • O(V + E) complexity
  • Deterministic ordering
  • Stable output for identical graphs

Kahn’s Algorithm is recommended as the default implementation.


A node becomes executable only when:

  • All required predecessors have completed.
  • Conditional expressions evaluate to true.
  • Resource constraints are satisfied.
  • Security checks pass.

Dependency counts are updated after each completed node.


Independent nodes execute concurrently.

Example:

Start
┌─────┴─────┐
▼ ▼
Fraud Inventory
│ │
└─────┬─────┘
Shipping

The scheduler dispatches both branches as soon as they are ready.


One node activates multiple successors.

Execution continues only after all required predecessors complete.

Merge policies may specify:

  • All branches
  • Any branch
  • Configurable quorum

Decision nodes evaluate expressions.

Example:

decision:
when: riskScore > 80
goto: manualReview

Conditions are evaluated exactly once unless replayed.


Certain nodes may generate new nodes during execution.

Example:

AI Planner
Generate Tasks
┌───┼────┐
▼ ▼ ▼
A B C

Rules:

  • Expansion occurs only at designated Dynamic nodes.
  • New nodes must preserve acyclic structure.
  • Expansion events are persisted for deterministic replay.

Graphs must not contain cycles.

Validation occurs:

  • During compilation
  • After dynamic expansion

Detected cycles prevent execution.


Planning algorithm:

  1. Compute initial ready queue.
  2. Dispatch eligible nodes.
  3. Persist node results.
  4. Update dependency counters.
  5. Activate newly ready nodes.
  6. Repeat until completion.

Ready nodes are stored in a priority-aware queue.

Priority may consider:

  • Workflow policy
  • Node priority
  • Resource requirements
  • Deadlines

FIFO ordering is used among equal priorities.


Node failures may:

  • Retry
  • Trigger compensation
  • Skip downstream nodes
  • Abort workflow
  • Redirect execution

Propagation behavior is defined by workflow policy.


Replay reconstructs the graph from:

  • Workflow definition
  • Dynamic expansion events
  • Checkpoints
  • Execution history

Replay must produce the same executable graph.


MetricTarget
Graph construction< 10 ms
Topological sortO(V + E)
Ready queue updateO(log N)
Node activation< 1 ms
Dynamic expansion< 20 ms

Targets apply to typical enterprise workflows (<10,000 nodes).


Expose metrics for:

  • Active nodes
  • Completed nodes
  • Failed nodes
  • Queue depth
  • Graph expansion count
  • Parallel branch count
  • Critical path duration

Each graph execution is traceable through the workflow Correlation ID.


Recommended module layout:

engine-workflow/
└── dag/
├── graph.rs
├── node.rs
├── edge.rs
├── planner.rs
├── scheduler.rs
├── ready_queue.rs
├── expansion.rs
├── topology.rs
├── validator.rs
└── mod.rs

Each module should have a single, well-defined responsibility.


  • Graphs must remain acyclic.
  • Execution order must be deterministic.
  • Dynamic expansion must be replayable.
  • Node execution must be idempotent.
  • Scheduling must not depend on wall-clock timing.

  • Workflow Overview
  • Execution Model
  • Workflow DSL
  • Scheduler
  • State Machine
  • Checkpointing
  • Retry Engine
  • Distributed Execution
  • Persistence
  • Rust Crate Design

VersionDateDescription
1.0.02026-06-26Initial DAG Engine Specification