AlgoViz

Checkpoints, interrupts and replay

medium 6 min

A checkpoint is a durable workflow snapshot at a known boundary.

Bookmark the page. Stamp the receipt. Check the stamp on return.

A clerk leaves a bookmark at the pending refund, stamps a ledger when money moves, and checks the stamp after an interruption.

A clerk leaves a bookmark at the pending refund, stamps a ledger when money moves, and checks the stamp after an interruption.
BookmarkWorkflow checkpoint
Ledger stampCommitted external effect
Check on returnIdempotent recovery
Practice recall

Video lesson · Chapter 1 of 4

One refund survives a restart

0:00 / 3:37

Theory

Read or listen first. About 2 min.

What it is

A checkpoint is a durable workflow snapshot at a known boundary. It enables suspension, human review, resumption and controlled forks. Its transaction boundary may differ from that of an external service such as a payment system.

Why it exists

The critical interval is between an external effect and the checkpoint recording it. Use stable operation identity and independent confirmation of the effect so a crash inside that interval does not cause a duplicate action.

Resume a refund without issuing it twice

Checkpoint → Decision record (request exact approval). Decision record → Operation ledger (authorize scoped write). Operation ledger → Checkpoint (recover committed outcome)
Checkpoint → Decision record (request exact approval). Decision record → Operation ledger (authorize scoped write). Operation ledger → Checkpoint (recover committed outcome)

Inside this chapter

Chapter sources
Checkpointing
Checkpoint a workflow at defined state transitions using a durable thread or run identity. A checkpoint stores enough state to resume according to the runtime contract. An external write may already have happened when persistence fails, so give side effects independent idempotency keys.

A checkpoint is written at a known boundary, usually after each step, under a durable thread or run ID. Resuming means loading the last checkpoint and re-running from there, which means any step after it will run again. If that step called an external service, the service may already have acted, so the call must carry a stable operation key that the service uses to return the earlier result instead of acting twice.

Example. Crash after a tool writes but before the workflow saves its next state. Resume from the checkpoint and recover the original write by operation key.

Another example. An onboarding workflow sends a welcome email and crashes before saving. On resume it calls the email service with the same message key, and the service reports it as already sent.

Crash between the write and the next checkpoint

The checkpoint store and the payment system commit separately. The idempotency key is what joins them.
Human-in-the-Loop (HITL)
A human-in-the-loop interrupt pauses execution and persists the decision context. Show the proposed action, evidence, scope and expiry to the reviewer. On resume, check that the approved arguments and current permissions still match. A free-form “yes” detached from the proposal is ambiguous.

The interrupt persists everything the reviewer needs: proposed action, arguments, evidence, scope and when the approval expires. On resume the runtime compares the approved arguments with what is about to execute and rechecks current permissions, because time has passed. A bare "yes" stored without the proposal it answered is ambiguous after any change.

Example. An approval refers to 24 USD. Change the proposed amount to 42 before resume and require a fresh decision on the revised arguments.

Another example. A deploy agent pauses before running a database migration. The reviewer approves migration 0042; by resume time the branch has 0043 as well, so the approval does not cover it.

An interrupt that survives argument changes safely

An approval is tied to the arguments it saw. A changed amount sends the run back for a new decision.
Time Travel
Time travel restores or forks from a historical checkpoint to explore an alternative path. Keep the original history intact for comparison. Replaying a state transition does not undo an email, refund or other external effect. Use inert fixtures or idempotent operations when exploring past runs.

Time travel loads an old checkpoint and either replays it or forks a new branch with edited state. It changes the workflow's history, not the world: an email sent from the original run stays sent. When exploring, swap side-effecting tools for fixtures or ensure every write is idempotent, and label forked runs so they never get mistaken for the production record.

Example. Fork a checkpoint immediately before a query rewrite. Compare the original and alternative retrieved IDs while keeping real external writes disabled.

Fork from history without touching the original

The original branch stays intact for comparison; the fork runs with writes switched off.
The effect-to-checkpoint window
The interval between an external side effect committing and the workflow durably recording it. A crash inside this window leaves the workflow unaware of a change that already happened, so recovery must consult the external system rather than the checkpoint.

You cannot make a checkpoint store and a payment provider commit in one transaction, so there is always a window. Shrinking it helps a little; making the call idempotent and reading back by key solves it. Some teams also write an intent record before the call (an outbox) so recovery knows exactly which keys to reconcile.

Example. A refund commits at the payment provider, then the worker dies before saving. The checkpoint says pending; the ledger says done. The ledger wins.

What resume sees, by crash point

Crash happensCheckpoint saysExternal system saysSafe recovery
Before the callpendingnothingcall with the operation key
After send, before commitpendingnothing or doneretry with the same key
After commit, before checkpointpendingdonefetch result by key, then checkpoint
After checkpointdonedonecontinue
Only the idempotency key makes the middle two rows safe to retry.
Deterministic replay
Re-running workflow code from history so that it reaches the same state, by feeding back the recorded results of model calls, tool calls, clocks and random values instead of producing them again.

Anything non-deterministic in a step, such as a model sample, the current time, a random ID or a network read, must be recorded the first time and served from the record on replay. Durable-execution engines rely on this to rebuild state after a crash. If code changes between the original run and the replay, the recorded sequence may no longer line up, which is one reason to version workflow code with its checkpoints.

Example. Replaying a failed run uses the stored model output for step 3. Calling the model again would give a different plan and the bug would vanish.

Replay from recorded results

  • Same model output, same tool results, same timestamps
  • Reaches the exact failing state
  • No external calls made
  • Safe to run many times while debugging

Re-execute live steps

  • Model samples a different plan
  • Tool data may have changed since
  • Writes can repeat
  • The original failure may not reproduce

How it works

Step through the idea, or press Play.

Step 1 of 3

Checkpoint. Approval pending · run 19

Understand it

Worked example

Resume a refund without issuing it twice

  1. 1

    Approval pending · run 19

    The run pauses before a consequential write. Store the proposed arguments and version so the approval refers to a specific refund.

  2. 2

    Approve 24 USD for order 42

    On resume, compare the approved arguments with the current proposal. A changed amount requires a new decision.

  3. 3

    Refund key 19/42 already committed

    If a worker crashed after the write but before the next checkpoint, recover the existing result by key. A replay cannot undo or safely repeat an arbitrary payment.

Follow the handoffs

The critical interval is between an external effect and the checkpoint recording it. Use stable operation identity and independent confirmation of the effect so a crash inside that interval does not cause a duplicate action.

Run 19 from pause to a single refund

Recovering never sends a new refund blindly. It reads the ledger by key first.

Summary

The whole topic in one minute.

Durable workflow state and external effects can commit at different times. Consult the authoritative operation record before issuing another write.

The critical interval is between an external effect and the checkpoint recording it. Use stable operation identity and independent confirmation of the effect so a crash inside that interval does not cause a duplicate action.

Sources