Introducing a new way to review your PRs.

Read the announcement

eventual-inc / daft

High-performance data engine for AI and multimodal workloads. Process images, audio, video, and structured data at any scale

View on GitHub

19 documents · Updated Nov 11, 2026

docs / sessions-checkpoints-and-context

Sessions, checkpoints, and execution context

Daft separates query state, run-wide settings, and durable progress. A session gives queries a shared view of catalogs, tables, providers, functions, and extensions. The execution context supplies planning and run settings. Checkpoints record source progress and sink output so that a retry can skip work that is already safe to skip.

Session scope

Session state

The session is the connection-like scope for query planning and SQL execution. It owns the names and defaults that make an otherwise incomplete query meaningful, such as the current catalog, namespace, provider, and model. It also holds objects attached for name resolution, including catalogs, tables, temporary views, providers, and functions. A session can also load a native extension so that its registered functions are available to that session. See daft/session.py and src/…/session.rs.

Session state is isolated when an engineer creates a new session. A session used as a context manager becomes the active session for that Python scope. Calls made through the top-level Daft API use that active session, or a process-level fallback session when no session scope is active.

Temporary tables and views belong to the session that creates them. They provide query-local names without changing the external catalog, and a temporary view can expose a DataFrame without materializing it as an external table. They disappear from name resolution when that session is no longer used.

References: daft/session.py• L71-147 daft/session.py• L176-297 daft/session.py• L404-446 daft/session.py• L807-820 src/…/session.rs• L23-48 src/…/session.rs• L76-112

Name resolution

Name resolution uses session state before it consults external catalogs. For tables, a temporary table is considered first. The current catalog and namespace then provide the usual unqualified and namespace-qualified lookup, while an explicitly catalog-qualified name selects an attached catalog.

The current catalog and namespace therefore affect both SQL planning and direct table operations. A query that relies on short names must run with the same session settings as the query that created those names.

References: src/…/session.rs• L253-377 src/…/session.rs• L394-467 src/…/session.rs• L470-510

Execution context

Planning settings

The planning context controls how Daft builds a DataFrame or SQL plan. Its most important shared setting is the default object-store IO configuration, which readers and expressions use when a call does not provide one. Planning settings are read while a plan is built, so changing them later does not act as a general substitute for rebuilding the plan.

Use the planning context for choices that shape the plan. Use an operation-level IO setting when one source or expression needs a different storage or access setup.

References: daft/context.py• L30-58 daft/context.py• L162-197 daft/session.py• L153-170 daft/…/_iceberg.py• L120-126

Execution settings

The execution context controls how an existing plan runs. It groups choices such as scan sizing, shuffle behavior, output sizing, ordering, batching, and parallel scan limits. These settings affect work placement and throughput rather than the names or objects visible to the query.

Planning and execution settings have different boundaries. A planning setting is needed when the plan is assembled. An execution setting is used when the DataFrame is collected or written. Context managers can restore the prior setting after a scoped change.

References: daft/context.py• L200-252 daft/context.py• L299-351 daft/…/dataframe.py• L1074-1100

Active session and context relationship

The active session and the execution context solve different problems. The session answers “which objects and defaults does this query see?” The context answers “how should Daft build and run this query?” Keeping these scopes separate lets a query use session-local names while the process applies shared run policy.

SQL execution reads both scopes at its boundary: it sends the session to the SQL executor and passes the current planning configuration with the request. This is the main hand-off from user-facing query state to the query system.

References: daft/session.py• L153-170 daft/context.py• L112-114 src/…/exec.rs• L20-52

Resource settings

Task resource requests

Resource settings describe the capacity needed by a query fragment or user-defined function. A request can state CPU, GPU, and memory needs. The scheduler uses these values to place work and to avoid treating incompatible CPU and GPU work as one pipeline.

Requests are hints about task capacity, not a replacement for data size or query semantics. Daft validates GPU values and rejects negative resource amounts at the API boundary. A GPU request may be fractional up to one GPU; larger fractional requests are not valid.

References: src/…/lib.rs• L18-59 src/…/lib.rs• L97-115 daft/…/__init__.py• L472-486

Resource aggregation

When a physical plan contains resource-aware UDF work, the plan derives a task request from the strongest requirement in that plan. This lets scheduling see the capacity needed by the whole fragment instead of only the default CPU value.

The resource request travels with the task into the execution engine. The related engine page, Execution engines, explains how that request is used by local and distributed execution.

References: src/…/plan.rs• L1233-1259 src/…/task.rs• L501-511 src/…/worker_manager.rs• L220-329

Checkpoint configuration

Source progress

A checkpoint is durable progress for a source-to-sink pipeline. CheckpointConfig pairs a checkpoint store with a source column that identifies an input and optional settings for the key filter. On a later run, rows whose key is already recorded are removed before the rest of the pipeline processes them.

The key means “this input was processed.” It is not a destination primary key and does not provide upsert behavior. A source key must exist in the source schema and should identify an input at the level where retrying work is safe.

Checkpoint filtering supports map-only pipelines. Operators that need a global view of data, such as joins or aggregations, do not fit this source-progress boundary because their result cannot be safely replayed one source input at a time.

References: daft/checkpoint.py• L25-143 src/…/lib.rs• L142-190 daft/…/_checkpoint.py• L13-39

Checkpoint store

The checkpoint store is the shared progress record for one destination. It keeps source keys and output file metadata under checkpoint IDs. The store configuration describes where that record lives, while the live store provides the read and write behavior.

One store path must serve both ends of a pipeline. The source writes progress to it, and a checkpoint-aware sink reads the pending output metadata from it when it commits. Use a distinct store for each destination so that progress from one sink cannot suppress input for another.

References: daft/checkpoint.py• L25-76 daft/checkpoint.py• L130-143 src/…/lib.rs• L126-140

Key filtering settings

Key filtering is the query step that compares current source keys with sealed keys from the store. Its optional settings control worker count, worker CPU, key-load batches, worker concurrency, and filter batches. When omitted, the execution engine chooses the values.

These settings change the cost and parallelism of the filter. They do not change which keys are considered processed. Values that are set must be positive.

References: src/…/lib.rs• L166-217 src/…/python.rs• L42-81

Checkpoint lifecycle

Checkpoint states

Checkpoint data moves through three states. Staging gathers the source keys and any sink file metadata. Checkpointing seals the pair and makes the progress visible. Committing records that the external destination accepted the output.

The state boundaries have different reader effects:

StateSource keysOutput filesMeaning
StagedHiddenHiddenWork is still being assembled.
CheckpointedVisibleVisible to the committerKeys and output metadata are coupled.
CommittedVisibleRemoved from pending filesThe external catalog or sink commit succeeded.

Checkpoint IDs are created per pipeline input and shared by the key stage and the sink. This keeps the source progress and the output produced for that input in one lifecycle.

References: src/…/store.rs• L12-45 src/…/types.rs• L9-43 src/…/lib.rs• L94-117

Query checkpoint flow

The following flow shows how a retry-safe query turns source inputs into durable progress and then into a destination commit.

flowchart LR
    S[Source inputs] --> F[Filter recorded keys]
    F --> K[Process remaining rows]
    K --> SK[Stage source keys]
    K --> SF[Stage output metadata]
    SK --> C[Checkpoint input]
    SF --> C
    C --> X[External sink commit]
    X --> M[Mark checkpoint committed]
    M --> R[Future run skips recorded keys]

For a write sink, the sink stages its output metadata and seals the checkpoint after its input finishes. For a plan without a native write sink, the checkpoint terminus seals the staged keys when the input flushes. In both cases, the query can expose its output only after the checkpoint store has coupled the input keys with the work produced for that input.

References: src/…/stage_checkpoint_keys.rs• L97-157 src/…/blocking_sink.rs• L181-295 src/…/checkpoint_terminus.rs• L20-29 src/…/checkpoint_terminus.rs• L166-215

External commits

The checkpoint store does not define the destination catalog commit. It supplies the pending file metadata to a format-specific sink, and the sink marks the related checkpoint IDs committed after the external commit succeeds. This separates durable Daft progress from the destination’s own commit protocol.

For retries of one logical commit, IdempotentCommit carries a stable idempotence key. The key must stay the same across retries and must differ across distinct commits. The same store still carries the staged work; the idempotence key prevents the destination from creating a second commit for the same attempt.

References: daft/checkpoint.py• L159-198 daft/…/dataframe.py• L1336-1363 daft/…/dataframe.py• L1565-1661

State boundaries

Reliable execution depends on keeping four boundaries distinct:

  • Session boundary: names, attached objects, current defaults, and loaded extensions are visible only through the selected session.
  • Plan boundary: planning settings shape the plan when it is built.
  • Task boundary: resource requests describe the capacity needed by a task or plan fragment.
  • Progress boundary: checkpointed keys are safe for later filtering, while checkpointed files remain pending until the external sink confirms its commit.

These boundaries explain why a session change does not rewrite an existing DataFrame plan, why a resource change does not change the rows in a query, and why a checkpoint commit must be coordinated with the destination. They also provide the recovery model: a retry reads durable keys, finds any output still pending, and repeats only the unfinished commit work.

Change checklist

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

  • Keep the session lookup rules aligned with SQL planning and direct read_table calls. A change to catalog or namespace scope can change the meaning of an unqualified name.
  • Keep session-loaded extensions aligned with function resolution. A function registered by an extension must be available in the session that plans the query.
  • Keep planning defaults aligned with every reader or expression that falls back to the shared IO configuration. A new reader must not silently use a different storage setup.
  • Keep resource validation, plan-level aggregation, and scheduler requests compatible. A field that is accepted by the UDF API but lost before scheduling changes placement without an obvious query error.
  • Keep the source key column, the canonical sealed-key schema, and the key-filter join aligned. A rename must preserve the store contract.
  • Keep the checkpoint store path identical at the source and sink. The source and sink form one progress contract.
  • Keep checkpoint sealing ahead of key visibility and keep external commit bookkeeping after the destination commit. Reversing either order can skip work or repeat a commit.
  • Keep idempotence keys stable across retries and unique across logical commits. A changed key can duplicate data; a reused key can hide new data.

Important failure modes

TriggerConsequenceGuard
Checkpointing is requested on the native runner.The source cannot build its required checkpoint filter and query construction fails.Use the Ray runner for checkpoint filtering.
The source and sink use different checkpoint paths.The sink cannot find the staged output metadata and can commit nothing while source keys appear processed.Reuse one CheckpointStore path for both.
The backing store does not provide read-after-write consistency.A retry may not see newly sealed keys and may process the same input again.Use a strongly consistent backing store.
A checkpoint key is reused for different inputs or is treated as an upsert key.New work can be skipped, or duplicate source rows can still reach the sink.Use a stable input identity and use a separate update mechanism for upserts.
A staged checkpoint is marked committed before the destination commit.Pending output can be removed from the commit view even though the destination has not accepted it.Mark IDs committed only after the external commit succeeds.
The same idempotence key is used for different inputs.The destination can treat new work as an already completed commit.Keep the key stable only for one logical commit.
A resource request contains a negative amount or an invalid multi-GPU fraction.UDF creation or task setup fails before execution.Validate CPU, GPU, and memory requests at the API boundary.
A native extension is loaded into a different session from the query.The query cannot resolve functions supplied by that extension.Load the extension into the session that plans and runs the query.

Key files

FileWhy to read it
daft/session.pyMain user-facing session scope, active-session behavior, extension loading, and query hand-off.
src/…/session.rsSession state model and catalog, table, provider, and function resolution.
daft/context.pyShared planning and execution context boundaries.
src/…/lib.rsResource request meaning and validation rules.
src/…/plan.rsHow plan requirements become a task resource request.
daft/checkpoint.pyUser-facing checkpoint store, source configuration, and idempotent commit contract.
src/…/lib.rsShared checkpoint identity and filtering configuration.
src/…/store.rsCheckpoint state transitions and visibility guarantees.
src/…/stage_checkpoint_keys.rsSource-side progress capture.
src/…/blocking_sink.rsSink-side output staging and checkpoint sealing.
src/…/checkpoint_terminus.rsSealing behavior for plans without a native write sink.
daft/…/_checkpoint.pyReader boundary where checkpoint configuration enters a source plan.
daft/…/dataframe.pyFormat-specific commit coordination and post-commit bookkeeping.
Data sources and sinksRelated overview of source and destination behavior.
Execution enginesRelated overview of local and distributed execution.