ADR-0048: Airflow WATCHER mode¶
Architecture: Section 13, The Airflow plugin
Amends ADR-0012 and ADR-0038. No core change.
Status: Accepted (2026-11-16, after the live check on the Astro example: a green run, then a failed unit cleared with Downstream and rerun on try 2).
Context¶
In LOCAL, VIRTUALENV and KUBERNETES modes every unit is its own Airflow task and its own process: each one starts Python, imports the engine, binds the project and checks the plan hash. On a wide DAG of short models that start-up cost dominates, and the core scheduler, which already runs units in parallel with in-process retries, goes unused. A user wants one pipeloom run for the whole selection and still one Airflow task per model, with its state, retries, logs and asset events.
Options¶
- One task for the run. A single task runs
pipeloom run. Cheap, but the graph, per-model state and asset events are lost. - Producer and watchers. One producer task runs the selection; one deferrable watcher per unit reads the files the run writes and reports that unit. The watchers cost a triggerer slot each instead of a worker slot.
- Producer pushes states. The producer sets the state of the unit tasks through the Airflow API. It needs API credentials on the worker and breaks the retry semantics of the unit tasks.
Decision¶
- Config:
ExecutionMode.WATCHER = "watcher". NewExecutionConfigfields:watcher_workers(--workersof the producer's run; None keeps the target's),watcher_poll_interval(10 seconds),watcher_timeout(86400 seconds: the producer'sexecution_timeoutand each watcher's deadline for one try) andwatcher_artifacts_root(an absolute path that overrides the root read at parse time).virtualenv_diris optional, as in VIRTUALENV. Watchers always defer, so there is no deferrable switch.RECHECK_S = 300andVISIBILITY_GRACE_S = 120are constants. PLA002 also covers a worker count below 1, a non-positive poll interval or timeout, and a WATCHER selection made only ofunit:selectors (the producer would run in unit mode). PLA007 is not reported: one process runs every unit. - Retries: the producer has Airflow
retries=0, because the core scheduler applies the model retries in process, and a producer try above 1 is skipped, so it runs once per DAG run. Each watcher gets the model'sretriesandretry_delay. A failure the producer already reported fails the watcher without a retry; a rerun's failure maps exit codes as LOCAL does. - Graph: the producer
pipeloom_runis a root task with no edge to the watchers. Watchers follow the plan edges, so a failed unit leaves its descendantsupstream_failed. Each watcher has one asset outlet per model, andgroup_bynests watchers.pipeloom_finalize(trigger ruleall_done) runs after the producer and every leaf. The producer'spriority_weightis the task count plus 2, withweight_rule="absolute", so it starts first. - Producer command:
python -m pipeloom run --log-format json, the project and plan arguments (--manifestin MANIFEST mode, always--expect-plan-hash), the rendered--selectand--exclude,--run-id,--run-started-at,--full-refresh, the orchestrator ids,--varsand--workerswhen set. An empty rendered selection is passed as--select name:*: a run without selectors keeps the selection a non-stable manifest recorded at compile time, while the DAG renders every unit. Exit 0 or 1 is a success (the results belong to the watchers; finalize fails the DAG run when the pipeloom run failed), onceruns/<run id>/run_results.jsonis visible under the resolved root within the grace, else PLA008. Exit 2 or 130 fails the producer. - Artifacts root: resolved at parse time from
<project_dir>/pipeloom.ymlread as plain YAML, as the core does:targets.<t>.artifactsreplaces the top-level block whole,rootfalls back totarget, and a relative root is joined to the execution project dir. An unreadablepipeloom.yml, or a${...}reference in the root without the override, is PLA008. The project is never bound on the worker for this (it would import user modules and break MANIFEST mode). The triggerer must mount the root at the same path. - Watcher state machine. Inputs are the unit's files and the producer's task state. The producer is in progress while its state is not terminal and the files hold no final verdict. At try 2 or later, when the producer is not in progress, the watcher reruns its unit (same run id, unit mode, one attempt). Otherwise the files decide: the latest attempt succeeded is a success; timed out or cancelled is a failure; failed with no retry left under the unit's policy (
should_retryof the core) is a failure. With no final attempt andrun_results.jsonpresent: askippedrow runs the unit here (its parent was rerun), acancelledrow is a failure, and a terminal row without its attempt file is invisible (PLA004 after the grace). With no results and the producer ended, PLA009 after the grace, which fails the try so a watcher with retries reruns the unit. Else the watcher defers. On success it logs the attempt summary and the tail of the unit's log; on failure the code, message and trace excerpt. - Trigger:
PipeloomWatcherTrigger(run_dir, unit_id, retries, retry_on, poll_interval, recheck_after)reads files only, every interval, in a thread. It yieldsdone,run,invisible(after the grace) or, afterrecheck_after,pending, on which the watcher checks the producer's state on a worker and defers again with the remaining deadline. The trigger never reads task states (a triggerer deadlock fixed in Airflow 3.2.2). - Shared storage: the watcher lists the unit folder and also opens
attempt-1up toattempt-<retries + 1>by name, since an NFS listing can lag behind a file. Partial or invalid JSON is not visible. Waiting is bounded by the grace. - Rerun and finalize: a unit invocation takes no lock and writes no results;
pipeloom_finalize, cleared with Downstream, merges the new attempt and overwrites the producer'srun_results.json. - Codes: PLA008 (WATCHER artifacts root not resolved) and PLA009 (WATCHER producer ended without run results).
- OpenLineage (ADR-0046): the producer's child carries the Airflow ids, so the
openlineagesink stays silent by default. Each watcher reports its unit to the Airflow provider through the operator hooks, with the static datasets of the manifest, as KUBERNETES does; a watcher that reruns its unit reports the facets of its own child, as LOCAL does. The producer reports nothing.
Consequences¶
- One process start per DAG run instead of one per unit, and the core scheduler's parallelism and in-process retries apply. Watchers hold triggerer slots, not worker slots, while they wait.
- The triggerer needs pipeloom-airflow and the artifacts root mounted at the same path as the workers. On NFS,
lookupcache=positiveand a lowacdirmaxkeep the grace short. - If a producer's worker dies, its child may keep running; PLA009 and a watcher retry can then run a unit twice.
- A watcher retry after a watch timeout can rerun a unit the producer finished meanwhile.
- To confirm on a live Airflow:
try_numberrises after a clear, anupstream_failedtask goes back to try 1, and a watcher can defer again fromexecute_complete.