Sub topic 14
Repairing a Failed Run
This chapter assumes you can build a multi-task job with dependencies, and that you know how retries, timeouts, and failure notifications work. It covers what to do after a run has failed: how to rerun only the work that did not succeed.
Why repair exists
A multi-task job run is a graph of task runs. When one task fails, its downstream tasks usually do not run. Their status is "Upstream failed" or "Excluded". Tasks that already succeeded keep their results.
Starting a new run would repeat all the work, including the expensive tasks that already finished. A repair run instead reruns only the failed tasks and the tasks that depend on them. Tasks that succeeded are not rerun.
Consider the three-task pipeline from earlier chapters: ingest, transform, publish. Suppose ingest succeeds, transform fails because of a bad column name, and publish is skipped. After you fix the notebook, a repair reruns transform and publish. It does not rerun ingest.
What a repair does
A repair belongs to the original run. It does not create a new run ID. Each repair adds an entry to the run's repair history, and the run page shows the attempts as a history of that run.
Key behaviors:
- Successful tasks keep their output and are not executed again.
- Failed, canceled, timed-out, and skipped tasks are the usual candidates for rerun.
- Tasks that depend on a rerun task are rerun too, because their inputs may change.
- The run uses the job's current task definitions for the tasks it reruns, unless you change them first. Fix the notebook, or edit the task settings, before you repair.
- Task values set by successful tasks stay available to the rerun tasks, so a downstream task can still read
{{tasks.ingest.values.row_count}}.
Repairing from the UI
- Open the job and select the failed run from the Runs tab.
- Fix the cause of the failure. This might be a notebook change, a cluster setting, or a missing input table.
- Choose Repair run.
- Review the list of tasks. Failed tasks are preselected. You can add or remove tasks from the list.
- Optionally change the parameters for the repair.
- Confirm. The repair starts and the run status returns to running.
Repair is available only when the run has finished. It is not available while the run is still active. A run that is still in progress needs to be canceled or allowed to finish first.
Repairing with the API
The Jobs API has a repair endpoint, POST /api/2.1/jobs/runs/repair. You send the run ID and the task keys to rerun.
import os
import requests
host = os.environ["DATABRICKS_HOST"]
token = os.environ["DATABRICKS_TOKEN"]
response = requests.post(
f"{host}/api/2.1/jobs/runs/repair",
headers={"Authorization": f"Bearer {token}"},
json={
"run_id": 123456,
"rerun_tasks": ["transform", "publish"],
},
timeout=30,
)
response.raise_for_status()
print(response.json())The response contains a repair_id. Use it to identify this attempt in the run's repair history.
Other request fields are worth knowing:
| Field | Purpose |
|---|---|
| `rerun_tasks` | List of task keys to rerun. |
| `rerun_all_failed_tasks` | If `true`, reruns every failed task. Do not combine it with `rerun_tasks`. |
| `rerun_dependent_tasks` | If `true`, also reruns tasks that depend on the listed tasks. |
| `latest_repair_id` | The ID of the most recent repair. Needed on repeat repairs. |
| Parameter overrides | Values that replace job or task parameters for this repair only. |
If you only want the failed tasks, rerun_all_failed_tasks is the simplest option. If you list specific tasks, name them by task_key.
import os
import requests
host = os.environ["DATABRICKS_HOST"]
token = os.environ["DATABRICKS_TOKEN"]
response = requests.post(
f"{host}/api/2.1/jobs/runs/repair",
headers={"Authorization": f"Bearer {token}"},
json={"run_id": 123456, "rerun_all_failed_tasks": True},
timeout=30,
)
response.raise_for_status()
print(response.json())Repeat repairs and `latest_repair_id`
A run can be repaired more than once. The API uses latest_repair_id to guard against two people repairing the same run at once. When the run has already been repaired, you must send the ID of the latest repair. If the ID is stale, the request is rejected. Fetch the run with GET /api/2.1/jobs/runs/get and read its repair_history to find the current ID, then retry.
Choosing between repair and a new run
| Situation | Better choice |
|---|---|
| One task failed, earlier tasks are fine | Repair |
| Input data changed and everything must be recomputed | New run |
| The failure came from a transient cluster problem | Repair |
| You need a different job-level parameter for all tasks | New run |
| The run was canceled midway | Repair |
A repair is a good fit when upstream outputs are still valid. It is a poor fit when the upstream results are now wrong, because repair keeps them.
Edge cases and gotchas
Time-dependent logic
Repaired tasks run later than the original schedule. A notebook that uses the current date, such as current_date(), will see the repair date, not the original run date. This can write data to the wrong partition. Pass the logical date as a parameter, for example {{job.trigger.time.iso_date}}, and let the notebook use it. The dynamic value for trigger time reflects the original trigger, so a repair keeps the intended date.
Non-idempotent tasks
A failed task may have done part of its work before it failed. A repair runs it again from the start. If the task appends rows, you can get duplicates. Design tasks to be idempotent, meaning that running them twice gives the same result as running them once. Use MERGE, overwrite a single partition, or write to a staging table and swap it in.
Retries are separate from repair
Retries happen automatically inside one task run, before the task is marked failed. A repair is a manual step after the task has failed for good. A repair does not reset the retry count in a way you should depend on. Treat a repaired task as a fresh attempt with the task's configured retry policy.
Concurrency limits
A repair counts as an active run. If max_concurrent_runs is 1 and the next scheduled run starts while your repair is still running, the new run is skipped. Check the concurrency setting before repairing close to a scheduled time.
Downstream `run_if` rules
If a downstream task uses run_if such as ALL_DONE or AT_LEAST_ONE_FAILED, it may already have run in the original attempt. A repair reruns it only if it is in your list of tasks, or if you request dependent tasks. Check that cleanup tasks do not run twice in a harmful way.
Job-level changes
If you change the job's schedule or notifications, the repair does not use them retroactively. If you change a task's compute, the repaired task uses the new compute.
Notifications and the repair history
A repair that fails sends failure notifications again, following the job's notification settings. In the run page, the repair history lists each attempt with its start time, end time, and status, so you can see which attempt produced the final result. Use this when you audit a pipeline that "succeeded" only after two repairs.
Exercise
A run of a three-task job (ingest, transform, publish) failed in transform after ingest succeeded. You fixed the transform notebook. Name the tasks a repair reruns, say whether the run ID changes, and explain one risk if transform appends rows to a table.
Show answer
The repair reruns transform and publish, because publish depends on transform. It does not rerun ingest. The run ID stays the same, and the repair is recorded in the run's repair history. If transform appends rows and had already written some before it failed, the rerun appends them again and creates duplicates. Making the task idempotent, for example with MERGE or a partition overwrite, avoids this.
Exercise
You call the repair endpoint for a run that was already repaired once, and the request is rejected. What is the most likely cause, and how do you fix it?
Show answer
The request probably omitted latestrepairid or sent a stale one. Read the run's repairhistory from the runs get endpoint, take the ID of the most recent repair, send it as latestrepair_id, and retry.