T-019: Lineage log and genome store
Goal
Record who was born to whom, so species can be measured afterwards without the sim ever
storing a species. See docs/DESIGN.md section 10.
Scope
- An append-only event log in the run folder: births (id, parents, step, place, genome hash) and deaths (id, step, place, cause, lifetime energy sources).
- A genome store keyed by content hash, each genome saved once.
- Periodic census records: counts, biomass and energy sources by region.
- Compact, streamable, and readable from the browser as well as natively.
- Logging must cost little. Measure it.
- A reader API in
crates/analysis.
Done when
- ☐ A long run's log can rebuild the full family tree of any living organism.
- ☐ Logging slows the run by less than 5%, measured.
- ☐ Format documented in
docs/RUNS.md.
Added 2026-12-02: where the runner expects you (from T-012)
drain_world_logsincrates/runner/src/run.rsis the empty hook where the world's birth and death records leave the sim each step. Fill it in.- Open the lineage log with
Logs::open, so it is cut back to the right length when a run resumes from a checkpoint. A resumed run must write byte-identical logs to one that never stopped. The runner's tests show how to check that, including a realkill -9. - The run folder already has an empty
lineage/for you.docs/RUNS.mdexplains the layout and the rules for adding to it.
Result
Branch t-019-lineage-log. Format and use for people: docs/RUNS.md, "The lineage log".
Hooks, contracts and decisions: docs/ARCHITECTURE.md section 18. Costs:
docs/perf/LOG.md, last entry.
What now works
- Four append-only files under
lineage/:events.bin(births and deaths, one frame per step that had any),genomes.bin(each genome once, whole or as a change from a parent's),census.bin(organisms, cells, cell mass and energy by source per region, everylineage.census_everysteps) andindex.bin(fixed 64-byte seek entries). - Hooks for T-018, T-017 and T-024:
lineage::birth(w, slot, &parents),lineage::death(w, slot, cause, other),Parent::of(w, slot), andbody.org.lineage.earn(source, amount). Any number of parents. The hooks read what they need from the world. Cause numbers are blocks per module, so nobody editslineage/to add one. - The sim encodes, the runner appends. The bytes are a pure function of the world.
The runner starts the log when it creates a run (everything alive is recorded as
present at the start), drains it after every step in
drain_world_logs, and on resume refuses a lineage file whose length does not match its checkpoint. - Genomes as changes: a new genome is stored as a copy/insert diff from the closest parent's genome, whole every 64 changes. One mutation costs about 20 bytes against about 540 for the whole genome. Each record carries a 32-bit check of the genome's hash.
- The reader (
analysis::lineage):Login memory (tree, ancestors, descendants, alive at a step, genome of any organism) andSeekerthrough the index from any byte source, including HTTP range requests in a browser.check_against(log, world)proves a log describes a world. Alineagetool:summary,check,ancestors,tree,census. - The testbed churn reports to the log: deaths, a replacement born to a random parent,
and split-off pieces born to their source.
lineage::breedis a stand-in for reproduction with real genomes, 1 to N parents and gene mixing, for tests and the lab.
Checks
crates/runner/tests/runs.rs: every run test now also requires the four lineage files to be byte-identical to a run that never stopped (stopped off-grid, resumed on 1, 2 and 3 threads, killed withkill -9at random moments, packed and unpacked three ways), and runscheck_againston the final world: every living organism has a birth record and a complete family tree, and the log's living set equals the world's. A new test writes junk past the checkpoint in all four files and resumes to identical bytes, and shows a file that does not match its checkpoint is refused.crates/sim/tests/lineage.rs: the same bytes on 1 and 3 threads, and across a save and load with bytes still waiting in the world; a world nobody drains stays under its cap.crates/analysis/tests/lineage.rs: 3,000 steps of breeding with up to three parents, 73 generations: every living organism's tree is complete and its genome rebuilds from the log to the exact bytes it has in the world. The seeker gives the same tree. Cases nobody listed: a parent that died and whose genome the store forgot before the birth was recorded, a birth recorded out of uid order, an unknown parent, recording switched off and on, records dropped by the cap, cut and corrupted files (errors, no panics).crates/sim/examples/wasm_probe.sh 20000 60 300 20now runs with a started log, whose waiting bytes are in the state hash: native and WebAssembly stay identical for 300 steps.cargo build -p analysis --lib --target wasm32-unknown-unknownbuilds.lineage_lab size, one million births: 45.2 bytes per birth in all, 236 generations, every one of 5,000 living organisms checked, genomes rebuilt exactly.
Done when
- ☑ A long run's log can rebuild the full family tree of any living organism.
A runner run of 20,000 soup cells with churn 0.004, killed with
kill -9at about step 8,000, resumed, stopped with Ctrl-C at step 16,686: 6,951,170 births and 6,448,705 deaths in 176 MB (13.2 bytes each).lineage checkagainst the last checkpoint: all 502,465 living organisms have a complete family tree (1,423,410 members, 136 roots, up to 112 generations) and the log's living set is exactly the world's, in 3.4 s. One organism's 78 ancestors through the index read 2 MB of the 176 MB in 5 ms. Also the million-birth lab with real genomes. - ☑ Logging slows the run by less than 5%, measured: 0.1% in a 100,000-cell churn world, 0.4 to 1.1% with real genomes at ten times a realistic birth rate.
- ☑ Format documented in
docs/RUNS.md.
Not done, and worth knowing
- Energy by source is always zero until metabolism calls
earn. - Two-parent children of distant relatives cost about 95 bytes a birth instead of 45: the change record copies from one parent only. A diff that copies from several bases would fix it.
- The viewer records nothing in its own worlds. A run's checkpoint opened in it has a
log started and builds a backlog of up to 64 MiB before dropping it. One line in the
viewer (
world.lineage.discard_output()per frame) would stop that. - Whole-run timings could not resolve 2 to 5% on this machine at this load: see the perf log. The in-process alternating measurement is the evidence.