Execution runtime and state
Dagster turns a job definition and run configuration into an execution plan. It then moves that plan through a runtime that creates resources, schedules steps, emits structured events, and updates the Dagster instance. The instance connects run history, event history, compute logs, and other orchestration state so that execution can be monitored and resumed.
Runtime model
The runtime separates the desired work from the work in progress. A run identifies the job, its configuration, its selected steps, and its place in a run group. An execution plan turns those inputs into steps with dependencies and an execution engine. The runtime context joins the plan to the run and the Dagster instance, then carries that context into local or delegated step work.
The main runtime concerns are:
| Concern | Role in the runtime |
|---|---|
| Run | Names one requested execution and records its lifecycle state. |
| Execution plan | Describes the steps and dependencies that can run for the request. |
| Active execution | Tracks pending, running, retried, skipped, successful, and failed steps. |
| Resource scope | Makes external services available for the work and closes them after use. |
| Dagster event | Reports progress, outputs, failures, and framework activity in a structured form. |
| Dagster instance | Coordinates storage and services used by the runtime. |
The runtime can execute a plan in the current process or through an executor that controls where steps run. This keeps the orchestration model separate from the process or machine that performs each step. See Run planning and execution for the step lifecycle and execution choices.
References: python_modules/…/api.py• L38-52 python_modules/…/plan.py• L92-120 python_modules/…/active.py• L52-129 python_modules/…/external_step.py• L48-91
Run planning
Run planning resolves the job definition with run configuration and optional step selection. The result is an ExecutionPlan, which is a concrete description of the work that the runtime may perform. The plan includes dependency order, input and output links, the selected execution engine, and state needed for reexecution. Input links also describe whether a value comes from an upstream output, an asset, configuration, a default, or a manager.
When a run already has a stored plan snapshot, the runtime uses its saved load data and known state while rebuilding the plan. This gives a worker enough context to execute the same run across a process boundary. A reexecution can instead derive a smaller plan from an earlier run and carry forward the outputs and retry information that remain valid. A delegated step receives a step reference with the run inputs and known state needed to rebuild its local context and return its events to the host.
The planning flow is:
flowchart LR
A[Job definition] --> C[Resolve run configuration]
B[Run selection and tags] --> C
S[Stored plan snapshot and known state] --> C
C --> P[Build execution plan]
P --> X[Create execution context]
X --> E[Run selected steps]
Planning can fail before step work starts when configuration is invalid or the job cannot satisfy the plan's requirements. A persistent instance also provides the snapshot and run information needed to reconstruct a run after handoff or restart.
References: python_modules/…/api.py• L651-718 python_modules/…/plan.py• L135-212 python_modules/…/plan.py• L811-829 python_modules/…/state.py• L101-188 python_modules/…/external_step.py• L107-158 python_modules/…/external_step.py• L182-224
Step orchestration
Step orchestration is the state machine that makes the plan advance. It exposes steps whose dependencies are ready, waits when no step can proceed, and reacts to each step event. Successful outputs unlock downstream work. Dynamic outputs can add resolved downstream steps after their mapping keys are known. Missing outputs can mark dependent steps as skipped, while retry requests place steps back into a retry state when policy allows.
The executor consumes this state machine and may run more than one ready step at a time. Instance-wide concurrency limits and step priority can restrict which ready steps start. The runtime treats an interrupted or lost step as a meaningful state problem rather than silently completing the run.
Each step follows a high-level event path:
- The runtime creates a step context with the current known state and required resources.
- The executor or a step launcher loads inputs, runs user compute, checks values, and stores outputs.
- The step produces input, output, success, retry, failure, or skip events.
- The active execution records the event and updates dependency state.
- The runtime starts newly eligible steps or finishes the run when all plan work reaches a terminal state.
See Run planning and execution for the detailed step and retry behavior.
References: python_modules/…/execute_plan.py• L32-105 python_modules/…/active.py• L88-175 python_modules/…/active.py• L295-349 python_modules/…/active.py• L579-721 python_modules/…/execute_step.py• L438-579 python_modules/…/inputs.py• L70-90
Runtime resources
Resources provide scoped access to services that user work needs, such as a database or an API client. The runtime finds the transitive set required by the selected steps, their inputs, outputs, and hooks. Dagster resolves resource dependencies before it initializes a dependent resource. It passes the resulting resource set into step contexts and tears resources down in reverse order when execution ends.
Resource setup is part of the run's observable lifecycle. The runtime can emit start, success, and failure events for resource initialization. A resource may also hold cleanup work after its setup function yields, so a run can fail during teardown even after its steps finish.
An IO manager is a resource with a data handoff role. It stores step outputs and loads them as inputs for downstream steps. Output and input contexts carry run, step, asset, partition, configuration, and metadata information so the manager can identify the data it handles. This lets the execution plan describe data flow without fixing the storage system used for intermediate values. See Resources and IO managers for this boundary.
References: python_modules/…/resource_definition.py• L52-82 python_modules/…/resources_init.py• L42-75 python_modules/…/resources_init.py• L119-215 python_modules/…/resources_init.py• L350-434 python_modules/…/init.py• L34-101 python_modules/…/output.py• L628-664 python_modules/…/io_manager.py• L43-54
Event recording
Dagster events are structured records that describe runtime progress. They cover run state, step state, resource setup, input and output checks, data movement, asset activity, hooks, engine actions, and failures. The same event stream supports live subscribers and later inspection.
The runtime yields events as work advances. Step execution turns input loads, type checks, user outputs, output handling, materializations, observations, and failures into this stream. The instance wraps each event in an event-log entry with its run ID, job name, step key, timestamp, message, and optional error data. It stores the entry in event storage, updates run storage for run-level events, and notifies subscribers for that run.
The instance also provides the read boundary for asset history. Consumers can use it to find materializations, planned materializations, partition status, and asset events that do not belong to a run. Asset reads can use storage cursors to continue from a known point, which lets backfills and other readers process new history without re-reading all prior events. Backfill progress and asset views use this history to relate asset state to the runs that produced it.
The event path is:
sequenceDiagram
participant R as Runtime
participant I as Dagster instance
participant EL as Event storage
participant RS as Run storage
participant S as Run subscribers
R->>I: Report structured event
I->>EL: Store event-log entry
I->>RS: Apply run status change
I-->>S: Notify event listeners
Event storage can write entries one at a time or as a batch. A failed batch write falls back to individual writes. This protects event capture while keeping the event stream suitable for run views, asset history, metrics, and other observability uses. See Events and observability for how engineers consume this stream.
References: python_modules/…/__init__.py• L82-109 python_modules/…/log.py• L31-67 python_modules/…/execute_step.py• L322-435 python_modules/…/execute_step.py• L754-884 python_modules/…/output.py• L697-735 python_modules/…/event_methods.py• L189-280 python_modules/…/event_methods.py• L351-372 python_modules/…/asset_methods.py• L483-506 python_modules/…/storage_methods.py• L36-55
Dagster instance
The DagsterInstance is the runtime's access point for persistent state and orchestration services. A persistent instance is loaded from DAGSTER_HOME and its dagster.yaml configuration. An ephemeral instance provides mostly in-memory state for short-lived execution such as tests.
The instance brings together the services that the runtime needs:
| Service | State or action |
|---|---|
| Run storage | Run records, run status, tags, run groups, and plan snapshots. |
| Event storage | Structured event-log entries and asset-related event history. |
| Compute log manager | Captured standard output and standard error from compute work. |
| Run coordinator | Controls when submitted runs may enter execution. |
| Run launcher | Starts run workers in the selected execution environment. |
| Schedule and daemon storage | State used by scheduling and background services. |
| Dynamic partition store | Current membership and definition identity for dynamic partition sets. |
The instance registers these services so they can use the same instance context. It also provides the shared lookup boundary for dynamic partition membership. A storage system can answer a batch membership request directly. When it cannot, the dynamic partition loader reads the definition once and reuses the result for later checks. A view that includes pending add and delete requests lets planning evaluate the partition state that will exist after those requests.
The instance also manages shared storage operations such as reindexing and disposal. This makes run metadata and events available across the web server, daemons, run workers, and other processes. See Instance and persistence for storage choices and process boundaries.
References: python_modules/…/instance.py• L68-128 python_modules/…/instance.py• L136-232 python_modules/…/instance.py• L602-670 python_modules/…/types.py• L121-205 python_modules/…/types.py• L207-298 python_modules/…/base_storage.py• L10-34 python_modules/…/storage_methods.py• L80-124
Asset backfill coordination
An asset backfill is a long-running request to materialize selected assets or asset partitions. Its saved state records the target set, submitted work, materialized results, and failed assets with their downstream impact. The daemon uses this state to turn asset-graph progress into new run requests instead of treating the backfill as one large run.
Each iteration validates the saved targets against the current asset graph and partition definitions before it acts. Dynamic partition checks use the instance's membership boundary, which can resolve a group of requested keys in one query or use a cached definition when the storage has no bounded batch query. The first iteration requests target roots. Later iterations read new materializations and failed runs, then use asset dependencies and backfill policy to select eligible downstream work. This prevents a child from being requested before its required parent state is ready and keeps compatible work grouped into the same run.
The daemon stores pending requests before submission, reserves run IDs, submits requests in chunks, and writes progress between chunks. It checks the backfill status during submission so cancellation stops new requests. If the daemon stops during submission, the saved pending requests let the next iteration resume without losing accepted work. Materialization reads use the saved event-storage position and may overlap prior records to account for event write order; repeated records are merged without double-counting.
Completion requires both asset status and run status. The iteration waits for active runs and automatic retries that are not yet launched. It marks the backfill successful or failed when all targets have a materialization or failure state. If all runs finish but targeted partitions still have no status, it marks those partitions and their downstream assets as failed rather than remaining in progress forever. Cancellation and failure continue to collect final materialization and failure state until the requested runs finish.
This coordination links asset history to run state through the instance. It also makes stored backfills sensitive to changes in the asset graph, partition definitions, partition shapes, and code locations that supply those definitions. See Instance and persistence for the storage boundary and Events and observability for the materialization events that drive progress.
References: python_modules/…/asset_backfill.py• L1022-1194 python_modules/…/asset_backfill.py• L1232-1350 python_modules/…/asset_backfill.py• L1353-1490 python_modules/…/asset_backfill.py• L1605-1740 python_modules/…/asset_backfill.py• L1943-2103 python_modules/…/asset_methods.py• L220-240 python_modules/…/instance.py• L650-670 python_modules/…/types.py• L152-205
State persistence
Persistence keeps orchestration state available after the process that performs a run exits. Run storage holds the run record and its lifecycle updates. Event storage holds the ordered record of structured events. Plan snapshots preserve the information needed to rebuild the work for a run.
The runtime also carries a smaller known execution state for delegated or repeated work. It includes prior retry counts, resolved dynamic outputs, output versions, ready outputs, and links to outputs from parent runs. Reexecution and resume derive this state from stored step events and plan snapshots, then use it to avoid treating already valid work as new work. Delegated workers receive the same state through a step reference so their local plan agrees with the host plan.
Asset execution also carries data-version state. The step context caches the latest input asset records and uses their data versions and event pointers with code version information to describe output provenance. This state supports consistent asset history without putting the full input history in every event.
Compute logs are a related but separate record. The compute log manager captures standard output and standard error and associates them with the run and a log key. The event stream records that capture and points consumers to the captured log data rather than storing all text inside each event.
References: python_modules/…/base.py• L36-75 python_modules/…/base.py• L217-229 python_modules/…/state.py• L32-60 python_modules/…/state.py• L101-188 python_modules/…/state.py• L225-423 python_modules/…/external_step.py• L150-224 python_modules/…/data_version_cache.py• L34-58 python_modules/…/data_version_cache.py• L71-139 python_modules/…/execute_step.py• L581-744 python_modules/…/compute_log_manager.py• L32-47 python_modules/…/storage_methods.py• L35-55
Change checklist
When these files or sections are changed, remember to consider these:
- Keep run status transitions aligned between
DagsterEventType, event handling, and run storage updates. - Keep execution-plan snapshots compatible with the known state used for resume and reexecution.
- Keep step input sources, dependency maps, and dynamic-output mappings aligned so delegated and resumed plans resolve the same downstream work.
- Keep resource initialization and teardown events aligned with the resource scope used by step contexts.
- Keep output and input context identifiers aligned with IO manager storage and asset partition records.
- Keep asset input-version caches aligned with materialization and observation records used to build provenance.
- Keep event-log entry fields stable for subscribers and for consumers that filter by run, step, or event type.
- Keep compute-log capture keys and the
LOGS_CAPTUREDevent contract aligned so log consumers can find captured output. - Keep asset backfill targets, pending run requests, reserved run IDs, and materialization cursors consistent so daemon iterations can resume without duplicating or losing progress.
- Keep backfill completion checks aware of both unfinished runs and runs waiting for automatic retry.
- Keep asset-graph and partition-definition validation aligned with the serialized target subset used by stored backfills.
- Keep asset-history queries and partition-status cache reads aligned with the event storage contract used by backfills and asset views.
- Keep optional partition cursors compatible between instance methods and event-storage implementations so incremental reads do not lose or repeat asset history.
- Keep dynamic-partition membership semantics consistent across single-key checks, batched checks, cached loaders, and pending add/delete request views.
- Keep shared storage lifecycle actions aligned across run, event, schedule, and local artifact storage.
- Keep delegated step references and host event replay compatible across process boundaries.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A worker starts a run that is already finished or in an incompatible state | The runtime ignores the duplicate worker or marks the restarted run as failed. | Run workers validate the stored run status before execution. |
| A required resource is missing or its dependency graph is cyclic | Context creation or resource setup fails before dependent step work can run. | Resource dependencies are checked and required resources are validated before each step. |
| A multi-process executor is used with non-persistent step outputs | A worker cannot load an output produced by another process and plan creation fails. | The plan checks executor requirements against the IO managers used by job outputs. |
| A step requests more retries than its retry policy allows | The step becomes failed instead of retrying again. | Retry state tracks prior attempts and compares them with the request limit. |
| An input fails to load or a value fails its type check | The step emits the relevant failure event and does not run valid downstream work. | Input sources and step execution wrap loading and type checks in step error boundaries. |
| A required output is missing or an output manager fails | The step fails and its dependent work cannot use that output. | Step execution validates required outputs and reports output handling errors as step failures. |
| Resource teardown fails after compute completes | The run records a teardown failure even though step work finished. | Resource scopes close in reverse initialization order and emit teardown failure events. |
| A batch event write fails | Event persistence falls back to individual writes. | Event handling retries the batch contents as separate storage operations. |
| Execution ends with steps in an unknown state | The plan does not complete successfully because the runtime cannot prove that all steps finished. | Active execution raises an unknown-step-state error or an interruption error. |
| Persistent storage cannot provide a run or plan snapshot needed for execution | The worker cannot reconstruct the requested run or its execution state. | Run creation and plan reconstruction require the corresponding stored records. |
| An asset, partition definition, or code location changes while an asset backfill is stored | The backfill cannot safely map its saved target to the current asset graph and fails or waits for the definition to return. | Backfill iterations validate saved assets and target partitions before creating new requests. |
| Backfill submission is interrupted after some runs are accepted | A later iteration could duplicate or lose requests if it cannot distinguish submitted work from pending work. | The daemon stores pending requests before submission and updates them in chunks with reserved run IDs. |
| Backfill runs finish without materializing all targeted partitions | The backfill could remain in progress even though no new result can arrive. | The iteration checks for a stall and marks unresolved partitions and their downstream assets as failed. |
| Event records arrive out of order while a backfill reads materializations | A materialization can be missed at an iteration boundary or counted twice. | The backfill uses a storage cursor with an optional overlap and unions results idempotently. |
| A materialization has a partition shape that does not match the backfill target | Backfill progress cannot be mapped safely to the targeted asset subset. | Materialization reads validate partitioned and unpartitioned targets before adding progress. |
| A backfill is marked canceling while runs or automatic retries still exist | The backfill can end before its final asset statuses are known. | Cancellation waits for requested runs to finish and continues to read materialization and failure state. |
| A dynamic partition membership lookup assumes a bounded batch query that storage does not support | Partition planning can become slow or repeatedly load the full definition. | The loader uses the bounded query only when storage advertises support and otherwise caches one full definition read. |
| Pending dynamic partition changes are not applied to a membership view | Planning can treat a key that will be added as absent or a key that will be deleted as present. | The request-aware store applies additions and deletions before it answers membership checks. |
| An instance passes a partition cursor to storage that does not support the newer argument | Asset history reads fail at the storage boundary. | The instance omits the optional cursor when it is unset and keeps the no-cursor call compatible with older storage implementations. |
Key files
| File | Why to read it |
|---|---|
| python_modules/…/api.py | Main boundary for building plans and starting run or plan execution. |
| python_modules/…/plan.py | Shows how job structure and run inputs become executable steps. |
| python_modules/…/active.py | Shows the state machine that advances steps and handles completion. |
| python_modules/…/context_creation_job.py | Shows how the run context, executor, log manager, and resource scope are assembled. |
| python_modules/…/execute_plan.py | Shows the event-driven loop around step work, logs, retries, and hooks. |
| python_modules/…/execute_step.py | Shows how one step loads inputs, runs compute, validates outputs, stores values, and emits asset events. |
| python_modules/…/inputs.py | Shows how plan inputs connect configuration, assets, managers, and upstream outputs. |
| python_modules/…/external_step.py | Shows how a delegated worker rebuilds one step and returns its events to the host. |
| python_modules/…/resources_init.py | Shows resource dependency setup, lifecycle events, and teardown. |
| python_modules/…/output.py | Shows the identity and asset context passed to output managers. |
| python_modules/…/data_version_cache.py | Shows how input asset history is cached for output provenance. |
| python_modules/…/asset_backfill.py | Shows how the daemon validates asset-backfill targets, persists progress, and turns materialization state into new run requests. |
| python_modules/…/instance.py | Defines the instance as the shared gateway to runtime services, state, and dynamic partition membership. |
| python_modules/…/types.py | Defines the instance-facing dynamic partition store and its cached and request-aware views. |
| python_modules/…/event_methods.py | Shows how events reach storage, run state, and live subscribers. |
| python_modules/…/asset_methods.py | Shows how the instance reads asset history, partition state, and asset status through event storage. |
| python_modules/…/storage_methods.py | Shows how the instance forwards storage queries and manages shared storage lifecycle actions. |
| python_modules/…/base.py | Defines the run-history and plan-snapshot storage contract. |
| python_modules/…/base.py | Defines the structured event-log storage contract. |
| python_modules/…/state.py | Defines the state passed across retries, reexecution, and process boundaries. |