Status: done (2026-11-02) Priority: 2 Size: M Arch: core Phase: implement Design ref: Pace (a run lasts 40–80 hours); Systems overview (Save and load: missing). Goal: A run cannot be saved. A save is needed to play for 40 hours, and it is the best debugging tool there is: a bug report carries the run, and a test can start from it. This task makes saving and loading work in Node; the page’s buttons and autosave follow from the plan (VB-077). Depends on VB-072 and VB-073; if either is not done, mark this blocked. Acceptance criteria:
Sim.save(st) returns a JSON-compatible object: format (1), the scenario, seed and map size, and the whole state. Object references become ids: an agent’s job and a job’s field, farm and stretch by key and index. Maps, Sets and typed arrays are encoded so that they come back as the same types.w.trees, w.treesMax, w.stones, w.biome, w.dev; grep for writes to w. in src/sim), and Sim.load(w, data) takes a world freshly generated from the saved seed and size, applies them, and returns a state.tests/saves.js in npm run verify: founders and heirs at seeds 7 and 42 are saved after 2 years, written as JSON text, parsed, loaded into a new world and advanced 1 year. The hashes of tests/golden.js (hashKeys) then equal those of the run that was never saved. The same for populous tiny at seed 7, saved after 1 year.tools/sim.js (VB-068), if done, gains --save FILE and --load FILE.$id where it first appears and is $ref after, so every shared object keeps its identity (130 in founders after 2 years, 870 in populous tiny after 1), st.cenv.people stays st.pawns, and a new kind of reference needs no code. tests/codec.js (npm test) covers the codec.st broke exactness: the idle pawns of the hour (relations.js, a WeakMap) depend on when in the hour they were drawn, so a run saved mid-hour (t = 3000.75, populous tiny) drew other company after loading. It is now st.idlers, saved with the rest. A sweep of 12 more save times (founders 11, heirs 7, populous 42 tiny; mid-hour and mid-day) then matched; tests/saves.js keeps the mid-hour case.Sim.advance calls after the save: 6-minute steps add up differently when the same hours are advanced in other chunks (seen in the sweep, before and after this task alike). VB-077 should keep that in mind for autosave.tools/sim.js --save, medium map, seed 7): populous after 2 years 11.23 MB of JSON, 2.39 MB gzipped; founders after 50 years 1.66 MB, 0.14 MB gzipped; founders small after 3 years 0.60 MB, 0.04 MB. In the populous save, pawns are 67% (their ties and relations; VB-127 caps ties at 150 a pawn), the world’s tiles 8%, households 7%, the route cache 4%.