Keep a distribution, because a mean cannot say who survives
M4.1 defines the tier 2 record and who may act on it, and nothing else: no collapse transaction, no population advance, no materialization, no habitat geometry. Those are M4.2 to M4.4 and each needs its own decision. The named risk for this step is that population averages hide viable outliers, which is a property of the record rather than of the maths applied to it later, so it is answered here. Age classes each carry their own count and their own reserve. A count with a mean reserve cannot tell a provisioned cohort from one where half the members hold nothing, and nothing downstream can recover what that discarded. Within a class members are indistinguishable; that is the declared resolution and a stated loss. No accessor returns a mean, because an average that is easy to reach becomes the authority. Totals are summed from the classes rather than stored beside them, following the archive's rule that a second tally is a thing that can disagree. Lineage is not a field at all: ancestry is resolved from the genome through the archive, so a cohort cannot contradict it or invent parentage from membership. Residuals are integer numerators strictly below one member and are never added to a count. Ownership is enforced rather than described. One record per habitat and genome makes no-inventory-spendable-in-two-tiers unrepresentable instead of forbidden, and replacement is refused under a different worker or an older epoch. That is a single-process invariant; fencing between workers is M7 and M10. The approximation bound is carried and never computed, since carrying a bound is not meeting one. All nine guards were confirmed load-bearing by removing each and rerunning. An earlier sweep reporting none of them load-bearing was wrong and discarded: it wrote to /tmp, which Git Bash and PowerShell resolve differently, so nothing was ever mutated. Release 34/34, analysis, ASan 34/34 and clang-format all ran and passed here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
# 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 this record was integrated to |
|
||||
| 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 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` |
|
||||
| Installing beyond `max_cohorts` (4,096) | `registry_full` |
|
||||
|
||||
An owner replacing under its own current epoch is the ordinary case and is
|
||||
accepted. 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.
|
||||
Reference in New Issue
Block a user