When to reach for it
- State loss in long-running or resource-intensive workflows is critical and must be prevented.
Snapshot the state so the run can be resumed, not restarted.
The system state (including reasoning and world model) is explicitly captured and externalized so a run can be recovered, resumed, or replayed across steps, sessions, and processes — not only after an abort.
In practiceWhen a batch-extraction agent crashes mid-run, the recorder's persisted step log lets a fresh instance skip the API calls already completed and continue from the point of failure.
After every step the complete state is written to a store outside the process, under the ID of the run. Any later process can load the latest snapshot and continue from there.
1 · Capture, after every step
2 · Restore, in a new process
| Step | Snapshot | After restart |
|---|---|---|
| 1 · Load 500 invoices | Saved | Not repeated |
| 2 · Extract invoices 1 to 250 | Saved | Not repeated; 250 model calls kept |
| 3 · Extract invoices 251 to 500 | None; crash at invoice 380 | Repeated from invoice 251 |
| 4 · Write the CSV file | Not reached | Runs |
def run(thread_id, steps):
# a fresh process starts here
state, done = store.latest(thread_id) or ({}, 0)
for i, step in enumerate(steps[done:], start=done):
state = step(state)
# one snapshot per finished step
store.save(thread_id, state, next_step=i + 1)
return stateWhen to reach for it
When it backfires
Every checkpoint includes whatever lived in working state — including PII or secrets the agent saw transiently while reasoning.
Countermeasure
Define a serialization contract that strips sensitive fields before persistence. Validate the contract with a test that diffs serialized state against an allowlist.
The step log records the inputs but re-executes tools on resume. An external result that has since changed makes the resumed run diverge from the one that was interrupted.
Countermeasure
Memoize side-effecting tool outputs in the record and replay them, rather than re-calling; mark genuinely non-replayable steps so resume restarts from the last safe boundary.
Keep going
Search patterns, frameworks, and pages.