DAG Engine Specification
Document ID: WF-004 Version: 1.0.0 Status: Draft Owner: Workflow Engine Team Last Updated: 2026-06-26
1. Purpose
Section titled “1. Purpose”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.
2. Objectives
Section titled “2. Objectives”The DAG Engine must provide:
- Deterministic execution
- Parallel scheduling
- Efficient dependency resolution
- Runtime graph expansion
- Replay compatibility
- Horizontal scalability
3. Core Concepts
Section titled “3. Core Concepts”The execution graph consists of:
- Nodes
- Edges
- Dependencies
- Conditions
- Execution metadata
Each workflow execution owns a graph instance.
4. Graph Model
Section titled “4. Graph Model” Workflow Graph
┌──────────────┐ │ Start │ └──────┬───────┘ │ ┌──────────┴──────────┐ ▼ ▼ Validate Load Profile │ │ └──────────┬──────────┘ ▼ AI Classification │ ┌────────┴────────┐ ▼ ▼ Auto Approve Manager Review │ │ └────────┬────────┘ ▼ Store │ ▼ EndThe graph must be acyclic after expansion.
5. Node Types
Section titled “5. Node Types”Supported node categories:
| Type | Description |
|---|---|
| Start | Entry point |
| End | Terminal node |
| Activity | Executable task |
| Decision | Conditional branch |
| Merge | Join parallel branches |
| Split | Create parallel branches |
| Event | Wait for external event |
| Timer | Delay execution |
| AI | LLM inference |
| Human | Manual task |
| SubWorkflow | Nested workflow |
| Dynamic | Runtime-generated node |
6. Edge Types
Section titled “6. Edge Types”Edges define execution relationships.
Supported types:
- Sequential
- Conditional
- Parallel
- Event-triggered
- Retry
- Compensation
Each edge may contain activation rules.
7. Node State Machine
Section titled “7. Node State Machine”Each node transitions through:
Created │ ▼Ready │ ▼Scheduled │ ▼Running │ ┌─┴──────────────┐ ▼ ▼Completed Failed │ ▼ RetryingCompleted nodes never execute again unless replay explicitly requires it.
8. Graph Construction
Section titled “8. Graph Construction”Construction steps:
- Parse WIR
- Create nodes
- Create edges
- Validate references
- Detect cycles
- Build adjacency lists
- Compute dependency counts
- Persist graph metadata
9. Graph Representation
Section titled “9. Graph Representation”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.
10. Topological Ordering
Section titled “10. Topological Ordering”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.
11. Dependency Resolution
Section titled “11. Dependency Resolution”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.
12. Parallel Scheduling
Section titled “12. Parallel Scheduling”Independent nodes execute concurrently.
Example:
Start │ ┌─────┴─────┐ ▼ ▼ Fraud Inventory │ │ └─────┬─────┘ ▼ ShippingThe scheduler dispatches both branches as soon as they are ready.
13. Fan-Out / Fan-In
Section titled “13. Fan-Out / Fan-In”Fan-Out
Section titled “Fan-Out”One node activates multiple successors.
Fan-In
Section titled “Fan-In”Execution continues only after all required predecessors complete.
Merge policies may specify:
- All branches
- Any branch
- Configurable quorum
14. Conditional Execution
Section titled “14. Conditional Execution”Decision nodes evaluate expressions.
Example:
decision: when: riskScore > 80 goto: manualReviewConditions are evaluated exactly once unless replayed.
15. Dynamic Graph Expansion
Section titled “15. Dynamic Graph Expansion”Certain nodes may generate new nodes during execution.
Example:
AI Planner │ ▼Generate Tasks │ ┌───┼────┐ ▼ ▼ ▼A B CRules:
- Expansion occurs only at designated Dynamic nodes.
- New nodes must preserve acyclic structure.
- Expansion events are persisted for deterministic replay.
16. Cycle Detection
Section titled “16. Cycle Detection”Graphs must not contain cycles.
Validation occurs:
- During compilation
- After dynamic expansion
Detected cycles prevent execution.
17. Execution Planning
Section titled “17. Execution Planning”Planning algorithm:
- Compute initial ready queue.
- Dispatch eligible nodes.
- Persist node results.
- Update dependency counters.
- Activate newly ready nodes.
- Repeat until completion.
18. Ready Queue
Section titled “18. Ready Queue”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.
19. Failure Propagation
Section titled “19. Failure Propagation”Node failures may:
- Retry
- Trigger compensation
- Skip downstream nodes
- Abort workflow
- Redirect execution
Propagation behavior is defined by workflow policy.
20. Replay Behavior
Section titled “20. Replay Behavior”Replay reconstructs the graph from:
- Workflow definition
- Dynamic expansion events
- Checkpoints
- Execution history
Replay must produce the same executable graph.
21. Performance Targets
Section titled “21. Performance Targets”| Metric | Target |
|---|---|
| Graph construction | < 10 ms |
| Topological sort | O(V + E) |
| Ready queue update | O(log N) |
| Node activation | < 1 ms |
| Dynamic expansion | < 20 ms |
Targets apply to typical enterprise workflows (<10,000 nodes).
22. Observability
Section titled “22. Observability”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.
23. Rust Crate Mapping
Section titled “23. Rust Crate Mapping”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.rsEach module should have a single, well-defined responsibility.
24. Design Constraints
Section titled “24. Design Constraints”- 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.
25. Related Documents
Section titled “25. Related Documents”- Workflow Overview
- Execution Model
- Workflow DSL
- Scheduler
- State Machine
- Checkpointing
- Retry Engine
- Distributed Execution
- Persistence
- Rust Crate Design
26. Revision History
Section titled “26. Revision History”| Version | Date | Description |
|---|---|---|
| 1.0.0 | 2026-06-26 | Initial DAG Engine Specification |