T-012: Runner, run folders and checkpoints
Goal
Run worlds headless for a long time and be able to pick any of them up later on another
machine. This is the "run there, look here" requirement in docs/DESIGN.md section 12.
Scope
runner run --config world.toml --seed N --steps N --out runs/NAME: runs headless at full speed and prints progress and steps per second.- A run folder holds: a manifest (config, seed, code version, checkpoint format version), checkpoints at an interval, and room for the lineage log and analysis results.
runner resume runs/NAMEcontinues from the last checkpoint. Resuming must give the same world as never stopping.runner info runs/NAMEsummarizes a run.runner pack runs/NAMEmakes one portable archive of a run. A thinned copy with fewer checkpoints must be possible, for small downloads.- Clean shutdown on Ctrl-C: write a checkpoint first.
- A thread-count option, so several runs can share the machine.
- Clear refusal with a readable message when a checkpoint's version is too new or too old.
Done when
- ☐ Tests: resume equals continuous. A packed run unpacked elsewhere resumes.
- ☐
docs/RUNS.mddocuments the folder layout and the commands.
Result
Done on branch t-012-runner-checkpoints. People's guide: docs/RUNS.md.
What works
runner run --out DIR --steps N|forever [--config F] [--seed N] [--set K=V]runs headless and prints progress (step, percent, steps/s, times real time, organisms, cells, time left) and one line per checkpoint with its size and cost.- The run folder holds
run.toml(format version, seed, code version with git commit, checkpoint container version, target, schedule, how the world started),config.tomlas given,params.toml,sessions.log,checkpoints/step-NNNNNNNNNNNN.ckptwith a.tomlsidecar each,logs/stats.tsv, and emptylineage/andanalysis/for their owners. runner resume DIRcontinues from the newest checkpoint that loads. A run stopped cleanly, by Ctrl-C, or bykill -9at any moment reaches the same world, and byte-identical logs, as a run never stopped. Logs are cut back to the length each checkpoint recorded.- Checkpoints are written atomically (temp file, sync, rename, directory sync). Old ones are
thinned by step number to about
--per-doubling(default 4) per doubling of age, so a run of a million intervals keeps 76. The first and the newest are always kept. --every auto(the default) measures speed for 2 s and picks a round interval near 5 minutes of running.- Ctrl-C, SIGTERM and SIGHUP finish the step and checkpoint first. A second Ctrl-C quits.
--threads N|all(default 4). The result is the same for any count.- Readable refusals: a checkpoint whose container or section version is newer or older
("...newer than this build can read. Update the program"), a run folder layout that is
newer or older, a checkpoint with settings this build does not know (unless
--allow-changed-rules). A damaged checkpoint is renamed*.damagedand the one before it is used; a version mismatch is never skipped silently. - A lock file stops two runners working on one folder.
runner info DIRsummarises a run instantly, even while it runs.runner pack DIR [--checkpoints all|last|N]writes one tar file, safe while the run is going;runner unpack FILE [--into DIR](ortar -xf) restores it.runner run --from FILEstarts a new run from any checkpoint (for example one the viewer saved).runner benchis unchanged.
Checkpoint cost (Mac mini, 4 threads, load average about 6, testbed soup):
| Cells | Size | Serialize and compress | Write and sync | Resume |
|---|---|---|---|---|
| 100,000 | 6.1 MB | 5 ms | 15 ms | |
| 1,000,000 | 61 MB | 55 to 80 ms | 33 to 43 ms | about 0.2 s, 430 MB peak memory |
A checkpoint costs 2 to 6 steps' worth of time, so at the auto interval it is well under 0.1% of a run.
Tests (crates/runner/tests/runs.rs, plus unit tests for thinning, manifest, names):
resume equals continuous (stopped off-grid, resumed on 1 and 3 threads, extended); logs cut
back; packed run (all, last, spread 3) unpacked elsewhere resumes to the same world;
container version too new and too old refused, by resume, run --from and info; run
layout too new refused; damaged newest falls back; lock; thinning stays small; real process
killed with SIGKILL at random moments (18 to 31 kills per test run) resumes exactly; real
Ctrl-C saves at the exact step and resumes exactly. Breaking log truncation or the
re-application of churn on resume makes 4 and 6 of these tests fail.
Decisions
- Default
--threads 4, not all cores, because the machine is shared.--threads allfor idle-time runs. - Checkpoints are written on the stepping thread. A background writer would save about 40 ms per checkpoint at a million cells; not worth it yet.
- A checkpoint with unknown settings or sections is refused on resume unless
--allow-changed-rules, becausedocs/ARCHITECTURE.mdsays such a world may not continue exactly. - The pack is an uncompressed tar: checkpoints are already LZ4-compressed, and any machine can open a tar.
- The testbed soup and churn are exposed as
--soupand--churnso the runner can be used and tested before real founders exist. Churn breaks conservation; it is marked as testbed everywhere. - No change to
crates/sim.