Status: done (2026-11-10)
Priority: 2
Size: M
Arch: life
Phase: implement
Design ref: Commands, time steps and views (Saving: Agreed 30 Oct, revised 7 and 8 Nov by Kim); QUESTION_ARCHIVE.md, “VB-077” (30 Oct) and “VB-079” (questions 3 and 8); docs/review-life.md, section 5.
Goal: VB-074 saves a run in Node; a player cannot yet keep a game. Save and load in the page: to and from a file, and in the browser keeping the last 3, by hand and when the page is hidden. Each save names the build that made it, and a save from any other build is refused with a message and an easy way to delete it and start a new game (Kim, 30 Oct and 8 Nov). Autosave at the moving round waits for a save under 0.5 s (VB-215).
Acceptance criteria:
build.py writes a build id into the page: a short hash of the sources it inlines, the same for the same sources, so python3 build.py --check still holds.src/page/saves.js, in src/page.json) saves {build, savedAt, label, save: Sim.save(st)} gzipped (CompressionStream):
visibilitychange to hidden, into IndexedDB, keeping the last 3;.json.gz;.json.gz or .json.The label names the scenario, seed, map, year and season, and the played pawn if any (VB-169).
Sim.load keeps its format rule, so fixtures still load across builds.node tools/sim.js --load FILE (the wrapper is unwrapped there), so a bug report can carry a played run.st.player included.tests/browser*.js (real Chromium): (Moved to VB-260: Kim, 10 Nov, the code first and the testing later; checked once by hand, below.)
tools/bench.js), at small-y40 and medium-y5, each stage apart (encode, stringify, gzip, IndexedDB write; read, gunzip, parse, decode). Stale fixtures are said to be so. On 5 November, in Node: 1.09 s to save and 0.32 s to load at medium-y5. The 0.5 s line is VB-199’s and VB-204’s, not this task’s. (Moved to VB-260.)docs/img/vb-214-*.png. Golden file unchanged. (Moved to VB-260; the golden file is unchanged.)
Notes:localStorage holds about 5 MB, so saves go to IndexedDB (VB-077’s note of 2 November).sim/jobs, sim/kinds, sim/commands and sim/clock; this task touches the page and build.py.design.md’s Saving point was brought up to these on 10 November (VB-260).Implementation (10 Nov 2026): build.py replaces __BUILD_ID__ with the first 10 hex digits of the SHA-256 of the page before the
replacement, so the same sources give the same page. src/page/saves.js (in src/page.json after page/notices.js): a save is
{build, savedAt, label, save: Sim.save(st)} as gzipped JSON (CompressionStream). IndexedDB village-builder has two stores keyed
<scenario>-<seed>-<cols>x<rows>:<slot>: saves holds each slot’s line (label, build, when, size, and what makes the archipelago) and
blobs its bytes, so listing never reads the bytes. readSave tells gzip by its magic bytes, else reads plain JSON, and refuses any
build but the page’s; a bare Sim.save (from tools/sim.js --save) names no build and is refused as another build’s. Sim.load keeps
its format rule. The loader’s build(seed, scenario, size, save) regenerates the world and calls Sim.load in place of Sim.seed; a
played pawn is selected in place of the offer to play. tools/sim.js --load unwraps a page save, whatever its build. The simulation
does not run while the landing page or the generation screen is up (src/page/speed.js). No module of src/sim and no state changed.
Not built: a confirmation before Delete and Delete archipelago (they act at once); a save begun as the tab closes, not only hides, may not finish; saving while a debug skip runs is refused silently.
Sizes, gzipped (Node, tools/sim.js --save): founders medium at year 1, 0.06 MB (1.30 MB of JSON); populous small at year 5, 1.15 MB
(6.06 MB); in the page, populous tiny seed 7 after 30 days 0.25 MB and after 130 days 0.41 MB. At medium-y5 it was 3.9 MB on
5 November, so an archipelago’s four slots are about 16 MB at worst today.
Validation (10 Nov 2026): npm test (86 scripts) and node tests/golden.js pass, and tests/smoke.js, tests/browser.js,
tests/browser-mobile.js and tests/browser-speed.js pass run one by one, changed to start from the landing page (as tools/shot.js
and tools/village-shot.js). npm run verify as a whole was not run, nor were times taken (VB-260). By hand, once, in real Chromium
(node tests/browser-saves.js OUTDIR, which prints and asserts nothing): on populous tiny seed 7 with a played pawn, a save to slot 1
continued after a reload has the same hash of Sim.save, time and played pawn; a file saved and loaded again has the same hash and
takes no slot; a save given another build id shows the refusal, and Delete it removes it; Delete archipelago removes that
archipelago’s saves only; a file of another build is refused with the message; no console errors. The page file ran a year in
node tools/sim.js --load. Not exercised: the auto slot on a hidden page, and Start a new game.