ADR-0035: Databricks rendering and job lifecycle¶
Context¶
pipeloom 0.5 deploys a plan as a Databricks job. ADR-0011 sketched the job shape and ADR-0012 the orchestrator modes, and both left facts to verify. ADR-0034 gave the core the hooks (a deploy block, a stable manifest, plugin commands, pipeloom finalize). This ADR covers the plugin side. It is written in halves: the first is rendering, which is pure and needs no workspace, and the wrapper and bundle command that need none either; the second half (deploy, run, repair, find by tag, upload) arrives with the client and amends this record. It amends ADR-0011 and ADR-0012.
Facts checked against the public Jobs API documentation: a task key is 1 to 100 characters of [A-Za-z0-9_-]; jobs/create, reset, update and runs/submit all accept at most 1,000 tasks; a job has at most 10 environments; an environment has an environment_version (a string, 1 to 6) and dependencies; a job run's result comes from its leaf tasks.
Options¶
- A
databricksexecutor. ADR-0020 picks executors by boundary, and Databricks is an orchestrator, not a boundary. Rejected. - Per-model compute as a model key. Compute is a runtime setting a target may override, so a model key would need its own precedence. Rejected for target-level
compute_ruleswith selectors. - Grouping only above the task limit. The shape of the job would change when the 1,001st model is added. Rejected: grouping applies whenever
task_groupingis set. - Tasks call the core CLI directly. Needs an environment where the
pipeloomscript exists, and cannot turn a start time or an empty run id into arguments. Rejected for a plugin wrapper entry point. - Rendering through the SDK dataclasses. They lag the API and drop fields such as
environment_version. Rejected for stdlib frozen dataclasses that mirror the subset we use.
Decision¶
The plugin pipeloom-databricks registers the databricks kind in the renderers group. Its options (DatabricksDeployOptions) are the validated deploy block: pipelines (each a selection of units and one job), named computes (serverless or job_cluster), compute_rules (the first matching rule wins), task_grouping (none, by_tag, by_folder) and passthrough job settings. The spec imports no Databricks or Spark library. Rendering is a pure function of the plan, the options and a few locations the caller supplies (project root, manifest path, the target's artifacts root, whether its state store is shared, cancel_grace); the core needs no new input for it.
A job is named pipeloom_<project>_<pipeline>_<target> and carries the tags pipeloom_job (<project>.<pipeline>.<target>), pipeloom_plan_hash, pipeloom_settings_hash (sha256 of the canonical settings without that tag) and pipeloom_version. User tags are merged and ours win. Equal settings hashes mean a deploy is a no-op.
Tasks run a plugin wrapper: python_wheel_task with package pipeloom_databricks and entry point pipeloom_databricks_task. Parameters are --opt=value strings, so an empty value stays one argument. They carry dynamic references ({{job.parameters.pipeloom_run_id}}, {{job.id}}, {{task.name}}, {{job.start_time.timestamp_ms}}); the start time is passed as milliseconds because the iso_datetime format is undocumented. A one-time run (runs/submit) gets the run id, the full-refresh flag and the start time as literals and no job references. It may use serverless compute only.
Each unit is a task named by its unit id; with grouping, a group is a task named tag_<first tag> (tag_untagged) or dir_<folder of the model file> (dir_root). Group dependencies come from unit parents; groups that wait for each other are PLD003. A group must run on one compute. A finalize task, pipeloom__finalize, depends on every leaf, runs with run_if: ALL_DONE, one retry and a 1,800 s timeout, on the default compute. Tasks are sorted by key, finalize last. Retries and the retry delay are the model's (a group takes the largest); timeout_seconds is the model timeout plus cancel_grace plus 300 s, summed over a group whose every member has a timeout. Serverless tasks set disable_auto_optimization: true, because auto-optimization retries a failed task on top of max_retries (found by the live workflow, amended 2026-11-05).
Task keys replace characters outside [A-Za-z0-9_-] with _. A key above 100 characters, a key shared by several ids and a key equal to the finalize key are shortened to 91 characters, _ and 8 hex characters of the sha256 of the raw id; every id in a collision gets the suffix, so keys do not depend on order. A job above 1,000 tasks, finalize included, is PLD001 with a hint to set task_grouping or split pipelines. PLD002 stays reserved and is never emitted, because submit and create share the limit. Invalid options for the plan or target are PLD004 (environment version 1, an unknown compute, more than 10 serverless environments, a key in settings that pipeloom owns (name too) or a pipeloom_ tag, a ${secret: reference, an artifacts root that is unset or relative, a state store that is not shared, a group on two computes, an ephemeral run on a job cluster, an unknown pipeline or one that selects no unit). A compute rule that matches no model is the warning PLD005.
The wrapper (pipeloom_databricks.task, a [project.scripts] entry plus a lazy function of the same name in the package, so both Databricks lookups find it) has the subcommands unit and finalize. It rejects any parameter that still holds {{ (PLD013, exit 1), turns an empty run id into dbx-<job run id>, turns the run start into --run-started-at (the job run's start_time from the Jobs API, falling back to start_ms with a warning when the call fails or the run is one-time: the live workflow showed that {{job.start_time}} is the start of the latest repair, so a repaired task would otherwise fail with PLX108; amended 2026-11-05), and calls pipeloom run or pipeloom finalize in the same process, so an active Spark session stays the active one. A group task recomputes its members with build_tasks from the shipped manifest (an unknown group exits 1). It passes databricks_job_id, databricks_job_run_id, databricks_task_key and databricks_task_run_id as orchestrator ids and exits with the core's code. Finalize scopes the run to the units of its pipeline, spelled as unit: selectors, because the shipped manifest has an empty selection and a bare finalize --manifest would scope no unit.
After a unit task the wrapper sets the task value pipeloom (v, run_id, status and, per unit, status, attempt, rows written, duration, target version, error code and warning count) read from the newest attempt files. Above 32,768 bytes units are dropped from the end and truncated is true. Task values are documented for notebooks only, so setting one is best effort: a failure prints one line on stderr and never changes the exit code. Only task_values.py (with the client modules) imports databricks.sdk, and only on a Databricks runtime.
pipeloom databricks bundle --target T --out DIR [--pipeline NAME]... [--bundle-root PATH] [--check] writes, per pipeline, pipeloom_<project>_<pipeline>_<target>.job.yml (with a header comment saying it is generated) and the stable .manifest.json into a bundle. Paths are bundle variables: ${workspace.file_path}/<project dir relative to the bundle root> and ${workspace.file_path}/<out relative to the bundle root>/<file>. The bundle root is --bundle-root or the nearest folder above --out with databricks.yml; none, or a project or output folder outside it, is exit 2. --check writes nothing and exits 1 listing the files that differ. The plugin registers the group in pipeloom.commands.
Amended 2026-11-20 (Databricks CLI versions). Databricks CLI 1.3.0 made the direct deployment engine GA and the default, and 1.20.0 removed the Terraform engine. The golden job files were checked with databricks bundle validate on CLI 1.18.0 and raise no unknown-field warning; the fields are Jobs API fields that both engines accept. The command writes no bundle.databricks_cli_version: pipeloom has no technical need for a floor, one would make bundle validate fail on older CLIs whose bundles work today (a break for a minor release under ADR-0016), and an included file overrides the root's value, so it would also loosen a range the user set in databricks.yml. Users who want a floor set it there. pipeloom never invokes the CLI, so there is no runtime version check and no diagnostic code.
pipeloom_databricks.testing.jobsim.simulate_job runs a rendered job locally: it substitutes the references, runs the tasks in dependency order through the wrapper, and honors run_if, only and a repair (rerun). The Spark engine's active mode, when DATABRICKS_RUNTIME_VERSION is set and no session is active, attaches with builder.getOrCreate() and no conf, because a wheel task starts without a session; it never configures or stops that session.
Run, repair and finalize states (second half). run finds the job by tag and compares its pipeloom_settings_hash tag with the local render: a missing job is PLD007 and a different hash PLD008, unless --ensure deploys first. --select and --exclude resolve on the plan, intersect the pipeline's units and become only (task keys, groups deduplicated, plus finalize); a partly selected group runs whole with a warning, and an empty selection is exit 2. With --run-id the start carries idempotency_token = sha256("<job_id>:<run_id>"). --ephemeral uploads as deploy does and submits with the token sha256(run_id); a selection prunes the submitted tasks and finalize waits for the selection's leaves. A repair of a finished run reruns tasks that ended FAILED, TIMEDOUT, CANCELED, UPSTREAM_FAILED, UPSTREAM_CANCELED or MAXIMUM_CONCURRENT_RUNS_REACHED plus finalize, passes latest_repair_id from the run history and the run's job parameters (without them {{job.parameters.pipeloom_run_id}} resolves to its empty default and the repair starts a new pipeloom run; amended 2026-11-05), and a run still active is PLD014. After a repair --wait keeps polling until the run reports the new repair id. The finalize wrapper calls connect(profile=None, env=os.environ) and get_run, and maps each unit without an attempt file: EXCLUDED and DISABLED (what serverless reports for a task left out by only) to excluded, UPSTREAM_FAILED and UPSTREAM_CANCELED to skipped (upstream_failed), CANCELED and TIMEDOUT to cancelled, FAILED to failed with PLD011 and the termination message. The map goes to core as --unit-states. A client error prints one warning and passes no states, so those units count as not run. A one-time run has no job run id in its task parameters, so its finalize asks for nothing.
Output is byte-deterministic: JSON with 2-space indent, ASCII only and LF, keys in field order; bundle YAML from yaml.safe_dump without key sorting. Environment dependencies default to the pinned distributions (pipeloom, pipeloom-databricks and every plugin in the plan, name==version, sorted).
Consequences¶
The job is a plain JSON document that a person can read, diff and send to the Jobs API unchanged, and rendering is testable with goldens and no workspace. The renderer needs three inputs the plan does not hold (artifacts root, state sharing, cancel grace), which the caller reads from the bound target. Tasks of a pipeline ignore dependencies on units outside it. Platform behaviors that only a live run can confirm (references in wheel task parameters, only with an ALL_DONE finalize) are guarded by the wrapper and checked by the manual workflow, not here.
Status¶
Accepted (first half: rendering, wrapper and bundle command; second half: run, repair and finalize states). Amended in 0.9 by ADR-0050.
Date¶
2026-11-05
Amendment 0.9 (ADR-0050)¶
With Python-first authoring (ADR-0050) the upload set of deploy and run --ephemeral is pipeloom.yml, the .py file of every node, every *.py under python_paths, the properties YAML files under model_paths (not read at run time, uploaded so the folder mirrors the project) and the stable manifest. A task never runs discovery: it imports the one module named by the node's callable. Modules found through model_packages are not uploaded; they must be installed in the job environment (for example through the compute's dependencies), and the plugin guide says so.