Architecture & components
This page describes Maia’s core components, responsibility boundaries, and the end-to-end lifecycle of a single run.
Overview
Section titled “Overview”Maia consists of two parts:
- App: configuration management, state persistence, scheduling, and public APIs.
- Runner: an optional executor used for isolated step execution and dependency installation; if Runner is not configured, App executes locally.
Components
Section titled “Components”- HTTP API: manage Workflow/Version; create jobs; query runs, logs, and artifacts.
- MaiaEngine: a tick-loop driven state machine (claim jobs, create runs, download inputs, schedule steps, retry, and terminate).
- Database (SQLite / Prisma): the single source of truth. Job/Run/Step/Attempt, log events, and artifact metadata are persisted here.
- Local disk: run directories (run/attempt), dependency cache directories, artifact files, and downloaded files.
Runner
Section titled “Runner”Runner exposes two HTTP endpoints:
- Step execution:
/v1/exec/step, streaming NDJSON logs plus an exit event. - Dependency installation:
/v1/exec/deps, streaming NDJSON logs plus an exit event.
Runner uses Bearer Token authentication via RUNNER_TOKEN.
Core objects
Section titled “Core objects”- Workflow: the workflow definition (editable).
- WorkflowVersion: a workflow version. Each version contains an immutable runtime snapshot
workflowSnap. - JobRun: a run request (manual trigger, scheduled trigger, or the result of a batch fanout).
- Run: the runtime instance created after the engine claims a
JobRun, bound toworkflowSnap. - RunStep: a step node within a
Run, derived from the snapshot’ssteps. - Attempt: a single execution attempt for a
RunStep. - InputFile / InputBlob: input files and content storage. Both uploads and URL inputs are stored as
InputFile; content is deduplicated viaInputBlob. - Artifact: step outputs. System artifacts include
input.jsonandoutput.json; users can register additional files.
Data flow
Section titled “Data flow”Create a job
Section titled “Create a job”- App receives
inputJsonand file inputs (URL list and uploaded files). - If the workflow configures
inputSpec, App validates params usinginputSpec.paramsSchemaand applies JSON Schemadefaultvalues. - App writes
JobRunand stores files asInputFile(uploads map toInputBlob).
Convert JobRun to Run
Section titled “Convert JobRun to Run”MaiaEngineclaimsQUEUEDJobRunitems during its tick loop.- The engine creates a
Runbound to the version snapshotworkflowSnap. - The engine creates
RunSteprecords from the snapshot (initial statusPENDING). - The engine builds
Run.initialInputfromJobRun.inputJsonand attaches the system fieldfiles(mapped fromInputFile).
Input file handling
Section titled “Input file handling”- If URL inputs exist, the
RunentersPENDING_INPUTSfirst. - The engine downloads URL files, updates
InputFilestate, and mirrorsstatus/path/sha256/mimeintoRun.initialInput.files. - Once all inputs are ready, the
RunentersRUNNING.
Step scheduling and execution
Section titled “Step scheduling and execution”- The engine selects runnable
RunStepitems by dependency (depsallSUCCEEDED). - For each step, the engine creates an
Attemptand executes the step script:- Runner configured: App invokes Runner; Runner streams NDJSON logs and an exit event.
- Runner not configured: App executes locally via
child_process.
- After the step finishes, the engine writes
output.json(wrapped as{ ok, timestamp, data }) and persists logs, statuses, and artifact metadata.
Termination conditions
Section titled “Termination conditions”- Any step fails:
RunbecomesFAILED. - User cancels:
RunbecomesCANCELED. - All steps succeed:
RunbecomesSUCCEEDED.
Realtime
Section titled “Realtime”App persists runtime events in the log event table and pushes an SSE event stream. Events include (but are not limited to):
run_statusstep_statuslog_lineinput_file_statusartifact_created
- Environment variables: step execution uses an allowlist; only workflow env vars and
MAIA_*context vars are injected. - Reserved keys:
files,upstream, andurlFilesare reserved and must not appear ininputSpec.paramsSchemaorexamples[].params.
Related topics
Section titled “Related topics”- Input spec:
inputSpec - Output spec:
outputsSpec - Dependency management:
dependencies,depsHash