# Cohort record, representation version 1 Scope: the tier 2 record defined by [ADR-0036](../docs/adr/0036-cohort-state-and-ownership.md) and shaped by [ECOLOGY_MODEL.md](../docs/biology/ECOLOGY_MODEL.md). Its validator is `src/ecology/cohort.cpp`. There is no byte layout here and no encoder. Unlike the genome record, a cohort is not hashed, not a mutation context and not exchanged between processes yet, so a wire format would be a format nothing writes or reads. Durable storage and cross-version migration are M7 and M8, and the version field exists so a later schema can fail closed on records it does not understand rather than guess. What this document pins is the meaning of each field and the invariants a record must satisfy to exist at all. Not a network protocol, a durable format, a habitat geometry, a conversion transaction or a population model. Nothing here advances, collapses or materializes anything. ## Record | Field | Type | Meaning | |---|---|---| | representation version | u32 | 1. Unknown versions fail closed | | habitat | u64 | Where the cohort is. Nonzero. Carries no geometry in version 1 | | genome | u64 | The genome every member carries. Nonzero | | owner worker | u64 | Who integrates this cohort. Nonzero | | owner epoch | u64 | Which epoch that ownership is held under. Nonzero | | last tick | u64 | The last interval boundary integrated to. Never runs backwards | | revision | u64 | Nonzero. Strictly increases with every replacement within an epoch | | conversion | u64 | The conversion that produced this record. Nonzero provenance | | age classes | 1 to 64 | Ordered, disjoint, each non-empty. See below | | approximation bound | count + inventory | Declared, never computed here | Lineage is deliberately absent. Ancestry is resolved from the genome through `LineageArchive`, so a cohort cannot hold a parentage that contradicts the archive's and cannot invent precise parentage from a statistical membership, which ECOLOGY_MODEL forbids. Totals are absent for the same reason. Count, reserve and residual are summed from the classes on demand; a stored total is a second tally that can disagree with what it summarises. ## Age classes | Field | Type | Meaning | |---|---|---| | age low | u64 | Ticks, inclusive | | age high | u64 | Ticks, exclusive. Must exceed age low | | count | u64 | Whole members in this class | | reserve | inventory | Energy and four matter channels held by the class in total | | residual | u64 | Fraction of a member owed, over `residual_scale` (1,000,000) | Each class holds its own count and its own reserve, so the record stores a distribution and not a mean. This is the point of the record: a count with a mean reserve cannot distinguish a cohort where every member is provisioned from one where half hold nothing, and no later stage can recover what that discards. Within one class members are indistinguishable. That is the record's declared resolution and a real loss. A caller needing finer structure declares narrower classes; it does not divide a total afterwards. No accessor returns a mean, because an average that is easy to reach becomes the authority. A residual is owed and not yet present. It is not a count, is never added to one, and is strictly less than one member, because at one member it is a member. Funding a residual against biomass is M4.3. ## Invariants A record that breaks any of these does not exist; construction returns the named error instead. | Rejected | Error | |---|---| | Representation version other than 1 | `unsupported_version` | | Zero habitat, genome, owner worker, owner epoch, revision or conversion | `invalid_identity` | | No age classes | `no_age_classes` | | More than 64 age classes | `overflow` | | `age_high <= age_low`, or a class overlapping or preceding the one before it | `unordered_age_classes` | | A class with no members and nothing owed | `empty_age_class` | | A class holding reserve with no members to own it | `unowned_reserve` | | A residual of one member or more | `residual_out_of_range` | | Counts, residuals or any inventory channel that would overflow when summed | `overflow` | Every quantity is unsigned, so a negative reserve is not representable. What is rejected is a declared state that would require one: reserve held by a class with no members. Arithmetic that could produce one does not exist in this version, because this version performs none. ## Ownership `CohortRegistry` holds at most one record per habitat and genome. Two records of one genome in one habitat would be two places the same biomass could be spent, which is what ECOLOGY_MODEL locks against; here it is unrepresentable rather than forbidden by convention. | Rejected | Error | |---|---| | Installing a second record for one habitat and genome | `duplicate_cohort` | | Replacing a record that is not installed, or naming a different habitat or genome | `unknown_cohort` | | Replacing under a different worker | `wrong_owner` | | Replacing under an older epoch | `stale_epoch` | | Replacing with a repeated or older revision inside one epoch | `stale_revision` | | Replacing with an earlier interval boundary, under any epoch | `backward_tick` | | Installing beyond `max_cohorts` (4,096) | `registry_full` | A replacement has to be a strictly later view of the same record. An epoch alone cannot establish that, because two writes an owner makes inside one epoch are otherwise interchangeable and replaying the earlier one would restore inventory the installed record had already spent. The revision orders writes within an epoch; a newer epoch may restart the series, since re-acquiring ownership begins a new one. The interval boundary is checked independently of both, so neither advancing a revision nor re-acquiring ownership rewinds simulated time. A later revision at the same boundary is legitimate and accepted: it is a correction. Epochs make a stale writer fail locally; they say nothing about fencing between workers, which is M7 and M10. The registry is in-memory, single-process and holds no lock, lease or quorum. A cohort is copy-only. A moved-from record would keep its identities and lose its classes, which is the invalid state construction refuses, so the implicit moves are suppressed and a move decays to a copy.