CHANGE · OBSERVE · UNDERSTAND

Agent cancellation and resumption: restore from a checkpoint

Interrupt an eight-step task and inspect exactly which work replays.

Eight exact fixture stages · sixty-second inspection0 / 60 seconds
  1. WaitingWaiting for inspection
  2. WaitingWaiting for inspection
  3. WaitingWaiting for inspection
  4. WaitingWaiting for inspection
  5. WaitingWaiting for inspection
  6. WaitingWaiting for inspection
  7. WaitingWaiting for inspection
  8. WaitingWaiting for inspection

Restore state, then continue after it

The task computes the sum of integers one through eight. Each step adds its own step number to the running sum, so an uninterrupted run produces thirty-six after eight executions. Persist step-four checkpoint saves both completedStep four and sum ten. No checkpoint saves neither value. Task finishes executes all eight steps without recovery. Interrupt after step six first computes subtotal twenty-one, discards volatile state and restores the saved pair or the initial state. The browser actually runs these bounded loops and prints their intermediate records. This is a deterministic recovery exercise, not an ADK persistence implementation.

Distinguish repeated work from new work

Choose Persist step-four checkpoint and Interrupt after step six. The restored state includes steps one through four, so the first recovery execution is step five. Steps five and six repeat; steps seven and eight are new work. Four recovery executions plus six initial executions give ten total, and the final sum remains thirty-six. Change to No checkpoint: recovery starts at step one, repeats six steps and executes two new steps. Eight recovery executions plus six initial executions give fourteen total. Calling all four or eight recovery executions replayed steps would incorrectly count new work as repetition. Inspect repeatedSteps and newRecoverySteps separately in the final JSON.

Check correctness and recovery cost separately

Both recovery policies can compute the correct sum because this task has no external side effects. The checkpoint reduces repeated computation from six steps to two; it does not magically eliminate all replay. With Task finishes, either policy uses eight total executions and has no first recovery step. Checkpoint state can exist even when it was never used. The complete initial and recovery arrays expose each subtotal, allowing you to verify restoration to ten and the final result independently. A checkpoint containing the step number without its matching accumulator would not be a valid snapshot.

Respect the cancellation boundary

Interruption here represents a cooperative stop between steps followed by an explicitly requested recovery. It does not mean that every user cancellation should automatically restart. The checkpoint lives only in this model; reload recomputes the example. No process is killed and no database is durable. Real systems must preserve task identity and a consistent snapshot, distinguish temporary interruption from terminal cancellation, and separately protect external side effects with receipts or idempotency. Saving computation progress alone cannot promise exactly-once effects. The readings provide broader agent lifecycle and recovery context; this bounded arithmetic task demonstrates only snapshot continuation.

Inspect every stage

Play simulation reveals eight explanatory stages over sixty seconds. The timeline is reading time, not measured task runtime. Pause simulation freezes the inspection position; Resume simulation continues it. Restart returns to zero while retaining the selected policy, fixture and speed. Timeline seeks directly from zero through sixty seconds and pauses playback. Speed selects half, normal or double pace; a change settles elapsed time at the old speed first. At completion, Replay simulation starts a new inspection. Selecting either scenario input resets without autoplay. Moving to a hidden tab pauses. The final structured result appears at sixty seconds; earlier cards explain how it was computed. Waiting cards are not completed task work. Every card includes text, so meaning does not depend on color.

Save a reproducible comparison

Capture baseline stores the currently visible result and control values. Seek to sixty first for a final-outcome comparison, then change one input and inspect the difference. Replace baseline updates that snapshot; Clear baseline removes it. The notebook stores observations in this browser, and Export notes downloads them. Expand experiment and Exit full screen change the view without changing the computation. Record the policy, fixture, repeated steps or failing case, and result rather than interpreting the inspection clock as a performance benchmark. These pages contact no agent service, create no external task and modify no source file.

Views are my own and do not represent any employer, past or present.

Search