10 — Workflow Engine

Status: Ratified Version: 1.0.0 Applies to: engines/workflow.py, mission pipelines, plan execution, scheduling


1. Purpose

The Workflow Engine executes Directed Acyclic Graphs (DAGs) of steps. It is the deterministic execution backbone of every mission. It handles dependencies, parallelism, retries, validation, checkpoints, and recovery — while the Planner (02 §5.5) decides what the graph looks like and the Mission Engine decides why the mission runs.


2. Concepts

Concept Definition
WorkflowRun One execution of a workflow (or plan). Has id, status, correlation_id.
Step A node in the DAG. Has id, type, input, output contract, retry policy.
Edge depends_on relationship; forms a DAG (cycle detection enforced).
Checkpoint A saved point in time at a step boundary enabling resume.
Pipeline An ordered composition of phases; each phase is a workflow.
Task The atomic execution unit the scheduler dispatches.

3. Step Types

Type Behavior
agent Delegate to an agent (via AgentOrchestrator); agent may emit goals
tool Execute a tool via ToolExecutor (adapter + sandbox)
skill Execute a security skill from the Skill Registry
condition Branch on a boolean expression over accumulated output
parallel Run child steps concurrently (fan-out) with a join barrier
loop Repeat child steps while a condition holds; bounded by max_iterations
wait Pause for duration or until condition/event
transform Pure data transform (aggregate, map, dedup) — no I/O
submission Require operator approval/input (approval gate)
notify Emit an event / external notification; non-blocking
ai Invoke AI decision through the AI Engine (never direct)
report Render a report view

4. Workflow Definition (Contract)

Workflows are defined in YAML (mission profiles) or JSON (API). Contract:

id: external-recon
version: 1
phases:
  - id: discovery
    steps:
      - id: subdomain-enum
        type: tool
        tool: subfinder
        mode: passive
        profile: fast
        input: { target: "<target>", scope: "<scope>" }
        output_schema: subdomain
        depends_on: []
      - id: dns-resolve
        type: tool
        tool: dnsx
        input: { targets: "ref:subdomain-enum" }
        depends_on: [subdomain-enum]
  - id: detection
    steps:
      - id: port-scan
        type: tool
        tool: nmap
        profile: stealth
        depends_on: [dns-resolve]
      - id: nuclei-scan
        type: tool
        tool: nuclei
        profile: fast
        depends_on: [port-scan]
        retry: { max_attempts: 2, backoff: "exponential", retryable: [transient, timeout] }
      - id: high-sev-gate
        type: condition
        condition: "output.findings.max_severity in ('high','critical')"
        true: [validation]
        false: [report]
        depends_on: [nuclei-scan]
      - id: validation
        type: tool
        tool: sqlmap-validate
        requires_approval: true        # destructive-class
        depends_on: [high-sev-gate]

Execution semantics:


5. Execution Model

5.1 Scheduling & Concurrency

5.2 Validation Gates

5.3 Retries

Per-step policy:

retry:
  max_attempts: 3
  backoff: exponential   # exponential|linear|fixed
  base_delay_s: 1
  max_delay_s: 60
  jitter: true
  retryable: [transient, timeout, rate_limited]   # outcome classes

5.4 Cancellation


6. Checkpoint System


7. Recovery

Failure handling hierarchy:

step failure
  → retry policy (bounded)
  → route around (mark tool unavailable; skip with reason)
  → degrade phase (execute fallback profile / reduced scope)
  → pause workflow for operator intervention (requires_approval)
  → fail workflow (mission recovery path)

Recovery rules:


8. Mission Execution Integration

Mission Engine drives a pipeline = ordered phases. Each phase is a workflow.

mission.started
  ├─ phase: recon (workflow)
  │    └─ workflow.completed → mission.phase_completed
  ├─ phase: detection (workflow)
  ├─ phase: validation (workflow; approval gates)
  ├─ phase: correlation (workflow: transform steps)
  └─ phase: reporting (workflow: report steps)
mission.completed

9. Determinism & Reproducibility


10. Monitoring & Observability

Every step/run emits:

Event Fields
workflow.started run_id, plan_id, graph_id
workflow.step_started step_id, type, tool/agent
workflow.step_completed step_id, duration_ms, output ref
workflow.step_failed step_id, error, code, retryable
workflow.step_retrying attempt, delay
workflow.checkpoint_saved checkpoint_id, offset
workflow.resumed from_checkpoint
workflow.completed / workflow.failed summary, duration

Traces: one span per run; child spans per step/task; per-step metrics (hx_workflow_step_duration_seconds, hx_workflow_step_failures_total).


11. Error Classes (see also 17 - Error Handling Standards.md)

Class Example Retryable
transient network blip, tool crash yes
timeout step exceeds deadline yes (policy)
rate_limited 429 from target/API yes (backoff)
invalid_input bad mode/params no
scope_violation target out of scope no; abort + alert
config_error bad workflow def no
approval_required gate reached pause, wait

12. Performance Budget


13. References