Refuse the whole conversion rather than drop the inconvenient member
M4.2 moves individuals into the M4.1 record and does only that: no advance, no materialization back, no transfer between habitats, no persistence. Collapse is two phases over one sample. plan_collapse reads the members once and returns an immutable plan that already carries a validated cohort; commit applies exactly that plan and derives nothing, so replaying a committed sample cannot resample, and a record that would not validate fails during planning rather than after the ledger has moved. A controlled, suspended, dead or unsettled member refuses the whole plan instead of being skipped. Filtering would let a caller obtain a plan by omitting whoever was inconvenient, and the result would be indistinguishable from an honest conversion, which is the adversarial selection the model forbids. Ages are carried into declared classes and a member fitting none refuses the plan, so nobody is quietly moved or dropped for having nowhere to go. Reserves are summed per class and never redistributed, so the distribution M4.1 exists to keep survives the move. Conservation runs through the ledger rather than beside it: one atomic transaction, one leg per member, each moving that member's entire reserve, so the conserved total is unchanged by construction. Dual representation is closed from both ends. A member must be emptied exactly, and a reservoir holding anything other than what was sampled makes the plan stale rather than partly applicable. The destination is proved available before anything moves, so no rejection can strand biomass in a reservoir nothing owns. Reversing that order is detected by the tests, which is the point: the ordering prevents the failure rather than a comment claiming it cannot happen. Two gaps are stated rather than implied covered. This cannot tell whether the members offered were all there were, so completeness is the caller's obligation. And emptying a reservoir is not withdrawing the right to use it, because the ledger has no removal. ReservoirId and Transfer gain the defaulted comparisons every other value type here already has, so a plan's legs can be compared. Additive, and ADR-0037 says so rather than claiming no M1 change. All ten guards were confirmed load-bearing by removing each and rerunning. One of my own expectations was wrong rather than the code: a replayed commit reported stale_plan where I expected destination_occupied. Both are pure checks made before anything moves, so only the diagnosis differed; the destination check runs first now, because "this already happened" says more about a replay. Release 35/35, analysis, ASan 35/35 and clang-format all ran and passed here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -157,3 +157,37 @@ Carrying a bound is not meeting one; M4.5 is where resolution equivalence is
|
||||
measured. Conservation between a cohort and the rest of the world is the ledger's
|
||||
property and is not asserted by this type, which holds an inventory without
|
||||
participating in any transfer.
|
||||
|
||||
## Implemented M4.2 collapse
|
||||
|
||||
[ADR-0037](../adr/0037-collapse-to-cohort.md) implements `PlanCollapse` and
|
||||
`CommitCollapse` for a single habitat and genome in one process. It settles
|
||||
nothing else: `AdvancePopulation`, `PlanMaterialize`, `CommitMaterialize` and
|
||||
`TransferPopulation` remain contracts nothing implements, and the direction is
|
||||
one-way until M4.4.
|
||||
|
||||
Collapse is two phases over one sample, so recovery replays a committed sample and
|
||||
never samples again: the plan is immutable, carries an already-validated cohort,
|
||||
and commit derives nothing. Members that are controlled, suspended, dead or
|
||||
unsettled are rejected as this document requires, and rejection refuses the whole
|
||||
plan rather than dropping the member. That is what makes adversarial selection
|
||||
visible: a conversion cannot quietly exclude the unhealthy and still look honest.
|
||||
Age, and the per-class reserve distribution, are carried through unchanged; a
|
||||
member whose age fits no declared class refuses the plan rather than being moved
|
||||
into one.
|
||||
|
||||
Exact inventory is totalled through the ledger, not alongside it. One atomic
|
||||
transaction carries one leg per member, each moving that member's entire reserve,
|
||||
so the conserved total is unchanged by construction and no remainder is left in a
|
||||
second tier. The destination is proved available before anything moves, so a
|
||||
refusal cannot strand biomass in a reservoir nothing owns, and every rejection
|
||||
leaves both the ledger and the registry exactly as they were.
|
||||
|
||||
Two gaps are explicit. This cannot establish that the members offered were all the
|
||||
members there were; completeness is the caller's obligation. And "remove active
|
||||
spending rights" is implemented as emptying, because the ledger has no reservoir
|
||||
removal: nothing prevents a later transfer crediting an emptied reservoir, and
|
||||
only the registry's single-ownership rule bounds what that would mean. Durable
|
||||
conversion sequence numbers, escrow and crash recovery across a process boundary
|
||||
are M7 and M8; the before-and-after property proved here holds across a rejection
|
||||
inside one process.
|
||||
|
||||
Reference in New Issue
Block a user