cancel
Showing results for 
Search instead for 
Did you mean: 
Technical Blog
Explore in-depth articles, tutorials, and insights on data analytics and machine learning in the Databricks Technical Blog. Stay updated on industry trends, best practices, and advanced techniques.
cancel
Showing results for 
Search instead for 
Did you mean: 
sbanchik
Databricks Employee
Databricks Employee

Serverless jobs make it easy to run production notebook workloads at scale, but until now, the state of a run was gone once it ended. If a pipeline ran for hours and failed on the last step, the variables, DataFrames, and other intermediate state you needed to investigate were no longer available. Debugging meant rerunning the upstream work, and waiting just to recreate the context of the original run.

With session restore for serverless jobs, Databricks preserves the Python and Spark state from an eligible run and lets you reopen it in an interactive notebook. Instead of reproducing the run, you can continue from where it ended: inspect variables and DataFrames, debug a failure, or explore results that were never written to a table, without rerunning the job.

jobsforklowquality.gif

Restoring a job run in a notebook

When a run is eligible, the job run page surfaces an action to bring that run into an interactive notebook. For a failed run, choose Debug in new notebook to land directly at the point of failure. For a successful run, choose Clone into new notebook to keep exploring from where the run left off. Either way, Databricks creates a new notebook, an independent copy that never touches your production notebook or job, attaches it to serverless compute, and restores the run's state, typically in seconds.

Traditionally, reopening a job's work meant re-running every setup cell: imports, class definitions, UDFs, temp views, and Spark configs, and then re-executing the expensive steps to rebuild the data. With session restore, Databricks reinstates the run's working environment, including:

  • Python variables, functions, classes, and imported modules: the Python side of the run is preserved, so you don't need to re-import or redeclare anything to start inspecting.
  • In-memory Spark DataFrames, cached data, and temporary views: data the run loaded, transformed, or cached, including temporary tables and views, is still there, so you avoid costly reloading and recomputation.
  • Spark session state, including configs, temporary variables, and catalog entries: session-level settings and catalog modifications are kept, so the environment behaves exactly as it did in the run.

Session restore also gives Genie Code a much better starting point for debugging. When a serverless job fails, Genie Code can investigate from the state the run left behind rather than trying to reconstruct what happened from the code alone. You can ask it to trace the failure, inspect intermediate results, and test a fix in the cloned notebook, then bring the change back to your job when you're ready.

jobsforkgenielowqual.gif

Under the hood: how session restore works

Serverless jobs tear down their compute as soon as a run completes. Session restore captures the run's state just before that teardown, then reconstructs it on demand.

  1. Snapshot before teardown: as an eligible notebook task finishes, and before serverless compute and the session are cleaned up, Jobs asks the driver to snapshot that task's execution context.
  2. Capture Python and Spark state: the Python REPL globals are serialized, including variables, functions, classes, and imported modules. Spark session metadata is captured alongside so the session can be reconnected later.
  3. Persist a compressed snapshot: the snapshot is compressed and uploaded to workspace storage. A lightweight pointer to the snapshot, plus the Spark session metadata, is stored with the job run's metadata for later retrieval.
  4. Restore into a new notebook: when you open the run and it attaches to serverless compute, the restore manager downloads and extracts the snapshot, waits for the REPL to become idle, restores the Python namespace, and restores the Spark session from the saved metadata.

The result: the run's full environment is reconstructed in a fresh notebook, and you pick up right where it ended.

Eligibility and current limitations

Session restore is available for notebook tasks running on serverless compute (environment version 5 or higher). State is captured automatically when a run:

  • fails,
  • runs for at least 30 minutes (measured by execution time, excluding time spent waiting for compute), or
  • is cancelled or times out.

A few things to keep in mind:

  • Snapshots are retained for 7 days after the run completes.
  • Only the job's run-as user can restore the state.
  • State tied to process-level I/O, such as file handles, locks, or open network connections, may not be restored. Values passed from upstream tasks may also be unavailable when the notebook is opened outside the workflow.
  • Session restore is not a job retry and does not replace your production notebook. The restored notebook is an independent copy for debugging and analysis.

What's next?

We're actively exploring how to make session restore even more useful:

  • Support for more serverless workloads: We’re exploring extending it to additional serverless workload types, including serverless GPU workloads for machine learning.
  • Longer retention: exploring whether to extend how long snapshots are kept beyond the current window.
  • A smoother path back to your job: because restore opens the run in a new, independent notebook, getting your fixes back into the original job is manual today. We want to make reconnecting a debugged clone to its source job a single step.

Try it today

Session restore for serverless jobs is available in Public Preview. Workspace admins can enable it from the Previews page, and eligible serverless job runs will begin capturing state automatically. To learn more, see the scheduled notebook jobs documentation: https://docs.databricks.com/aws/en/notebooks/schedule-notebook-jobs#session-restore-for-serverless-j...

Screenshot 2026-10-01 at 1.25.45 PM.png