LangGraph Crash Recovery with Automatic Checkpointing

Overview

When you use a checkpointer, LangGraph automatically saves state after every node execution, not just at interrupt points. This means if your program crashes at any time, you can resume from the last completed node.

The Key Concept

Automatic Checkpointing After Every Node - LangGraph continuously saves your workflow's state to SQLite (or another backend) after each node completes, enabling automatic crash recovery without any special code.


Complete Example: Crash Recovery


How It Works

First run (crashes at step 2):

At this point:

Second run (resumes from checkpoint):


Separate Script Approach (More Realistic)

workflow.py (the workflow definition):

run.py (the runner script):

Usage:


Real-World Example: Long-Running Data Pipeline


Key Points

  1. Automatic checkpointing: LangGraph saves state after EVERY node completes, not just at interrupt points

  2. No special code needed: You don't need to add checkpoint calls - it's automatic

  3. Resume detection: Check if state.next exists to detect incomplete workflows

  4. Thread ID is crucial: Same thread_id = same workflow instance

  5. Idempotent nodes: Design nodes to be safely re-runnable (avoid duplicate side effects)

  6. Only state data is saved, not LLMs: When your code restarts, it still needs to load and initialize any LLMs it uses. Checkpoints store serializable data (JSON-like structures). LLM objects, functions, and connections can't be serialized to JSON, so they must be recreated on restart.

    What IS saved in checkpoints: āœ… State data (strings, numbers, lists, dicts, simple objects) āœ… Which node to execute next āœ… Conversation history / messages āœ… Variables and results from completed nodes What is NOT saved: āŒ LLM instances (model objects) āŒ Function definitions āŒ Tools āŒ Database connections āŒ File handles āŒ Any non-serializable objects


Inspecting Checkpoints Manually


Production Patterns

Cron job that's crash-resistant:

Kubernetes job with restarts:

The workflow will automatically resume from the last checkpoint after each restart.


Bottom Line

With SQLite checkpointing, your LangGraph workflow is automatically crash-resistant:

  1. State is saved after every node

  2. On restart, check if there's existing state

  3. If yes, resume with invoke(None, config)

  4. No special interrupt code needed

This works for crashes from:


Checkpointer Options

MemorySaver (Development)

SqliteSaver (Production - Single Machine)

PostgresSaver (Production - Distributed)


Additional Resources