# Cellular habitat snapshot v1 This bounded snapshot is implemented by `biology::CellularHabitat` under ADR-0101. It describes a region-local finite food opening and its current stock; it is not yet an admitted PostgreSQL checkpoint profile. A containing cellular checkpoint must bind its exact world, region and frame identity. All integers are unsigned little-endian unless stated. Records are packed by the codec, not by native C++ layout. ## Envelope | Offset | Width | Field | Contract | |---:|---:|---|---| | 0 | 8 | magic | ASCII `EVOPATK1` | | 8 | 4 | format | 1 | | 12 | 4 | habitat rules | 1 | | 16 | 8 | world | Nonzero identity | | 24 | 8 | region | Nonzero identity | | 32 | 8 | frame | Nonzero identity | | 40 | 4 | width_um | Positive, <=1,000,000, multiple of 1,000 | | 44 | 4 | height_um | Positive, <=1,000,000, multiple of 1,000 | | 48 | 4 | patch_pitch_um | 1,000 | | 52 | 4 | patch_count | 0..4,096 | | 56 | 8 | reserved | Zero | | 64 | 8 | reserved | Zero | | 72 | 56*n | patch records | Ordered by ascending (x_um,y_um) | | 72+56*n | 8 | checksum | FNV-1a64 over all preceding bytes | Exact length is `80 + 56 * patch_count`. The checksum detects accidental corruption; it is not an authentication mechanism. ## Patch record (56 bytes) | Offset | Width | Field | Contract | |---:|---:|---|---| | 0 | 4 | x_um | Patch lower-left coordinate; 1,000 μm aligned and in bounds | | 4 | 4 | y_um | Patch lower-left coordinate; 1,000 μm aligned and in bounds | | 8 | 8 | source | Nonzero opening-provenance identity | | 16 | 8 | energy_pj | Finite usable chemical energy | | 24 | 8 | carbon_fg | Finite organic carbon | | 32 | 8 | nitrogen_fg | Finite organic nitrogen | | 40 | 8 | phosphorus_fg | Finite organic phosphorus | | 48 | 8 | other_fg | Finite organic other matter | Unlisted patches contain no stock. Each conserved channel's sum across the opening must fit `u64`; overflow rejects creation. Records must be strictly ordered and unique. There is no automatic refill or default opening. ## Restore validation Before allocating patch storage, the decoder checks the minimum/maximum byte length, checksum, magic, versions, count cap and exact length. It then validates identity, dimensions, patch pitch, zero reserved fields, patch alignment, source ids, strict ordering and per-channel totals. Restore rebuilds through the same creation validator and accepts only bytes identical to a canonical re-encoding. ## Format 2: deposits (ADR-0136 step A) Format 2 keeps the same 72-byte header with three differences: - **Format field:** it reads 2. - **Pitch field:** it is 0, since deposits are not aligned. - **First reserved u64:** it holds `next_deposit`, which is above every deposit id. Records are 64 bytes and keep the format-1 ordering: ascending `(x_um, y_um)`, with addresses unique. Exact length is `80 + 64 * count`. | Offset | Width | Field | Contract | |---:|---:|---|---| | 0 | 4 | x_um | Deposit centre, in bounds; any micrometre | | 4 | 4 | y_um | Deposit centre, in bounds; any micrometre | | 8 | 4 | id | Nonzero, unique, below `next_deposit`; stable for its life | | 12 | 2 | radius_um | 1 to 5,000: the contact disc | | 14 | 1 | kind | 1 pool, 2 bubble | | 15 | 1 | reserved | Zero | | 16 | 8 | source | Nonzero provenance identity | | 24 | 40 | stock | Energy, then carbon, nitrogen, phosphorus, other | A cell touches a deposit when its square footprint comes within `radius_um` of the centre. Under rules 8 that contact is feeding: - **Feeding order:** by ascending address, up to the cell's intake rate per tick. - **Pools:** a pool gives at most a quarter of that rate. - **Corpses:** a dead cell's detritus becomes one bubble per non-empty channel, with new ids from `next_deposit`. - **Empty deposits:** removed.