Skip to content
Start free

Recover from a run that stopped halfway

Last night's rerun of October stopped partway. Read what it left behind, decide what is safe, and bring the reports back to a correct state.

2 parts · 10 and 2 min · part 1 on a computer

Free course. Your Maestro, an AI, .

Before reading on, recall Module 3: when a report replaces a month's rows instead of appending them, what does that protect you from? Answer in one sentence.

The alert came in overnight: October's rerun stopped before it finished. The tempting moves are to rerun at once, or to delete everything in reports/ and start over. Both skip the step that matters: finding out what the failed run actually left behind, and which files you can still trust.

Three questions guide the diagnosis:

  1. What does the alert say? It names the month and how the run ended.
  2. Which files are readable? A file a reader uses, like latest.json, either opens as valid JSON or it does not.
  3. Which files are debris? A file the run was in the middle of writing, such as one ending in .tmp, was never meant to be read.

The answer to the third question depends on how report.py writes. Its write_atomic function writes the new content to a temporary file first and only then calls os.replace to swap it in. Until that line runs, the old file stays exactly as it was. Read write_atomic in report.py before you run anything, and decide what that means for a run that stopped halfway. If the order of those two steps is unclear, ask your Maestro.

In this sandbox, last_night.py recreates the folder an interrupted run would leave, using the project's own code. Nothing is scheduled, and the alert is just a line in reports/alerts.txt.

Try it

Run diagnose.py and decide, file by file, what you can trust. Then rerun October with report.run and add three checks that prove the folder is back in a correct state.

Your turn

Run diagnose.py: it first recreates last night's interrupted run, then shows what it left. Decide which files are trustworthy. Then, where the comment says, rerun October with report.run and add checks that no .tmp file is left, October has exactly 4 history rows, and latest.json shows 2800.0. You're done when all three checks print True.

A good place to stop. Up next: part 2 of 2 · 2 min

What the diagnosis shows

latest.json still opens and shows October with a total of 2800.0, while latest.json.tmp fails to parse: it is the half-written file the run never swapped in. Because the stop came before os.replace, the published report is the last complete one, and the .tmp file is debris. Rerunning October writes the temporary file again from the start and swaps it in. Afterwards no .tmp file is left, October still has exactly 4 rows in history.csv, and latest.json shows 2800.0. Checking those three things, rather than trusting the word ok, is what tells you the recovery worked.

What a real machine adds

The sandbox shows only the files a run leaves. On your own machine you would also read the scheduler's own log to see when the run started and why it stopped, check that the disk had room for the temporary file, and confirm that the account running the report can write to reports/. None of those can be checked here.

Check yourself: After an interrupted run, latest.json opens normally and latest.json.tmp does not. What should you do first?