Status: done (2026-11-22)
Priority: 3
Size: M
Design ref: none (code structure). AGENTS.md, Conventions (st is plain data).
Goal: Three things in and around src/sim/saves.js are more than they need to be. Derived state is kept out of a save in three ways: hidden as a non-enumerable property (st.idx, st.awake), saved (st.jobsBy), or rebuilt on load (st.living, st.liveHouseholds). Stores.take records a movement of nothing, which is the codec’s only -0. And load migrates format-1 saves from before VB-099, VB-127, VB-159, VB-169, VB-198 and VB-204, though the only saves kept are the fixtures, made locally for the sources as they are (VB-272), and no one holds older saves (Kim, 10 Nov 2026).
Acceptance criteria:
sim/saves holds a list DERIVED of the fields of st that are not saved, each with the function that rebuilds it on load (living and liveHouseholds: rebuildLiving; idx: index; awake: null, rebuilt at the next step; jobsBy: from st.jobs). save skips them and load rebuilds them. st.idx and st.awake become ordinary properties: no Object.defineProperty is left in src/. Their @state lines say “derived, not saved (sim/saves DERIVED)”.DERIVED: st.idlers (who is in it depends on when in the hour it was made, VB-074) and st.pathCache (a route searched again after a load may differ from the one cached, so a loaded run would leave the saved one).tests/saves.js holds, as today, that a run saved and loaded mid-year goes on to the same state as the run that was not; tests/plaindata.js and the invariants check the derived fields against their sources.Stores.take returns 0 without recording when nothing was taken, and put, move and cook likewise for nothing; no ledger entry or yearly total has n of 0. Invariant in tests/lib/invariants.js. The codec keeps -0 (it is two lines, and the state may hold one again).FORMAT is already 3 with READS = [3] (VB-259), so load refuses other formats. The migrations for older saves go (each line of load whose comment says older saves have no …; a line that also builds derived state stays or moves to DERIVED): contacts, events, fish, forage, tick, tickPart, a village without ledger, holders without totals, dissolved households’ ledgers, haySpoilt, player and its wishes, match and left, rng.traits, seedPlans/fillPlans, offers, occasions and rng.occasions, agent.occasion, migrateTies (and its export from sim/relations), and trimRoutes on load if VB-236 has landed. node tools/fixtures.js make remakes the fixtures locally (VB-272).jobsBy, if it leaves st’s keys), which node tools/same.js --base REF lists and the PR repeats; no number of the simulation changes: living, households and grain at populous and founders, small map, seeds 3, 7, 11, 42, 15 years, the same before and after.medium-ref (node tools/bench.js) no slower than before; the PR says what fell (lines, the save’s size).npm run verify’s hard checks pass, its targets reported with their residuals.
Notes:FORMAT has been 3 since VB-259, and the migrations in load grew to about twenty lines since this task was written (src/sim/saves.js, load); the criterion lists them. Fixtures are local since VB-272. VB-214 and VB-226 are done.fb35e75, populous, seed 7, small map, 2 years: of 1,676 ledger entries 94 move nothing and of 1,446 yearly totals 129; 158 values are written as {"$num": "-0"}, all of them these.farm, field, meadow and stretch, jobsBy’s job objects, the shared owner of jobs and fences, idlers’ agents). If jobs held ids the codec’s first pass and its $id and $ref could go, about 15 lines; worth it only when jobs are being changed anyway. With jobsBy rebuilt on load, 699 of them go here.sim/saves.js. After VB-236 if trimRoutes on load is to go.DERIVED holds living, liveHouseholds, idx, stepAt (the successor of st.awake, gone since VB-473) and jobsBy; scenarios makes idx and stepAt null, save skips the list and load sets each null and runs its rebuild. The tests comparing a loaded run, and tools/same.js, leave DERIVED out (kept in tests/lib/canon.js); the invariants compare jobsBy and idx with their sources (idx’s holds and lines as their readers filter them: they keep every past holder and line).Stores.record, so put, take, move, cook and the rest record nothing of 0; their returns are unchanged.load decodes, rebuilds DERIVED, compiles the leans (derived from the attitude) and calls sim/agents loaded. With them fillPlans (sim/plans), migrateTies (sim/relations, sim/ties), indexEvents (sim/records), oldProjects and trimRoutes’s export; the tests of each migration went too. sim/agents loaded keeps its own older-save lines (not load’s; left for whoever next changes it).-0 written 25 to 2, movements of 0 36 to 0, save 59 to 56 ms, load (with the island’s generation) 496 to 456 ms. src/ fell by 410 lines (saves.js 677 to 372). medium-ref bench left to the nightly run, so its criterion stays open. Fixtures are a local cache: remade by the night.same.js (tiny, founders and heirs, 2 years) differs only in households’ ledger and totals, by the movements of nothing.