State
Where rivet’s state lives under Airflow, and how to set up a worker for it.
State, by deployment
| Worker | State | What the operator does |
|---|---|---|
Ephemeral pod (KUBERNETES_SERVICE_HOST in the environment, or deployment="pod") | PostgreSQL, required | refuses SQLite (RIVET_AIRFLOW_STATE_SQLITE_ON_POD); refuses every CDC export (RIVET_AIRFLOW_CDC_ON_POD: the checkpoint is a file and would live on the pod’s disk) until rivet stores it in the state database; runs the config in place; keeps rivet’s stderr in a private file on the pod’s disk (stderr_temp), never in the task log |
Local or long-lived worker (deployment="local" overrides the detection for a long-lived Kubernetes worker with a persistent volume) | SQLite in a declared directory, or PostgreSQL | requires state_dir for SQLite state and for CDC; checks it; refuses state or a checkpoint left beside the original config; refuses SQLite state when Airflow’s executor may run tasks on several hosts (Celery, Kubernetes, Edge, …: RIVET_AIRFLOW_STATE_SQLITE_MULTI_HOST) unless the task says single_host=True; warns once per task that SQLite is single-host |
A state_dir that is not given where the state needs one is refused with RIVET_AIRFLOW_STATE_DIR_REQUIRED; one that cannot be created or written is refused with RIVET_AIRFLOW_STATE_DIR_NOT_WRITABLE. Creating a PostgreSQL state database needs psycopg2 on the worker, and a worker without it is refused with RIVET_AIRFLOW_STATE_DATABASE.
state_dir is an operator parameter, not an Airflow Variable. The builders pass one value to
every task they create, so “the same path for every task” holds by construction, it is visible
in the rendered fields, and reading it needs no metadata-database access on the worker.
PostgreSQL state is RIVET_STATE_URL=postgresql://... in the task’s environment:
env_from_connections={"RIVET_STATE_URL": "rivet_state"}, or set it on the worker and name it in
env_passthrough=["RIVET_STATE_URL"] (a worker variable is not inherited unless it is named).
A RIVET_STATE_URL set on the worker and not passed on is refused. If the worker’s
RIVET_STATE_URL names a state rivet would open, by rivet’s own rule (it starts with
postgres:// or postgresql://, or it is a sqlite:<path> file), and the task’s environment has
no entry for it (not in env_passthrough, env or env_from_connections), the task fails before
rivet starts with RIVET_AIRFLOW_STATE_ENV_NOT_PASSED and is not retried: rivet would otherwise run
green on an empty SQLite state in state_dir while the real state sits in the database or file the
worker names (an incremental export reads from the start again, a CDC stream re-anchors). An empty
or blank value, or one with any other scheme, selects no state here and is not refused. The
message names the variable and never its value. Fix it one of two ways: inherit the worker’s
value with env_passthrough=["RIVET_STATE_URL"], or give the task its own value with
env_from_connections={"RIVET_STATE_URL": "<conn_id>"} (or env). If the worker’s variable is
not meant for this pipeline, unset it on the worker, or declare env={"RIVET_STATE_URL": ""} on
the task: a declared value, also an empty one, is the task’s own decision and rivet then keeps
SQLite state in state_dir.
A sqlite:<path> state a task passes on is honoured. rivet opens the file the URL names: an
absolute path as written (sqlite:/data/rivet/state.db, sqlite:///data/...), a relative one
against the directory of the config it runs, which is state_dir (the copy). The checks for state
left beside the original config look for that file instead of state_dir/.rivet_state.db, the
single-host warning and the multi-host refusal name it, and a pod refuses it like any SQLite state.
The file still lives on this worker’s disk: it is single-host state.
Local worker setup guide
-
Create the state directory yourself, once, on storage that outlives the worker process. A host path or a named volume, never a container’s own filesystem. One directory per pipeline (per source database), for example
/var/lib/rivet/<pipeline>. The operator never creates it: a directory that silently appears empty is exactly the failure this guide exists to prevent, so a missing one is refused (RIVET_AIRFLOW_STATE_DIR_MISSING). -
Every task of every DAG that touches the pipeline must see the SAME absolute path. With Docker, mount the same host path at the same container path in every worker. Pass that path as
state_dir(the builders do it for all their tasks). -
What is in it.
.rivet_state.db: rivet’s state, under its default name.<config name>.<hash>.yaml(and<config name>.<hash>--<export>.yaml): the operator’s copy of your config, byte for byte.<hash>is the first 8 hex digits of the SHA-256 of the original’s absolute path, so two configs with one file name never share a copy. rivet resolves the config’s relative paths (its SQLite state, acdc.checkpoint, aquery_file, a localdestination.path) against the config’s directory, so running the copy puts all of them here (see 5). Edit your original; the copy is rewritten on every task. The operator does not setRIVET_STATE_URL=sqlite:itself: the copy already keeps the state here on every rivet it runs. Asqlite:value the task passes on moves the state to the file it names (see above); leave it unset for tasks unless the state must live elsewhere.- every relative
query_fileof the config, copied to the same relative path (see 5), and.rivet_airflow_query_files.json, which records the config directory each one came from, as the DAG gave it (thedags/repoof a git-sync link, not therev-<sha>it points to today), so a new revision of the same config is the same owner. The copy and the record are made under one lock (airflow/locks/state/query-files.lock), so two tasks of two config directories that share this state directory never both pass the check. - a relative
cdc.checkpoint, which resolves beside the copied config, that is, here. airflow/<dag_id>/: sealed plan artifacts (plans/<run_id>/<export>__<task_id>__s<max_tries>__<inputs>-<hash>.json), the crashed ledger, scratch files;airflow/locks/run/<export>.lock(run, apply, cdc_run),airflow/locks/<export>.lock(load and compact of a whole export) andairflow/locks/table/<export>__<table>-<hash>.lock(load and compact of one table) (Overlap).logs/<dag_id>/<task_id>-<hash>/: rivet’s stdout and stderr, one file per step and try.- How a name becomes a path. A DAG id, task id, run id or export name that is one lower-case
word of
a-z 0-9 _ . -(at most 80 characters, not starting with.or-) is used as it is. Any other name (other characters such as:+or non-ASCII letters, upper case, a mapped task’stask_id[index]) is written as its readable form (each run of other characters replaced by_) followed by-and 12 hex digits of the SHA-256 of the exact name: run idscheduled__2026-10-06T00:00:00+00:00becomesscheduled__2026-10-06T00_00_00_00_00-b07b0ae9e551. Two different names therefore never share a directory, a sealed plan, a log file or a ledger, also on a file system that ignores case. A task’s log folder always carries the hash, also for a plain task id, so it is never a folder an older layout wrote to. - One sealed plan per task, try series, config and export. The artifact’s name is made from the
export, the task id (with the map index), the try series (
s<max_tries>; Airflow movesmax_trieswhen a task is cleared) and<inputs>: a digest of the config’s absolute path, the config’s bytes and the export’squery_file. Two tasks of one DAG run never share a plan, also when they run two configs that both have an export of one name; a retry of the same task replays its own plan; a clear starts a new series and plans again, so a clear after a successful apply never replays a cursor snapshot that apply already moved past (rivet would refuse itRIVET_PLAN_ARTIFACT_STALE); a config or query file edited between two tries is planned again under a new name. - A retry replays its own plan only while the resolved config path and the config’s bytes are unchanged. A config reached through a symlink that is re-pointed between two tries (a new git-sync revision of the DAG folder) is planned again, also when the bytes are the same, and leaves one more config copy and plan artifact in the state directory.
- The plan digest does not cover the environment. Changing the source between two
tries of one task instance (another URL in
env, an edited Connection) replays the plan made for the old source against the new one. Clear the task in a new DAG run, or delete its artifact, after such a change. - The artifact records the export and the config it was planned from (
export_name,config_path).applyrefuses a plan object in which either is missing or is not the task’s own (RIVET_AIRFLOW_PLAN_ARTIFACT_FOREIGN), expired or not, and leaves the file as it is, so the retry is refused for the same reason until a person deletes it (or, once it has expired and is 24 h old, the pruning below removes it). The config is compared as a file, not as text: another case, Unicode form or symlink of the same file is the task’s own, and a recorded path that no longer exists is not. A file at that path that is not a JSON object (empty, cut short) is planned over. - Upgrading a state directory written by an earlier build of this package: files of an
older layout are left alone. They are never read, never pruned and never deleted, so
remove
logs/<dag_id>/<task_id>/folders without a-<hash>suffix andairflow/<dag_id>/plans/<run_id>/<export>.jsonfiles by hand when you no longer need them. A run in flight during the upgrade plans again, and its crashed budget starts empty (at most one extra crash retry). .rivet_airflow_marker: a random id written by the first task that used the directory; an empty one is refused (RIVET_AIRFLOW_STATE_DIR_MARKER_EMPTY) until a person deletes it.
The copies and every file under
airflow/andlogs/are created with mode0600, in directories of mode0700(an existingairflow/orlogs/directory is tightened). Moving an existing pipeline under Airflow: if.rivet_state.dbor a relativecdc.checkpointfile already sits beside your original config and not here, the task is refused before rivet starts (RIVET_AIRFLOW_STATE_BESIDE_CONFIG,RIVET_AIRFLOW_CHECKPOINT_BESIDE_CONFIG): the copy would not see it, and rivet would start from an empty state or re-anchor the stream. Stop the runs, move the file into the state directory (the state database with its-waland-shmfiles; the checkpoint to the same relative path), and run again. Using the config’s own directory asstate_dirneeds no copy and no move. Afterrivet init -o X: init records the source’s primary keys in a.rivet_state.dbbesideX, which the task then refuses the same way: move it (with-waland-shm) intostate_dir, or runinitwithRIVET_STATE_URLset to the PostgreSQL state the tasks use. rivet 0.32.2 addsRIVET_STATE_URL=sqlite:<path>, so init can write into<state_dir>/.rivet_state.db, the file the tasks use (README Quickstart). -
What breaks when a task sees a different or an empty directory. rivet creates a new, empty state there and treats every export as a first run: an incremental export re-reads from the start, a CDC stream re-anchors and the changes between the lost position and the new anchor are gone, with no error. What the operator can check without rivet’s state identity: the directory exists, is absolute and writable, and its marker equals the marker of each direct upstream rivet task of the same DAG run (taken from their XCom); on SQLite state a difference is refused with
RIVET_AIRFLOW_STATE_DIR_DIFFERS. On PostgreSQL state it is not: no task reads what another left in the directory, and several hosts, each with its own directory at one path, are the deployment that state is for (an extract on one host and its load on the other, measured by the live gate’s multi-host leg). It cannot see a directory that was emptied between two DAG runs, or two hosts that each have their own copy. -
Relative paths in the config. The copy changes the directory rivet takes as the config’s, and nothing else:
Key rivet resolves it against Under this package query_filethe config’s directory; an absolute path, ..and a symlink out of it are refused by rivetstays as written; the file is copied to the same relative path in the state directory before every task. Refused before rivet starts ( RIVET_AIRFLOW_QUERY_FILE) when it is absolute, has.., leaves the directory through a symlink, is missing for the task’s export, or when a config from ANOTHER directory already put a file at that relative path in this state directory (the refusal names the directory and the remedy for an owner that is an earlier revision of this config, or is gone: delete.rivet_airflow_query_files.jsonin the state directory and the next task claims the path)cdc.checkpointthe config’s directory resolves in the state directory, a subdirectory included (rivet 0.32.2’s init -o <stem>.yamlwrites./cdc/<stem>_<export>.ckpt); a file left beside the original is refused, see 3. The<checkpoint>.ownerrecord rivet 0.32.2 keeps beside it (which config owns the checkpoint) is neither checked nor touched by the operator: move it with the checkpoint or leave it, rivet re-claims a checkpoint whose recorded owner no longer names ita local destination.path(orprefix)the config’s directory the state directory: init’s ./output/orders/lands in<state_dir>/output/orders/(from rivet 0.32.2 a CDC scaffold written with-o <stem>.yamlsays./output/<stem>/orders_cdc/, which lands in<state_dir>/output/<stem>/orders_cdc/);cwddoes not move it. Write an absolute path to put the files elsewherethe other paths rivet opens as written, such as tls.ca_filethe process’s working directory unchanged: the working directory defaults to the directory of your ORIGINAL config; set cwdto change itThe preflight reads the config as rivet does: every ${name}is taken from a-p/--paraminextra_args(a run, CDC run or plan task only:rivet load,compactandapplyhave no -p, and those tasks refuse it withRIVET_AIRFLOW_PARAM_NOT_ACCEPTED), then from thetask’s environment, and spliced into the text before the YAML is parsed, with YAML 1.2 scalars ( 017andname: 2024stay the text written). Amodeno variable resolves is treated ascdcby the guards; an export name or acdc.checkpointno variable resolves is refused (RIVET_AIRFLOW_CONFIG_UNRESOLVED), as rivetrefuses the config. -
Single host. SQLite state and the lock files are visible to one host only. Two workers on two hosts need PostgreSQL state and a destination both reach (an object store). Measured with two Celery workers on two hosts, each with its own state_dir at one path (the live gate’s
--workers 2):- On PostgreSQL state with a GCS destination, extracts of one DAG run on both hosts, each
export moving host every run, and the CDC stream moving host, deliver every row once
and never move the stored cursor back. A retry of
RivetApplyOperatoron the other host finds no sealed plan there and plans again from the stored cursor: the delta is extracted once (the killed try on the first host wrote nothing and kept its artifact, pruned after 24 h). Not measured, by the same construction: a plan an earlier try on the first host already applied is not answeredalready_appliedon the other host but planned again, which for an incremental export reads only the rows past the moved cursor. - SQLite state: each host has its own
.rivet_state.db. An export that runs on the other host reads from the start, exit 0: the whole table again, and on the way back the rows the other host already took (990 of 1000 rows written twice). So SQLite state under an executor that may use several hosts is refused before rivet starts (RIVET_AIRFLOW_STATE_SQLITE_MULTI_HOST); a deployment with one Celery worker sayssingle_host=True. - A local destination (
rivet init’s default./output/, which lands in the state_dir): the files are split between the hosts; the first run on the other host writes there without complaint, and a later run on a host whose manifest is behind the stored cursor is refusedRIVET_STATE_CURSOR_PAST_MANIFESTby rivet. - The lock files guard one host (by construction, not measured): a zombie try on one host and its retry on another are kept apart only by rivet’s own run lease (Overlap).
- A ledger file would count crashes per host, so on PostgreSQL state the operator keeps none:
a crash is retried only within the first
crashed_retriestries (Retries).
- On PostgreSQL state with a GCS destination, extracts of one DAG run on both hosts, each
export moving host every run, and the CDC stream moving host, deliver every row once
and never move the stored cursor back. A retry of
-
Moving to PostgreSQL state. Stop the DAGs; create a database; set
RIVET_STATE_URLto itspostgresql://URL for every task (the worker’s environment, orenv_from_connections). This package does not copy the SQLite state into PostgreSQL: the new state starts empty, so plan the switch as a first run of every export (a full export simply runs again; an incremental export has no cursor to resume from). Keepstate_dirfor CDC: a checkpoint is a file on every state backend today, and it stays where it is.