Skip to content
AgenticAIWiki
  1. Learn
  2. Part 9
  3. 52. Graph-based orchestration
  4. 52.4

Lesson 52.4 · 4 of 6 · 7 min read · Reviewed 24 Nov 2026

Interrupt, inspect and resume

By the end, you can

  • Use checkpoints to pause a graph run, inspect its state and resume it.
  • Place an interrupt before a risky node and keep side effects safe on resume.

Because a graph run is just “current node plus state”, you can save it, stop, and carry on later. That simple fact gives you human approval, crash recovery and debugging in one mechanism.

Checkpoints

A checkpointer writes the state to storage after each node finishes, with:

  • a thread id (or run id) naming the run;
  • the next node to execute;
  • the state at that moment.

Storage can be memory for tests, or a database for production. To continue a run, you load the latest checkpoint for its thread id and keep going from the saved next node.

Interrupts

An interrupt is a planned pause. You mark a node, such as merge, as one that needs outside input. When the run reaches it, the runtime saves a checkpoint and returns control to your app instead of running the node.

Your app then shows the reviewer what is about to happen:

Run 7f2: waiting before merge
  branch:   fix-discount
  tests:    14 passed, 0 failed
  diff:     +12 -3 in pricing.py
  [Approve]  [Reject]  [Edit and approve]

The person’s answer is written into the state (approved: true), and the run resumesSession resumption: Continuing an earlier session by reloading its saved history or state.. If they reject it, a router can send the run back to fix with their comment in the state.

This is the human-in-the-loopHuman-in-the-loop: A design where a person reviews, approves or corrects AI decisions at defined points. checkpoint from 37.2, built into the graph rather than bolted on.

Inspect and edit

While paused, the state is just data, so you can:

  • inspect it: the plan, the code, every test result;
  • edit it: correct a wrong field, add a reviewer note, tighten the task;
  • replay from an earlier checkpoint: rewind to before a bad step and try again. Some frameworks call this time travel.

Editing state is powerful, so log every manual change with who made it and why.

Make side effects safe to repeat

A crash can happen after a node’s side effect but before its checkpoint is saved. On resume, the node runs again. Design for that:

Node Risk on repeat Guard
Send email Two emails Record a message id in state; skip if present
Create a ticket Duplicate ticket Use an idempotency key
Merge a branch Second merge fails or doubles Check whether it is already merged first
Run tests None Safe to repeat

Put the side effect in its own small node, right after the interrupt, so the approval and the action sit next to each other in the traceTrace: A record of everything that happened during one request or agent run, as a tree of timed steps..

When to use it

  • Any node that is irreversible, costly or visible to others: put an interrupt before it.
  • Long runs that may outlive a process: checkpoint every node.
  • Debugging: load the checkpoint just before a failure and step through.

Common mistakes

  • Unserialisable state. A database connection in the state can’t be saved. Store ids, not objects.
  • Approval with no context. “Approve step 6?” gets clicked blindly. Show the diff and the test results.
  • Interrupts everywhere. Pausing before every node causes approval fatigue. Pause only where it matters.

Key points

  • A checkpointer saves the state after every node, keyed by a run or thread id, so a run can stop and continue later.
  • An interrupt pauses the run before (or inside) a node and waits for outside input, typically a human approval.
  • While paused, a person can inspect the state, edit it, and then resume from the same point.
  • Nodes with side effects must be safe to run again, because a resumed or replayed run may repeat them.
Hands-on labRuns in the Playground

Pause before merge and resume safely

Checkpoint a graph run, pause it before a risky node, resume after approval, and make the side effect safe to repeat.

You will have: A checkpointing runner with an interrupt before merge and an idempotent merge node.

Steps

  1. Run the starter: the run pauses, but it can never get past merge and the duplicate resume would merge again.
  2. After the simulated restart, load the checkpoint, show the reviewer the state, and record the approval.
  3. Resume from the checkpoint and let merge run.
  4. Make merge record a merge_id and skip if one already exists.
  5. Check that the duplicate resume does not merge twice.

Done when

  • The first call prints 'paused before merge'.
  • The resumed run finishes, using only the saved checkpoint.
  • merges performed: 1, even after the duplicate resume.

Open in the Playground No API key needed.

Starter code (Python)
import json

# Checkpoint after every node, interrupt before merge, survive a restart, and merge exactly once.
STORE = {}                # thread_id -> JSON checkpoint (stands in for a database)
MERGES = []               # the real side effect: every merge that happened
INTERRUPT_BEFORE = {"merge"}

ORDER = ["plan", "write", "test", "merge", "end"]


def node_plan(s):  return {"plan": "fix rounding in pricing.py"}
def node_write(s): return {"code": "v3", "attempts": 1}
def node_test(s):  return {"passed": True}


def node_merge(s):
    # TODO: make this safe to repeat: if s has a merge_id, skip; otherwise merge and record merge_id
    MERGES.append(s["code"])
    return {}


NODES = {"plan": node_plan, "write": node_write, "test": node_test, "merge": node_merge}


def save(thread, node, state):
    STORE[thread] = json.dumps({"next": node, "state": state})


def run(thread, state=None, node="plan", resume=False):
    if resume:
        cp = json.loads(STORE[thread])
        node, state = cp["next"], cp["state"]
        print(f"resumed {thread} at {node} from checkpoint")
    while node != "end":
        if node in INTERRUPT_BEFORE and not state.get("approved"):
            save(thread, node, state)
            return f"paused before {node}"
        state = {**state, **NODES[node](state)}
        node = ORDER[ORDER.index(node) + 1]
        save(thread, node, state)
    return "finished"


print(run("run-7f2", state={"task": "make test_discount pass"}))
# --- the server restarts here: nothing in memory survives except STORE ---
# TODO: the reviewer approves. Load the checkpoint, set state["approved"] = True and a reviewer name, save it back

print(run("run-7f2", resume=True))
# A duplicate resume (for example, a retried request) must not merge twice:
cp = json.loads(STORE["run-7f2"])
save("run-7f2", "merge", cp["state"])
print(run("run-7f2", resume=True))
print("merges performed:", len(MERGES))
Show a solution
import json

# Checkpoint after every node, interrupt before merge, survive a restart, and merge exactly once.
STORE = {}                # thread_id -> JSON checkpoint (stands in for a database)
MERGES = []               # the real side effect: every merge that happened
INTERRUPT_BEFORE = {"merge"}

ORDER = ["plan", "write", "test", "merge", "end"]


def node_plan(s):  return {"plan": "fix rounding in pricing.py"}
def node_write(s): return {"code": "v3", "attempts": 1}
def node_test(s):  return {"passed": True}


def node_merge(s):
    if s.get("merge_id"):
        print("merge already done, skipping")
        return {}
    MERGES.append(s["code"])
    return {"merge_id": f"m-{len(MERGES)}"}


NODES = {"plan": node_plan, "write": node_write, "test": node_test, "merge": node_merge}


def save(thread, node, state):
    STORE[thread] = json.dumps({"next": node, "state": state})


def run(thread, state=None, node="plan", resume=False):
    if resume:
        cp = json.loads(STORE[thread])
        node, state = cp["next"], cp["state"]
        print(f"resumed {thread} at {node} from checkpoint")
    while node != "end":
        if node in INTERRUPT_BEFORE and not state.get("approved"):
            save(thread, node, state)
            return f"paused before {node}"
        state = {**state, **NODES[node](state)}
        node = ORDER[ORDER.index(node) + 1]
        save(thread, node, state)
    return "finished"


print(run("run-7f2", state={"task": "make test_discount pass"}))
# --- the server restarts here: nothing in memory survives except STORE ---
cp = json.loads(STORE["run-7f2"])
print("reviewer sees:", cp["next"], cp["state"])
cp["state"].update(approved=True, approved_by="Sam")
STORE["run-7f2"] = json.dumps(cp)

print(run("run-7f2", resume=True))
# A duplicate resume (for example, a retried request) must not merge twice:
cp = json.loads(STORE["run-7f2"])
save("run-7f2", "merge", cp["state"])
print(run("run-7f2", resume=True))
print("merges performed:", len(MERGES))
Quick checkA graph pauses for approval before merge. The server restarts overnight, and the reviewer approves in the morning. What makes the run continue correctly?
How sure are you?
Pick an answer and how sure you are