duckOrch GitHub ↗
On this page

duckOrch architecture and execution

duckOrch stores task definitions, asset state, and run history in DuckDB. It executes a directed acyclic graph of tasks, records dataset dependencies, and exposes orchestration to SQL, the CLI, and the MCP server. The user guide and the SQL reference describe the interfaces available in the documented release. The original design record includes the prototype roadmap, schema sketches, and design decisions.

Extension and workers

The C++ extension registers DuckDB operations and executes prepared statements. Rust implements task metadata parsing, dependency analysis, graph traversal, scheduling, and lineage serialization. The native interface passes validated values and results between the components. Code that calls DuckDB's C++ internals targets a supported DuckDB revision.

Area Responsibility
Task registration Read SQL files, parse their metadata, and store source identity and input/output information.
Graph planning Resolve explicit dependencies and inferred table relationships, detect cycles, and order the affected tasks.
Execution Dispatch ready tasks, execute SQL on a worker connection, and record success, failure, or skip outcomes.
Assets Track partitions, materializations, checks, dynamic refresh, and automation conditions.
Lineage Record dependencies and generate Mermaid diagrams or OpenLineage events.
Host integrations Expose typed planning and state operations in Python, asset tools through MCP, and machine-readable CLI output.

Task definitions

A task is a trusted SQL file with metadata in SQL comments. A deployment can validate task definitions before registering them. The parser can infer some inputs from the statements. Declare dependencies explicitly when a query's inputs or side effects are opaque to analysis.

-- @task name=user_stats
-- @description Active users by country
-- @inputs analytics.clean_users
-- @outputs analytics.user_stats
-- @depends_on clean_users
-- @retries 3
-- @timeout 300
-- @test "SELECT COUNT(*) FROM analytics.user_stats WHERE users < 0" expect 0

CREATE OR REPLACE TABLE analytics.user_stats AS
SELECT country, COUNT(*) AS users
FROM analytics.clean_users
GROUP BY country;
Metadata Purpose
name, description, owner, tags Identify a task and provide ownership, description, and grouping.
inputs, outputs, depends_on Declare source relations, produced relations, and task edges.
schedule Store a cron schedule for recurring work.
retries, timeout Set retry and deadline policies.
incremental_by Name the source watermark column for incremental processing.
test Declare a SQL assertion for the task output.

Registration identifies missing dependencies, duplicate names, and cycles. A task should declare outputs that later stages consume. The planner relies on correct registration of dependencies when scheduling independent writes in parallel.

Execution, state, and retries

Register tasks with PRAGMA orch_register and execute their DAG with PRAGMA orch_run. Initialize the registry with PRAGMA orch_init. The CLI also exposes registration, execution, inspection, and graph operations. Use --json for machine-readable CLI responses.

The internal schema records task definitions, run attempts, and lineage edges. Its run data includes the task identity, timestamps, status, row count where available, and error details. A downstream task can run when its prerequisites succeed. When a prerequisite fails, dependent tasks are skipped while unaffected branches may continue. The worker scheduler allows independent tasks to run concurrently subject to the configured concurrency setting.

The execution design uses per-worker connections and transaction boundaries. A retry starts a fresh transaction and records its own outcome. Keep data mutation atomic and idempotent so that a retry produces the same intended output. Inspect __orch__.runs and the CLI output to diagnose failed work and skipped descendants.

Incremental runs and assets

Incremental tasks can use a watermark from earlier successful work. Resolve runtime values through supported named bindings. The guide documents legacy templating and the named-parameter path. A full refresh provides the complete rebuild path when prior state or inputs need to be replaced.

Assets add explicit partitions and materialization state. Use partition-scoped runs for isolated refreshes and backfills. Automation conditions and dynamic assets can evaluate upstream changes and refresh selected outputs. Quality checks can attach assertions to asset or task outputs and retain the results in the catalog.

The embedded Python module includes half-open change windows, durable generation coverage, manifest publication and rollback, and schema checks. The host chooses the database and trusted model IDs, then passes typed values. See the embedded Python API for signatures and the user guide for setup and examples.

Lineage and scheduling

Mermaid diagrams show task and dataset relationships. OpenLineage events identify jobs, runs, and input/output datasets for systems that ingest the OpenLineage format. Review declared dependencies and the recorded lineage together when investigating an unexpected run or planning a change.

The worker scheduler processes dependency-ready tasks. CLI scheduling and asset automation are separate entry points. Run scheduling in the intended host process and coordinate who owns writes to a database. Use the MCP server guide for registered asset and inspection operations exposed to agents.

Design history and compatibility

The original design covers task-format decisions, state-store interfaces, graph visualization, retry policies, and agent integration. Historical sketches include optimizer hooks, column-level lineage, configurable state stores, and approaches to coordinating with other extensions. Check the SQL reference and guide for the current public API. The original design record preserves historical examples, diagrams, phase milestones, implementation risks, and attribution.