← Board · source

T-017: Metabolism and the matter cycle

done · M2 · model fable · needs T-010, T-011

Goal

The economy of the world: where energy and matter come from, what everything costs, and what happens at death. See docs/DESIGN.md sections 3 and 4.

Scope

Done when

Added 2026-12-02: size has to matter through the economy

Read "Scale is free" in docs/DESIGN.md section 5. No cost or income may depend on body size by rule. Size effects have to come from this: **exchange happens at surfaces, costs are paid by volume.** Light, dissolved food and vent chemicals reach a cell according to how exposed it is to the water. Upkeep is paid for all matter.

Added 2026-12-02: what the fields give you (from T-011)

Read docs/ARCHITECTURE.md section 16 first. In short:

Added 2026-12-02: what the genome leaves for you to price (from T-010)

See docs/GENOME.md section 7 and the end of the T-010 ticket.

Added 2026-12-02, after you started: energy by source (from T-019)

The lineage log records, per organism and per region, how much energy came from each source. It is always zero today. Credit energy as it is taken in with body.org.lineage.earn(source, amount) (docs/ARCHITECTURE.md section 18). If this note reached you too late, say so in your report and the orchestrator will make it a small follow-up.

Result

Branch t-017-metabolism. The full write-up is docs/METABOLISM.md. Charts and tables are in docs/media/T-017/.

Done-when

What exists

The leftovers from T-010 and T-011

Energy by source and death causes (the note added after I started)

It reached me in time. The branch has main as of c793f66 merged in (three merges, as main moved while the checks ran).

Worlds grown from genomes (T-065, merged into main while this ran)

T-065's testbed used the egg and store calls this ticket replaced, so the merge needed code, not only conflict fixes:

Shared files touched

crates/sim/src/develop/{mod,grow,embryo}.rs, crates/sim/src/index.rs (new for_each_in_box), crates/sim/src/fields/mod.rs (noise made public, for its portable exp), crates/sim/src/testbed.rs, crates/sim/src/lineage/breed.rs (one line), crates/sim/src/store/body.rs and crates/sim/src/store/columns.rs (#[inline(always)] on the view builders, nothing else), crates/runner/src/perf/world.rs (living = true for soup worlds), docs/perf/worlds/soup-100k-living.toml (new), docs/perf/README.md, crates/sim/tests/develop.rs, crates/sim/examples/wasm_probe_native.rs, crates/sim/Cargo.toml, crates/runner/src/bench.rs, docs/ARCHITECTURE.md, docs/DESIGN.md, docs/GENOME.md, docs/perf/LOG.md, docs/perf/IDEAS.md. Nothing under physics/.

Checkpoint format: orgs.develop is version 2, the metabolism state is version 2, and there are new columns orgs.metabolism.* and cells.metabolism.*. Older checkpoints are refused with a message that names orgs.develop.

Not done, or not as good as hoped

Speed

scripts/perf.sh --check against main at c793f66, on the final code, load average 2.8. Exit 0, every case "same":

worldthreadsbase steps/snew steps/stime new vs basecyclesverdict
genomes-grown137.437.0+0.9% (+0.4 to +1.8)+1.4% (+0.9 to +2.3)same
genomes-grown4108.7108.8+0.4% (-0.7 to +1.0)+0.2% (-0.4 to +0.5)same
soup-100k-churn4288.2289.0-0.3% (-0.6 to -0.0)-0.2% (-0.4 to +0.0)same
soup-100k-living1 and 4new world, the base build cannot make it
soup-100k196.495.8+0.5% (-0.2 to +1.4)+0.5% (-0.0 to +0.8)same
soup-100k4310.5312.0-0.5% (-0.7 to -0.1)+0.0% (-0.3 to +0.1)same
soup-10k1926.0925.2-0.0% (-2.1 to +0.7)+0.3% (-0.6 to +0.6)same
soup-10k42917.52876.8+1.4% (+1.3 to +1.6)+0.8% (+0.7 to +1.0)same
soup-1m433.234.0-2.3% (-3.9 to +0.1)-0.5% (-0.8 to +0.4)same

By stage: physics within 1% everywhere, the fields stage 11 to 14% faster, the index 3 to 9% faster in all cases but one (soup-10k on 4 threads, +9.5% of 0.04 ms).

The new world is docs/perf/worlds/soup-100k-living.toml: a soup with every organism in the economy. runner perf suite --only soup-100k,soup-100k-living --threads 1,4, load 3:

worldthreadssteps/sns per cell-stepmetabolism ms/step
soup-100k196.5103.60.001
soup-100k4315.131.70.001
soup-100k-living187.2114.61.179
soup-100k-living4281.535.50.399

The stage costs 11.8 ns per cell-step on one thread and 4.0 on four. A world with every cell in the economy runs at 0.90 of the speed of one with none. Two thirds of the stage on one thread is the exposure refresh. Memory: 18 to 19 MB per 100,000 cells in `runner bench` (10 bytes per cell, 57 per organism).

Memory safety

No unsafe code was added or changed. The stage adds columns and two parallel loops, and the inlining fix touches attributes in store/, so scripts/check-unsafe.sh was run in full on the final code (b381331):

stepresult
lintok
miri-sb (Stacked Borrows)ok, 620 s
miri-tb (Tree Borrows, data races, three threads)ok, 1204 s
tsan (threaded integration tests)ok, 32 s
tsan on tests/metabolism.rs, which the script does not listok, 13 passed

The script took 31 minutes, not the 8 it promises. An earlier full run also passed. After the last merge (no change under store/ or to exec.rs since that run) the quick form, lint and ThreadSanitizer, passed again on the final code.

Merged (orchestrator, 2026-12-02)

Merged into main at 511efcb. Format check, lint and all tests pass on the merged tree.