Introducing a new way to review your PRs.

Read the announcement

bruin-data / bruin

Build data pipelines with SQL and Python, ingest data from different sources, add quality checks, and build end-to-end flows.

View on GitHub

21 documents · Updated Nov 20, 2026

docs / execution-runtime

Execution runtime

The execution runtime turns a prepared pipeline workload into running asset processes and task results. It combines dependency-aware scheduling with a pool of workers, maps each asset type to its run method, and carries run dates, variables, connections, limits, and cancellation through the work.

Runtime boundaries

Scheduler and worker boundary

The scheduler owns task state and decides when work is ready. The executor owns task dispatch and process execution. A task enters the worker queue only after its blocking upstream tasks finish and after active connection limits allow it. The worker returns a result, and the scheduler uses that result to mark the task and release more work. See Pipeline orchestration for how the graph and workload are built.

The main task represents the asset work. Column checks, custom checks, and optional metadata push use separate task instances. This separation lets the runtime report each outcome and lets blocking checks affect downstream work without making every post-task action blocking.

References: pkg/…/scheduler.go• L99-115 pkg/…/scheduler.go• L233-289 pkg/…/scheduler.go• L940-979

Operator dispatch

An operator is the runtime action for one asset type and task role. The default dispatch map covers the supported asset kinds and task roles with no-op entries, then SetupExecutors replaces the entries needed by the current workload with operators for SQL systems, Python, R, ingestion, sensors, checks, and metadata work.

This two-step setup keeps the scheduler independent of a specific data system. It also means an asset type must have a valid operator for every task instance that remains pending when a run starts.

References: pkg/…/defaults.go• L8-16 pkg/…/defaults.go• L423-438 cmd/run.go• L1466-1469

Asset execution modes

Sequential task execution

Each worker executes one task at a time through the sequential task runner. Before dispatch, the runner applies the full-refresh rule and selects the operator for the asset type and task role. A full refresh can come from the run or from an asset parameter. The run-level request is a global override, while an asset-level restriction prevents the effective operation from using full refresh. When an asset has a timeout, the runner applies a deadline to that asset operation and reports an asset-specific timeout only when that deadline causes the cancellation. An earlier deadline from the whole pipeline run remains a run-level cancellation.

If full refresh is requested for an asset that restricts it, the runtime changes that asset to incremental execution and reports a warning. If no operator exists for the asset type or task role, the task fails before external work starts.

For table assets, an effective full refresh normally selects a create-replace materialization. An explicit DDL strategy keeps its DDL behavior and reports that the table is not dropped or recreated unless its type or format requires it. Supported Data Vault strategies keep their own loading rules instead of silently becoming a plain table load.

References: pkg/…/sequential.go• L14-24 pkg/…/sequential.go• L26-38 pkg/…/sequential.go• L40-81 pkg/…/materializer.go• L23-53 pkg/…/materializer.go• L64-80 pkg/…/pipeline.go• L1473-1501

Concurrent pipeline execution

The concurrent executor starts the configured number of workers. Workers read tasks from the scheduler queue independently, so independent branches can run at the same time while dependency edges still control release order. A worker sends one result after its task ends, which drives the next scheduler step.

The bruin run --workers value controls the size of this local worker pool. Its default is 16. A worker count of one gives serialized processing for otherwise independent tasks, but the scheduler still applies dependency and connection rules.

flowchart LR
    scheduler[Scheduler] --> queue[Work queue]
    queue --> workerA[Worker A]
    queue --> workerB[Worker B]
    queue --> workerN[Worker N]
    workerA --> results[Task results]
    workerB --> results
    workerN --> results
    results --> scheduler

References: pkg/…/concurrent.go• L69-107 pkg/…/concurrent.go• L118-248 cmd/run.go• L607-611

Output and task observability

Workers attach task context to child output and report start and end events. Normal logs include task identity and time information. Interactive Python output can pass through unchanged when the run has one worker and a real terminal, which preserves progress updates that use carriage returns. The interactive TUI uses worker callbacks instead of normal running and finished lines.

The command groups results into asset, quality-check, metadata, and not-started counts. A run with pending or queued tasks when cancellation stops scheduling is reported as aborted, so the summary distinguishes unfinished work from work that failed after it started.

References: pkg/…/concurrent.go• L52-67 pkg/…/concurrent.go• L118-195 pkg/…/command_runner.go• L96-148 cmd/run.go• L95-112 cmd/run.go• L359-531

Execution defaults and limits

Pipeline and asset defaults

Execution uses the effective asset model produced before scheduling. Pipeline defaults fill missing asset values, including connection, materialization, timeout, retry, hook, and check settings, while an asset's own values take precedence. A missing pipeline concurrency is normalized to one. Pipeline retry cooldown is translated into the runtime retry delay. This pipeline-level value describes overlapping runs in the broader platform; local asset parallelism comes from --workers.

The runtime receives these values after parsing and normalization. The pipeline specification explains how defaults, variants, and materialization rules form that effective model.

References: pkg/…/pipeline.go• L2415-2442 pkg/…/pipeline.go• L2481-2528 pkg/…/pipeline.go• L3425-3438 pkg/…/pipeline.go• L3443-3561 cmd/run.go• L755-773

Variable and variant inputs

Pipeline variables provide named values with defaults for run-time rendering. A variant is a named set of overrides for those variables. The pipeline accepts a variant only when its name and override types are valid, then applies the override before it builds assets and renders identity fields such as asset names and dependencies.

Schema diagnostics check variable definitions and their default values against Draft 7 JSON Schema rules. These diagnostics support warning-based validation and do not change the values or schemas passed to a live run. A variant still must reference a declared variable and use a compatible value type before pipeline construction can continue.

References: pkg/…/variables.go• L14-66 pkg/…/variables_schema.go• L11-35 pkg/…/variant.go• L34-50 pkg/…/variant.go• L128-170 pkg/…/pipeline.go• L3104-3123 pkg/…/pipeline.go• L3211-3225

Connection concurrency limits

Connection concurrency limits protect a named external system from too many active asset tasks. The scheduler resolves the connection names used by pending task instances, counts queued and running work, and only releases a task when all of its limited connections have capacity. An ingestion task can consume both its source and destination limits.

The pipeline model resolves an explicit asset connection first. If it is absent, it infers a connection from the asset type or ingestion destination, then checks configured platform defaults before using the standard connection name. Some asset types can use more than one platform connection, and connectionless sources or metadata assets do not consume a connection slot. A limit of zero or less is invalid. A limit does not reduce the worker pool; it keeps eligible work pending until a slot becomes available.

References: pkg/…/pipeline.go• L2577-2639 pkg/…/pipeline.go• L2712-2757 pkg/…/manager.go• L2213-2257 pkg/…/scheduler.go• L387-492 pkg/…/scheduler.go• L993-1108 cmd/run.go• L1414-1421

Task and pipeline timeouts

The run command gives a normal batch run a seven-day pipeline deadline unless the user sets another value. A streaming run has no default pipeline deadline because it is expected to remain active until interrupted; an explicit timeout still applies. Each asset can also have its own timeout, and the runtime reports an asset timeout only when that asset's deadline is the cause.

Cancellation from the pipeline deadline or an interrupt stops scheduling new work. The scheduler drains results from in-flight workers for a bounded period and returns a partial result set so the command can save state and print a summary.

References: cmd/run.go• L755-764 cmd/run.go• L1483-1496 pkg/…/sequential.go• L26-38 pkg/…/scheduler.go• L836-937

Query runtime

Query preparation

SQL assets reach a target-specific operator through a shared query model. The query runtime renders run values and macros, extracts executable statements, and preserves session statements when the target needs them. It can also classify a statement as a result query or a data-changing or schema-changing statement so the result can be presented correctly.

The run context supplies values such as the start date, end date, execution date, pipeline name, run ID, full-refresh state, and query annotations. The same context lets hooks and asset parameters resolve at execution time after the final run range is known. Pipeline metadata comments are read as asset definitions before execution, while materialization removes embedded @bruin control comments from the SQL sent to a target.

References: pkg/…/extract.go• L14-25 pkg/…/extract.go• L336-356 pkg/…/extract.go• L359-405 pkg/…/render.go• L11-45 pkg/…/comment.go• L42-62 pkg/…/materializer.go• L23-27 cmd/run.go• L911-926 cmd/run.go• L1209-1225

Query row limits

The query runtime gives each target a way to bound returned rows without changing the meaning of the source query. T-SQL targets use a shared limiter that preserves the original query text and selects a valid form for plain queries, leading common table expressions, and top-level ordered queries. SQL Server and Fabric expose this behavior through their connection adapters.

The limiter keeps ordering valid when a bare outer ORDER BY would be illegal inside a wrapper. It also avoids treating keywords inside strings, comments, nested queries, or identifiers as part of the outer query. These rules protect bounded query workflows from syntax errors and from changes to case-sensitive aliases.

References: pkg/…/tsql_limit.go• L8-23 pkg/…/tsql_limit.go• L25-87 pkg/…/db.go• L172-177 pkg/…/db.go• L86-93 pkg/…/tsql_limit_test.go• L9-201

Query result and dry-run behavior

The query interface separates returned rows from execution facts. A result query can produce columns and rows, while a non-result statement can produce a statement type, affected-row counts, DDL details, or warehouse usage data. This gives command workflows a common result shape across database systems.

The standalone bruin query workflow can run a query or ask a connection to validate it without execution. Dry-run support is optional per connection. When available, it returns validity and target-specific information such as estimated bytes, cost, referenced tables, schema, or an explain plan.

References: pkg/…/dryrun.go• L5-57 pkg/…/statement.go• L9-18 pkg/…/statement.go• L85-121 cmd/fetch.go• L213-241 cmd/querier.go• L9-15

Language runtimes

Python asset runtime

Python assets run as local modules in the repository that owns the asset. The runtime builds per-asset environment values, injects connection data and run metadata, and selects a Python environment through uv. It supports project dependencies and older requirements-based workflows. If the asset materializes a table, the runtime exchanges data with the Python process through a temporary Arrow file.

Python assets are main tasks. Their checks use the target data-system operators rather than the Python process itself. This keeps Python code responsible for producing the asset result while the normal scheduler still owns checks and downstream release.

References: pkg/…/operator.go• L19-31 pkg/…/operator.go• L71-198 pkg/…/uv.go• L221-289 pkg/…/uv.go• L302-329 pkg/…/uv.go• L359-442

R asset runtime

R assets run through a local Rscript process. When an renv.lock file is present, the runtime prepares the isolated R environment before it starts the script. Without that lock file, it runs the script directly. The process receives per-asset variables, connection data, and run context in the same broad contract as Python assets.

R assets are also main tasks. The runtime checks that R is available when the operator is created, so a run can fail during setup before it schedules R work.

References: pkg/…/operator.go• L42-84 pkg/…/operator.go• L87-183 pkg/…/runner.go• L46-74

Child process cancellation

Language and ingestion runtimes use command execution under the task context. Ordinary one-shot commands follow the normal command cancellation path. Streaming ingestion commands use managed process handling so cancellation can stop the process group instead of leaving a long-running child behind.

Child output flows through the worker printer. The command runner returns a process error to the operator, which returns it to the worker and then to the scheduler as the task result.

References: pkg/…/command_runner.go• L24-51 pkg/…/command_runner.go• L96-148 pkg/…/uv.go• L259-266 pkg/…/runner.go• L76-101

Command-driven pipeline runs

Run preparation flow

The run command is the main entry point for a pipeline execution. It converts command flags into run context, loads the pipeline, materializes any selected variant, applies selection and state rules, configures connection limits, validates the pending workload, and creates the operators needed by that workload. The command families and operational workflows page places this run flow in the wider CLI lifecycle.

The command can target a pipeline, one asset, multiple asset paths, or a standalone Python script. A variant pipeline is previewed before the final pipeline load so the command can require an explicit variant and materialize the selected one. Other pipeline clients can materialize every declared variant as separate effective pipelines. Incompatible selection modes are rejected before scheduling. The CLI workflows page provides the wider command-level context for these entry paths.

Asset definitions can come from a separate task YAML file or from metadata in SQL, Python, or R comments. The loader turns either form into the same asset model before defaults, variant values, and scheduling rules apply. Strict YAML validation rejects unknown definition fields when validation is requested, so malformed asset metadata stops preparation rather than creating an incomplete workload.

The command then creates a deadline and signal-aware context. It starts workers against the scheduler queue and waits for the scheduler to return task results. The following flow shows the relationship between command preparation, scheduling, worker execution, and run state.

flowchart TD
    flags[Run command flags] --> context[Run context and dates]
    context --> load[Load and materialize pipeline]
    load --> filter[Select and filter task instances]
    filter --> validate[Configure limits and validate]
    validate --> setup[Build operators]
    setup --> scheduler[Start scheduler]
    scheduler --> workers[Start worker pool]
    workers --> processes[Run SQL, Python, R, ingestion, checks]
    processes --> results[Task results]
    results --> scheduler
    scheduler --> state[Save run state and summary]

Normal batch filtering skips streaming assets. Stream mode keeps the selected streaming asset and limits the workload to its main task. This prevents a never-ending asset from blocking checks, metadata push, or ordinary finite-run completion.

References: cmd/run.go• L775-921 cmd/run.go• L923-1001 cmd/run.go• L1015-1219 cmd/run.go• L1389-1503 cmd/run.go• L1586-1648 pkg/…/pipeline.go• L3104-3227 pkg/…/pipeline.go• L3298-3342 pkg/…/comment.go• L42-62 pkg/…/yaml.go• L537-583

Resume and state flow

At the end of a run, the command saves task state with the run parameters, run ID, compatibility hash, and optional backfill information. A --continue invocation restores the latest state only when the current pipeline has the same compatibility hash. Succeeded or skipped work does not run again; failed and in-flight work returns to the pending set.

This state flow makes a command run resumable without treating a changed pipeline as the same workload. The scheduler still owns the dependency graph after restoration, so resumed work follows current task release rules only when the graph is compatible.

References: cmd/run.go• L1003-1045 cmd/run.go• L1391-1404 cmd/run.go• L1602-1604 pkg/…/scheduler.go• L1152-1213 pkg/…/pipeline.go• L2531-2552

Streaming command flow

Streaming mode is a special command workflow for one never-ending CDC or message-broker asset. The command validates that the input is exactly one streaming asset, rejects flags that assume a finite batch, runs only the main task, and leaves interruption as the normal completion path. A streaming full refresh can use a stable --refresh-id so a retry can identify the same refresh request.

Because a stream does not reach normal success, checks and metadata push do not run in this mode. Managed child-process cancellation allows Ctrl+C or a termination signal to stop the foreground stream. The default pipeline timeout is omitted, but an explicit timeout still applies.

References: cmd/run.go• L574-595 cmd/run.go• L797-805 cmd/run.go• L992-1005 cmd/run.go• L1483-1496 pkg/…/uv.go• L259-266 cmd/run_test.go• L1558-1609

Change checklist

When these files or sections are changed, remember to consider these:

  • A new asset type must have entries for every task role it can create in both the default dispatch map and SetupExecutors.
  • Changes to task roles or blocking rules must preserve the scheduler relationship between main work, checks, metadata push, and downstream assets.
  • Changes to --workers, pipeline defaults, or connection details must keep local worker capacity separate from per-connection capacity and platform run overlap.
  • Changes to asset connection inference must keep explicit connections, ingestion destinations, alternate platform defaults, and connectionless assets aligned with scheduler limit accounting.
  • New run-context values must be passed through command setup and into SQL rendering, language environments, and child commands as one contract.
  • Changes to task cancellation must cover the scheduler drain path and long-running managed child processes.
  • Changes to state restoration must keep the compatibility hash aligned with every pipeline identity or graph field that affects safe continuation.
  • Changes to query classification or extraction must preserve the distinction between returned rows and non-result execution summaries.
  • Changes to target-specific row limiting must preserve valid syntax for CTEs and outer ordering while keeping the original query text and adapter behavior aligned.
  • Changes to variant materialization or run selection must keep variable validation, preview validation, asset construction, and the final pipeline load aligned before operators are built.
  • Changes to asset-definition parsing must keep separate YAML files and embedded source comments mapped to the same execution model.
  • Changes to full-refresh materialization must preserve DDL exceptions and platform-specific Data Vault behavior.
  • Changes to streaming filtering must keep normal runs from scheduling streaming assets and stream mode limited to one main task.
  • Changes to streaming validation must keep the single-asset rule, stable refresh ID, and timeout behavior aligned.
  • Changes to cancellation reporting must preserve the distinction between failed tasks and tasks that never started.
  • Changes to full-refresh request or restriction handling must keep run-level overrides, asset parameters, and incremental fallback aligned.
  • Changes to inferred asset dependencies must keep the dependency visible to both pipeline lineage and scheduler release rules.

Important failure modes

TriggerConsequenceGuard
A pending asset type or task role has no operatorThe task fails before it can run.Add the dispatch entry and initialize its real operator in SetupExecutors.
A task exceeds its asset timeoutThe task returns an asset timeout and can block downstream work.Set a timeout that matches the target operation and use the pipeline timeout for run-wide control.
The pipeline deadline expires before the asset timeoutThe result is a run-level deadline error rather than an asset timeout.Treat the outer run deadline as the controlling limit and do not classify it as an asset fault.
A named connection reaches its concurrency limitThe task stays pending even when a worker is free.Increase the connection limit only when the external system can support it.
An asset type has no connection mapping or usable defaultRun preparation cannot resolve the connection needed for scheduling or execution.Set an explicit asset connection or add the correct platform default mapping.
A blocking main task or check failsIts downstream tasks become upstream-failed.Inspect the first blocking result before rerunning dependent work.
The run context is cancelled during active workThe command returns partial results and may leave unfinished tasks in the saved state.Use cancellable operators and managed process handling for long-running commands.
--continue uses state from a changed pipelineResume is rejected rather than using a stale graph.Start a new run or restore the compatible pipeline revision.
A streaming asset is included in a normal batch runThe asset can prevent the batch from reaching normal completion.Use normal filtering for finite assets and use --stream for one streaming asset.
A streaming asset is run with finite-batch assumptionsThe command rejects the combination or cannot reach normal completion.Use one streaming asset with --stream and stop it with an interrupt.
A streaming full refresh is retried with a different refresh IDThe retry is not identified as the same refresh request.Reuse the same --refresh-id when retrying that refresh.
A connection does not implement dry-run supportbruin query --dry-run stops without validating the query.Use a connection with the optional dry-run capability or run the query normally.
A bounded T-SQL query has a shape that the limiter cannot wrap safelyThe target can reject the generated query.Preserve target-specific handling for CTEs and outer ORDER BY clauses, and keep malformed inputs on the safe fallback path.
A variant name or override is invalidPipeline construction stops before the workload is scheduled.Use a declared variant name and values that match the variable definitions.
A variable default fails its declared schemaWarning diagnostics report an invalid value and can block validation workflows.Keep the default value valid for its variable schema.
Full refresh reaches a DDL materializationThe table is not dropped or recreated as a normal create-replace run would be.Use a non-DDL strategy when replacement is required, or accept the DDL rules.
A variant pipeline is run without a selected variantThe command stops before it schedules work.Pass the declared variant name with --variant.
An inferred asset input does not exist or points to itselfPipeline construction stops before scheduling.Make input_asset name an existing different asset.

Key files

FileWhy to read it
cmd/run.goShows the command workflow from flags and pipeline loading through filtering, worker startup, result handling, streaming, and state saving.
pkg/…/pipeline.goDefines the effective pipeline and asset execution inputs, including defaults, full-refresh rules, connection resolution, inferred dependencies, compatibility identity, and variant materialization entry points.
pkg/…/variant.goDefines variable overrides, variant validation, and the boundary between build-time identity rendering and run-time templates.
pkg/…/variables.goDefines variable defaults, schemas, merges, and schema diagnostics used to prepare execution inputs.
pkg/…/materializer.goShows how full refresh selects materialization behavior and how hooks and control comments are applied before SQL execution.
pkg/…/comment.goShows how embedded source comments become asset definitions.
pkg/…/yaml.goShows how separate task YAML becomes the same asset model used by the runtime.
pkg/…/scheduler.goDefines task states, dependency release, connection limits, cancellation, and resumable run state.
pkg/…/sequential.goDefines per-task dispatch, full-refresh restriction, and asset timeout behavior.
pkg/…/concurrent.goDefines the worker pool, task result flow, output handling, and progress callbacks.
pkg/…/defaults.goShows the default asset-type and task-role dispatch contract.
pkg/…/extract.goExplains how SQL content becomes executable query statements with run-time rendering.
pkg/…/statement.goDefines query classification and execution summary behavior.
pkg/…/dryrun.goDefines the shared result shape for query validation and execution facts.
pkg/…/tsql_limit.goShows how bounded T-SQL queries preserve source text while handling CTEs and outer ordering.
pkg/…/operator.goShows the Python asset boundary and per-asset runtime environment.
pkg/…/uv.goShows Python environment selection, dependency execution, and materialization handoff.
pkg/…/operator.goShows the R asset boundary and environment setup.
pkg/…/command_runner.goShows child command output, cancellation, and error return behavior.
docs/pipeline-orchestration.mdParent page for workload construction, dependency graph creation, and task selection.
docs/pipeline-specification.mdRelated page for pipeline defaults, variants, asset metadata, and materialization rules.
docs/cli-command-workflows.mdRelated page for the CLI command families that start and support pipeline runs.
docs/cli-workflows.mdRelated page for command entry paths and broader CLI workflows.