# How Do Long-Running Agents Use Checkpoints?

> How agents save checkpoints during long jobs, what those saves cover and miss, and how to resume safely, explained simply for your AI interview.

**In short:** A checkpoint is a saved record of an agent's progress at a safe point, so a long job that crashes can resume from its last save instead of starting over. The record must sit in durable storage, and it cannot undo actions the agent already took outside its saved state, such as an email sent.

AI and LLM interview question Q182, Agents and tool use. Advanced, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-long-running-agents-use-checkpoints

## Say it in 30 seconds

A checkpoint is a saved record of an agent's progress at a safe point. A long job, like moving forty thousand claims over a weekend, saves after each finished claim. If the server crashes, the restart reads the last record and carries on from there. The record must live somewhere durable, such as a database or a disk, not in memory. It can't undo things the agent already did outside its saved state, like an email sent, so I check those before any retry.

## Say it in 2 minutes

Long-running agents are AI jobs that work for minutes, hours or days. They can crash, time out, or be told to slow down by a service, so they need a way to pick up where they stopped. A checkpoint is a saved record of progress, such as the step number, the results so far and the next action. Think of a court clerk who writes the orders and the next hearing date into the case file, so the next session starts from that file.

Here is the AI case. An agent moves forty thousand insurance claims into a new system over a weekend, at about two seconds each. After each finished claim it writes a record to a database. The server restarts just after claim 27,410. The agent reads the record, checks the new system for claim 27,411, and carries on. Without the record, it would start again and could move some claims twice.

Two details matter in an interview. The record must live in durable storage, because a record kept in memory loses everything when the program restarts. And a checkpoint can't undo things done outside its saved state. Restoring files does not reverse an email already sent or a payment already made, so those actions need their own IDs and a check before any retry.

Long runs also need upkeep. Old checkpoints pile up, so I set a rule that deletes old ones on a schedule. For anything that moves money or sends mail, I ask a person to confirm first.

## What is a checkpoint, in plain words?

A long-running agent is an AI job that keeps working for minutes, hours or days. It might move a backlog of records, run a large test suite or watch a queue. Such a job can crash, time out, or hit a rate limit (a service asking it to slow down) halfway through, so it needs a way to pick up where it stopped.

A checkpoint is a saved record of that progress, taken at a safe point. The record holds what the next run needs: the step number, the results so far and the next action. It is written somewhere that survives a restart.

Think of a court clerk. At the end of each hearing, the clerk writes the orders made and the next date into the case file. The next session reads the file and picks up there, so nobody re-argues the first day.

Here is the AI version. An agent moves forty thousand insurance claims into a new system over a weekend, one claim at a time. After each finished claim it saves a checkpoint. If the server crashes, the restart reads the last record and carries on with the next claim.

- **Checkpoint:** A saved record of progress, taken at a safe point, so a run can resume.
- **Durable storage:** A place that keeps data after the program stops, such as a database or a disk.
- **Resume:** Carry on from a saved point, not from step one.
- **Side effect:** Something that happens outside the agent's own memory, like an email sent or a payment made.
- **Process memory:** The program's own working memory. A restart wipes it.

## How does a checkpoint work during a long run?

The agent saves at a safe point: after a step has finished and its result is written down. Saving halfway through a step can store half a change, and the restart would then repeat that change or skip it.

1. **Pick the save points:** Save after each finished unit of work, such as one claim or one test file.
2. **Write a small record:** Store the step number, the results so far, the next action and the IDs of items already done.
3. **Store it somewhere durable:** A database or a disk survives a restart. Process memory does not.
4. **Load the last record on restart:** The agent reads it, checks that the outside world matches it, then carries on from the next step.

*Diagram, One long run with checkpoints: One run of the claims job. Each finished claim is saved as a checkpoint. When the server crashes, the restart reads the last record and resumes at the next claim, so the finished claims are not moved again.*
1. The job starts with the full list of claims.
2. Each claim is checked, then its record is saved.
3. The record goes to a database, so it survives a restart.
4. The crash ends the run. The restart begins from the last saved record.
5. The restart reads the last record and carries on from the next claim.

With made-up numbers: at about two seconds a claim, 40,000 claims take roughly 22 hours. A crash at hour 15 with no checkpoint means 15 hours of work is redone. With a checkpoint after each claim, the redo is one claim, the one in progress, which the agent checks before it retries.

Here it is in plain Python. A JSON file stands in for durable storage, and a simulated crash stops the run at claim 5.

```python
# A simplified claims mover. A JSON file stands in for durable storage. Rewrites the whole list each step: fine for a demo, not for 40,000 claims.
import json, os, tempfile

STORE = os.path.join(tempfile.mkdtemp(), "checkpoint.json")

def save(step, moved):
    with open(STORE, "w") as f:
        json.dump({"step": step, "moved": moved}, f)

def load():
    if not os.path.exists(STORE):
        return {"step": 0, "moved": []}
    with open(STORE) as f:
        return json.load(f)

def run(claims, crash_at=None):
    state = load()
    for step in range(state["step"], len(claims)):
        if step == crash_at:
            return "CRASHED before claim " + str(step + 1)
        state["moved"].append(claims[step])
        save(step + 1, state["moved"])
    return "DONE: " + str(len(state["moved"])) + " claims moved"

claims = ["CL-%04d" % n for n in range(1, 7)]
print(run(claims, crash_at=4))
print(run(claims))
```

Output:

```text
CRASHED before claim 5
DONE: 6 claims moved
```

## What kinds of checkpoint are there, and where are they kept?

Three ways agents keep a record of progress show up in real tools, and each saves a different thing, so pick the one that matches what the agent changes.

- **Agent state: Saved run state.** LangGraph, an agent framework, saves each run's state as checkpoints, so a run can resume after an interruption or a failure.
- **Files: File snapshots.** The Claude Agent SDK backs up the files that its Write, Edit and NotebookEdit tools (ways an agent edits files) change, then rewinds them on request.
- **Code: Git commits.** Anthropic's coding harness asks the agent to commit its progress to git, so git can revert a bad change.

*Diagram, Where the checkpoint is kept: The same record, kept in two places. Process memory is quick, but a restart clears it, so the job starts again. A database or a disk survives the restart, so the job resumes where it stopped.*
1. Option one: the record stays in the program's memory.
2. Option two: the record goes to a database or a disk.
3. A restart clears memory, so the job starts from the beginning.
4. The database still has the record, so the job resumes.

LangGraph's guide makes the same point about its in-memory option:

> "MemorySaver and InMemorySaver store checkpoints in RAM. When the process restarts, all checkpoints are lost." (LangChain, LangGraph persistence)

## What can a checkpoint not undo?

A checkpoint puts back the agent's saved state. It cannot pull back what already happened outside that state.

> "File rewinding restores files on disk to a previous state. It does not rewind the conversation itself." (Claude Agent SDK, file checkpointing)

The SDK's own limits list makes the gaps concrete. Rewinding does not undo changes a shell command (Bash) made, except in files the main conversation had already edited with Write or Edit. It also does not undo creating, moving or deleting directories. Checkpoints are tied to the session that made them, meaning one conversation with the agent.

1. **Sent emails and payments:** Restoring the saved state does not recall an email or a payment. Give each action its own ID, check it before any retry, and ask a person before money moves or mail goes out.
2. **Checkpoints kept in memory:** They vanish on restart, so the record must sit in a database or on disk.
3. **Piles of old records:** Long conversations make many checkpoints. LangGraph's guide notes they can slow the run down and take up storage, so prune them on a schedule.

> **Tip:** Don't say a checkpoint makes a job safe. Say it limits repeated work, then name the actions it cannot undo and how you check them.

### How would you make a claims agent safe to restart?

Say the agent moves insurance claims between two systems, and some of those moves trigger payments. My plan has five parts.

1. **Save after each confirmed claim:** The record holds the claim ID and the step number, and it is written only once the new system confirms the move.
2. **Keep the record in a database:** A restart on a different server must still find it.
3. **Check before every retry:** On restart, look up the claim in the new system first. If it is already there, mark it done and move on.
4. **Gate the payments:** Each payment carries an ID and waits for a person's approval, so a repeated run cannot pay twice.
5. **Break it on purpose:** Stop the job at random points in a test run, restart it, and confirm the final count is exactly 40,000.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a saved record of progress that a run resumes from.
- [ ] Where it lives: durable storage, not process memory.
- [ ] What it covers: agent state, files or git commits, depending on the tool.
- [ ] What it cannot undo: sent emails, payments and changes in other systems.
- [ ] Safe restarts: check before a retry, and give actions their own IDs.
- [ ] Upkeep: prune old checkpoints on a schedule.

**Common traps**

- Trap: "A checkpoint means the job can never repeat work." Better: It limits repeated work. Actions outside the saved state can still repeat, so check them first.
- Trap: "Keeping it in a variable is enough." Better: A variable lives in process memory and dies with the process. Store the record in a database.
- Trap: "Rewinding the files also rewinds the chat." Better: File rewinding leaves the conversation intact, so the agent still remembers what it tried.

## Can you spot the unsafe checkpoint?

**Spot the unsafe checkpoint:** The job runs on a server that can restart at any time. Which loop is safe to resume after a crash?

A. claims = load()  # the job keeps its place in memory only
for c in claims: move(c)
B. for c in claims: save_checkpoint(c.id); move(c)  # saved before the move
C. for n, c in enumerate(claims): move(c); save_to_db(c.id, step=n)  # saved in a database after the move is confirmed
D. for c in claims: move(c); save_to_ram(c.id)  # fast, no disk write

**Answer:** C. Only this one saves to durable storage after the move is confirmed. A crash in the short gap can repeat one claim, which the check before a retry catches. Saving first would mark claims done that never moved.

**Quick check:** The process restarts. Its memory is empty, but the checkpoint is in a database. What should the agent do first?

A. Start again from claim 1 to be safe
B. Read the last checkpoint and check the claim in progress before it retries
C. Ask the model to guess where it stopped
D. Switch to a bigger model, then restart

**Answer:** B. The database record says where to resume, and the check stops a claim from being moved twice. Starting from claim 1 repeats work already done, and asking the model to guess ignores a saved record.

## Can you answer these from memory?

**Flash cards**

- **What is a checkpoint?** A saved record of an agent's progress at a safe point, used to resume.
- **Where should it be kept?** Durable storage such as a database or disk. Process memory is lost on restart.
- **Does rewinding files undo the chat?** No. File rewinding restores files on disk and leaves the conversation as it was.
- **What can't a checkpoint undo?** Side effects outside saved state: sent emails, payments, changes in other systems.
- **Why save after a finished step?** A half-done step can store half a change, and the restart then repeats it.
- **What stops checkpoints piling up?** A cleanup rule: delete old checkpoints on a schedule.

## Likely follow-up questions

- Q184 How do you manage agent state? https://designervenkat.online/interview/ai/how-do-you-manage-agent-state
- Q173 How do you stop endless agent loops? https://designervenkat.online/interview/ai/how-do-you-stop-endless-agent-loops
- Q176 How should an agent handle tool errors and retries? https://designervenkat.online/interview/ai/how-should-an-agent-handle-tool-errors-and-retries
- Q174 What are common agent failure modes? https://designervenkat.online/interview/ai/common-ai-agent-failure-modes
- Q190 How do you trace and debug an agent run? https://designervenkat.online/interview/ai/how-do-you-trace-and-debug-an-agent-run
