Execution Engine
The execution engine is responsible for running your workflow: traversing the node graph in dependency order, calling LLMs and connectors, handling errors, and streaming results back to the browser in real time.
How Workflows Execute
A Modular9 workflow is a Directed Acyclic Graph (DAG). Execution follows this sequence:
- Trigger fires — the workflow is initiated by a chat message, cron tick, or webhook POST
- Trigger node runs — passes the initial payload (text, file content, or webhook body) downstream
- DAG traversal — the engine walks the graph in topological order
- Node execution — each node calls either the LLM Gateway (specialists) or Connector Executor (connectors)
- Output flows — each node's output becomes the next node's input
- Completion — all nodes complete, or an error/cancellation stops execution
Trigger → Node A → Node B → Node C (connector)
↓
Node D
In this example, Node A runs first, then Node B and Node D can run in parallel (they only depend on A's output), and Node C runs after Node B completes.
Dual Execution Paths
Modular9 supports two execution environments:
Vercel (Inline Executor)
On Vercel's serverless infrastructure, BullMQ cannot run background workers. Instead, Modular9 uses the Inline Executor (src/lib/execution/inline-executor.ts), which runs the full DAG traversal inside an API route using Next.js's after() function:
// The execution runs after the HTTP response is sent
import { after } from 'next/server'
after(async () => {
await runWorkflowInline(workflowId, runId, trigger)
})
This means the /api/executions endpoint responds immediately (returning the run ID), and the actual computation happens asynchronously after the response is delivered.
Docker Self-Host (BullMQ Worker)
On self-hosted Docker deployments, a dedicated BullMQ Worker process runs execution jobs from a Redis queue. The worker picks up jobs, processes them, and emits events back through Redis.
API Route → Redis Queue → BullMQ Worker → Execution
↓
SSE Event Stream
The execution path is auto-detected via the VERCEL environment variable.
Real-Time Output via SSE
Execution progress streams to the browser using Server-Sent Events (SSE) via the /api/executions/[runId]/stream endpoint.
Events emitted during execution:
| Event type | When | Payload |
|------------|------|---------|
| run:start | Workflow begins | { runId, workflowId } |
| node:start | Node begins processing | { nodeId, pluginId, input } |
| node:complete | Node finishes | { nodeId, output, tokens, duration } |
| node:error | Node fails | { nodeId, error } |
| node:trace | Reasoning trace available | { nodeId, trace } |
| run:complete | All nodes done | { runId, totalDuration } |
| run:error | Workflow-level failure | { runId, error } |
The browser receives these events and updates the Output tab in real time — each node's output appears as it becomes available, not all at once at the end.
Event Replay Buffer
A common SSE race condition occurs when the client connects after some events have already been emitted. Modular9 solves this with an event replay buffer using Upstash Redis:
- Events are pushed to a Redis list via
RPUSHas they're emitted - New SSE subscribers immediately receive all buffered events via
LRANGEon connect - Late subscribers see the complete execution history
Agent Runner
For Specialist nodes, the Agent Runner (src/lib/execution/agent-runner.ts) constructs the LLM call:
- Load plugin — fetch the plugin manifest from the registry
- Build system prompt — starts with
plugin.systemPrompt(domain expert identity) - Inject skills — append all skill markdown files from
skills/*/SKILL.md - Apply LOGIC.md — if
logicConfigis set, inject the compiled reasoning scaffold - Frame user message — wrap upstream output with context: "Here is the input from the previous step. Process this according to your role."
- Call LLM Gateway — send to the configured AI provider
- Run quality gates — validate output against contracts (if configured)
- Return output — text output passed downstream
Graceful Fallback
If a skill file is missing or fails to load, the agent runner logs a warning and uses a generic prompt instead of crashing the execution. One bad skill file does not break the node.
If a node's selectedModel is null, the runner resolves it in order:
- User's default model from the database
- Hardcoded fallback:
meta/llama-3.3-70b-instruct
Error Handling
Node-Level Errors
If a node fails (LLM API error, connector timeout, invalid response), execution handles it gracefully:
- The failed node emits a
node:errorevent - Downstream nodes that depended on the failed node are skipped
- Other parallel branches continue executing
- The run completes with a partial result
Run-Level Errors
If a catastrophic error occurs (database failure, uncaught exception), a run:error event is emitted and the execution is marked as failed in the database.
Retry Logic
Individual nodes do not retry automatically in the current implementation. If a node fails due to a transient LLM API error, you can re-run the entire workflow. Per-node retry is on the roadmap.
Workflow Lifecycle
Each workflow execution progresses through these states:
queued → running → completed
↘ failed
↘ cancelled
| Status | Description |
|--------|-------------|
| queued | Waiting to be picked up by the worker (BullMQ only) |
| running | Actively executing nodes |
| completed | All nodes finished successfully |
| failed | One or more nodes errored; execution stopped |
| cancelled | User-initiated cancellation via the stop button |
Execution history is stored in the workflow_runs table with the final status, duration, and all node outputs.
LOGIC.md Reasoning Middleware
Nodes can optionally carry a LOGIC.md reasoning specification (logicConfig in the node data). This is processed by the Logic Middleware layer before the LLM call:
- Reasoning strategy — choose from 6 strategies: chain-of-thought, tree-of-thought, react, reflexion, step-back, or direct
- Input/output contracts — Zod-validated schemas that the node's I/O must conform to
- Quality gates — expression-based conditions evaluated after the LLM responds (e.g.,
confidence > 0.8) - Circuit breaker — per-node failure tracking; if a node fails N times, it enters cooldown
If a quality gate fails, the middleware can: retry the LLM call, escalate to a higher-capability model, or use a predefined fallback response.
Execution Monitor
The Output tab in the right panel shows real-time execution state as an accordion — one row per node:
- Plugin color dot + node name
- Duration badge (time to complete)
- Token count badge (prompt + completion)
- Status indicator (running, complete, error)
Expanding a row shows the full rendered markdown output, a copy button, and a token breakdown. The last completed node is auto-expanded.
Next Steps
- Building Workflows — practical guide to workflow composition
- LLM Configuration — configure AI providers and models
- Connectors — how connector nodes fit into execution