Add cellular owner checkpoint codec
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 41s
Foundation / checks (ecs) (push) Successful in 1m55s
Foundation / checks (postgres) (push) Failing after 52s
Foundation / checks (tsan) (push) Failing after 31s
Foundation / checks (network) (push) Failing after 3m3s
Foundation / checks (client) (push) Failing after 4m26s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-10 22:37:47 -04:00
parent fdeff05ac2
commit 181b9aeec2
7 changed files with 565 additions and 72 deletions
+63 -51
View File
@@ -1,61 +1,73 @@
# Cellular lives checkpoint envelope v1
# Cellular lives checkpoint v1
This schema is specified by [ADR-0108](../docs/adr/0108-cellular-checkpoint-profile.md).
It is the complete payload for region checkpoint profile 4,
`cellular-lives-v1`. Profile 3 remains the independent creation-only
`primitive-lives-v1` format.
Authority: ADR-0108 through ADR-0110. `server::CellularLives` in
`src/server/lifecycle/cellular_lives.cpp` implements the canonical owner
snapshot and restore codec. This is checkpoint profile 4; it does not alter
the profile-3 primitive-life format. All integers are little-endian and records
are packed by the codec, not native C++ layout.
## State closure
## Envelope
The canonical little-endian envelope carries explicit lengths and versions for
the region identity, 50 ms current tick, finite cellular area, provisioned
habitat and region-wide opening totals, ordered living-cell records, ordered corpse
records, region heat and the complete lineage archive. Integers have fixed
widths; records are sorted by stable identity/address. Decoders reject unknown
versions, nonzero reserved fields, duplicate or noncanonical records,
overflow, trailing bytes, malformed checksums and any count or length above the
caps before allocating from untrusted lengths.
| Offset | Width | Field | Contract |
|---:|---:|---|---|
| 0 | 8 | magic | ASCII `AEVCLV01` |
| 8 | 4 | format | 1 |
| 12 | 4 | cellular rules | 1 |
| 16 | 8 | world | Nonzero identity, must match restore request |
| 24 | 8 | region | Nonzero identity, must match restore request |
| 32 | 8 | frame | Nonzero identity, must match restore request |
| 40 | 8 | tick | Committed 50 ms simulation tick; must match restore request |
| 48 | 4 | width_um | Cellular area width |
| 52 | 4 | height_um | Cellular area height |
| 56 | 4 | ambient_temperature_millikelvin | Nonzero temperature used to derive budgets |
| 60 | 4 | spawn_site_count | 1..256 |
| 64 | 4 | living_count | 0..256 |
| 68 | 4 | corpse_count | 0..65,536 |
| 72 | 4 | habitat_bytes | Nested cellular habitat v1 length |
| 76 | 4 | archive_bytes | Nested lineage archive v1 length |
| 80 | 4 | reserved | Zero |
| 84 | 8 | nursery_source | Nonzero source identity |
| 92 | 40 | opening_total | Region-wide starting inventory: energy, carbon, nitrogen, phosphorus, other matter (u64 each) |
| 132 | 40 | nursery_inventory | Current unspent nursery inventory, same channel order |
| 172 | 40 | heat_inventory | Accumulated energy; all matter channels must be zero |
| 212 | 8*n | spawn sites | Signed little-endian i32 x/y micrometre pairs |
| … | 168*n | living records | Strictly ascending life identity |
| … | 100*n | corpse records | Strictly ascending organism identity |
| … | habitat_bytes | habitat | Canonical cellular habitat v1 snapshot |
| … | archive_bytes | lineage | Canonical lineage archive v1 snapshot |
| end−8 | 8 | checksum | FNV-1a64 over all preceding bytes |
The state is complete at one committed tick. It contains no pending or
client-authored intentions. Durable action requests and outcomes remain in the
fenced database batch records that publish the matching checkpoint.
The exact total length is `220 + 8*spawn_site_count + 168*living_count +
100*corpse_count + habitat_bytes + archive_bytes`. The complete envelope is
limited to 16 MiB. The checksum detects accidental corruption; it is not an
authentication mechanism.
Each living record retains player-account binding when present, life and
organism identity, current genome identity, birth tick, growth state, position,
body matter, reserve energy/matter and every timer required by the selected
cellular rule version. Extent, phenotype and metabolic budgets are derived from
the archived genome and growth state. Restore recomputes them; a stored cache
must exactly match or the payload is refused.
## Living record (168 bytes)
Each corpse retains the dead organism identity, death tick, final position and
transferable body/reserve inventory. Heat is a separate energy-only region
account. The habitat carries its finite patch stock and immutable source
provenance. For every ledger channel, region-wide opening holdings must
reconcile exactly to current habitat, nursery, living bodies and reserves,
corpses and heat according to the declared transfers. Resource amounts do not
retain per-source tags after they leave a patch (ADR-0109).
Fields, in order: 16-byte account identity; six u64 values (`life`, `organism`,
`genome`, `event`, `born_tick`, `source`); two u32 values (`realized_per_thousand`,
`damage_per_thousand`); two u64 micrometre coordinates; then body and reserve
inventories, each five u64 channels in the envelope order. Account identities
must be unique. IDs and source/event references must be nonzero. The body is
the genome-derived structural matter inventory and contains no energy.
Restore requires exact world/region/frame and end-tick agreement with the
manifest, complete organism/genome/archive closure, unique player bindings,
in-bounds footprints, valid energy/matter channels, and canonical byte-identical
re-encoding. Genesis contains no living cells or corpses. Profile-4 clone genesis
is unsupported until an identity-remapping contract exists.
## Corpse record (100 bytes)
## Bounds
Fields, in order: four u64 values (`life`, `organism`, `source`, `died_tick`);
two u64 micrometre coordinates; two u32 growth values; u32 phenotype extent;
and one five-channel inventory. The archive must contain the matching dead
organism and death tick. Inventory must retain at least the genome-derived body
matter; heat is not part of the corpse.
| Component | Maximum |
|---|---:|
| Total payload | 16 MiB (ADR-0110) |
| Living cells | 256 |
| Provisioned food patches | 4,096 |
| Retained organisms and corpses | 65,536 |
## Restore validation
Every nested format/version is pinned by profile 4's manifest version bundle.
The manifest SHA-256 verifies the immutable object; nested checksums are for
early corruption detection and canonical decoding, not authentication.
## Implementation status
This document records the approved closure direction only. No profile-4 codec,
SQL admission or recovery implementation is claimed until the corresponding
code and tests land.
The decoder checks envelope bounds and checksum, identity/tick, versions,
reserved fields, all counts and nested lengths, and exact total length before
reserving record vectors. It then decodes the bounded habitat/archive records,
recomputes phenotype and body from archived genomes, verifies positions and
footprints, verifies exact living-set/archive closure and unique life/account
identities, and reconciles every current channel (nursery, heat, habitat, lives,
corpses) to the explicit opening total. It accepts only byte-identical
canonical re-encoding. The codec is an in-memory profile contract: manifest
allowlisting, PostgreSQL publication and process recovery are separate M11.3d
gates and remain required before this profile is durably playable.