learning-it by example

#38 AI agents and MCP 5.2 min

Checkpoint and Resume: Crash Without Sending Twice

My job crashed, I restarted it, and it sent the same email twice.

1. In a long running job that saves a checkpoint after each step, what happens when the job is restarted after a crash?
2. In the made-up six-step report job (checkpoint and resume demo), what happened when the job crashed in the send step with a checkpoint but no safe send?
3. Why is a checkpoint not enough to stop the email being sent twice?
4. In the checkpoint and resume demo, how does the safe send step avoid the second email?
5. In the checkpoint and resume demo, what is said about the safe send's key check when two workers run at the same time?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Run the four cases

    Copy the code folder first. Run python compare.py. It uses only the standard library. Compare each line with the video: steps run 10 and 1 email, then 7 and 1, then 7 and 2, then 7 and 1. Then explain in one sentence why the third case sent two emails.

    A hint

    The crash is raised after the step ran and before its result is saved.

  2. Crash at the last step

    In compare.py change the first case so that it crashes in "log" instead of "draft", still with no checkpoint. Predict the steps run and emails sent, then run it. The printed label for that case will still say "crash in draft"; change the label too if you want it to match. I got steps run 12 and emails sent 2.

    A hint

    Without a checkpoint the restart begins again at the first step, so the send step runs again.

  3. Safe send without a checkpoint

    In compare.py add a fifth case to CASES with the label 'safe send only, crash in send', the crash step "send", keep False and safe True. Predict the steps run and emails sent, then run it. I got steps run 11 and emails sent 1.

    A hint

    Without a checkpoint all earlier steps run again, but the safe send finds its key in the outbox.

  4. Move the crash earlier

    Add another case to CASES with a checkpoint, no safe send, and a crash in "fetch". Predict the steps run and emails sent, then run it. I got steps run 7 and emails sent 1. Say why the number of steps is 7 and not 6.

    A hint

    The step that crashed ran once before the crash and runs again after the restart.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

The crash is a raised error, not a killed process. One crash point per case and six made-up steps. The email is a line in a file. The key check reads a file, so it does not protect two workers running at once. No database, locks or retries.

Up next in AI agents and MCP

More in AI agents and MCP

All AI agents and MCP videos

Related videos