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:
dingo
2026-09-24 09:45:09 -04:00
co-authored by Claude Opus 5
parent 5a4c34a903
commit 1a59b63c7a
11 changed files with 932 additions and 3 deletions
+66
View File
@@ -961,3 +961,69 @@ No existing contract changed. The proof golden `d61ad5bf0c928c76`, the ecosystem
fingerprint `2cd4a15f9fbe9949`, the ensemble fingerprint `5ec59d390909b526` and
the frozen genome fixture are unchanged. Linux validation is pending; no Gitea
result is claimed since `b01a824`.
## M4.2 collapse to cohort
Executed on this Windows host (2026-09-24): Release configure, build and `ctest`
35/35; the analysis preset (clang-tidy 19, warnings as errors) built clean; the
ASan preset configured, built and ran 35/35; `clang-format` 19.1.5 reported no
violations. All four checks ran and passed on the committed tree. No Clang or GCC
compile happens on this host, so Linux CI remains the first such result.
`evo-collapse-tests` covers seven properties: that a plan totals its members
exactly and moves each member's whole reserve, that ages and the per-class reserve
distribution survive the move without redistribution, that every ineligible state
and every malformed request refuses the whole plan by name, that a committed
collapse leaves the ledger's conserved total unchanged while emptying every member
reservoir and crediting the destination, that every rejection leaves both the
ledger and the registry exactly as they were, that one plan cannot be committed
twice, and that a moved-from plan is still whole.
All ten guards were confirmed load-bearing by removing each in turn and rebuilding:
the ineligible, foreign, duplicate, self-destination, age classification, stale
sample, occupied destination, empty class and commit ordering guards, and the
copy-only declaration. Two needed a second pass. The first age mutation did not
compile, which is not evidence about the test, so it was rewritten to make the
class predicate always match, which places every member in the first class and is
detected at runtime. Removing the copy declarations fails to compile in Release
for the reason recorded for the cohort; with the static assertion also removed the
same mutation was rerun under ASan, where it exits 1, so the runtime assertions
are load-bearing independently of the compile-time proof.
The commit ordering mutation is worth naming: moving the ledger transaction ahead
of the destination check is detected, because a rejected conversion then leaves
biomass in a reservoir nothing owns while the members are already empty. That is
the dual-representation failure this milestone is named after, and the ordering is
what prevents it rather than a comment saying it does not happen.
One expectation of my own was wrong rather than the code. A replay of a committed
plan was expected to report `destination_occupied`, but the staleness check ran
first and reported `stale_plan`, which is equally true. Both are pure checks made
before anything moves, so safety was unaffected and only the diagnosis differed;
the destination check now runs first, because "this conversion already happened"
says more about a replay than "the world moved". The ordering rationale is
recorded beside it.
`accounting::ReservoirId` and `accounting::Transfer` gained the defaulted
comparisons that every other value type in the project already carries, so a
plan's legs can be compared. This is additive, no behaviour depends on it, and
ADR-0037's status was corrected to say so rather than claim no M1 change.
Coverage limits. Completeness of the offered member set is not checkable here and
is not checked: nothing establishes that the caller offered every member it had.
Emptying a reservoir is not withdrawing the right to use it, since the ledger has
no removal, so a later transfer could credit an emptied reservoir and no test
asserts otherwise. The before-and-after property is demonstrated across rejections
inside one process; there is no persistence, so a crash between the ledger
transaction and the registry install is outside what an in-memory registry can
show, and durable conversion sequences, escrow and replay stay M7 and M8. Plans
are bounded to 256 members by the ledger's transaction limit and nothing
coordinates several conversions. The ledger-failure and destination-unavailable
branches are reachable only past bounds the tests do not build, so they are
refused-by-construction rather than exercised.
No existing behaviour changed. The proof golden `d61ad5bf0c928c76`, the ecosystem
fingerprint `2cd4a15f9fbe9949`, the ensemble fingerprint `5ec59d390909b526` and
the frozen genome fixture are unchanged, and the other 34 tests pass untouched.
No deployment manifest or image pin changed. Linux validation is pending; no Gitea
result is claimed since `b01a824`.