A cohort's reserve is the whole of its reservoir, not a part of it

Commit proved the destination reservoir existed and that the registry slot was
free, but never that the reservoir was empty. Gathering into an occupied
reservoir therefore succeeded and mixed inventory the conversion had never
sampled into the cohort's backing store: the cohort's recorded reserve
understated what backed it, and the surplus belonged to nobody.

Reproduced against the unfixed code rather than taken on trust. Gathering into
reservoir 5, which the fixture already seeds with seven picojoules, commits and
leaves the ledger holding 67 against a cohort recording 60, exactly as reported.

A destination holding anything is refused now. The success test also asserts the
destination balance equals the installed cohort's reserve, so the equality is
checked rather than assumed, and the regression asserts the refusal leaves the
balances, the action counter and the registry as they were, then that emptying
the reservoir first makes the same plan committable.

The check runs after the staleness loop rather than beside the other destination
checks. Both run before anything moves, so it is a reporting choice: replaying a
committed plan into a fresh registry would be refused by either, and that the
members no longer hold what was sampled says more than that the reservoir is
occupied.

The guard was confirmed load-bearing by removing it alone. An earlier attempt at
that reported it as not load-bearing; that result was void and discarded, because
a heredoc had mangled the mutation script and nothing was ever mutated. Second
time this quirk has produced a false negative in a sweep, and both times the
printed output rather than the exit status is what caught it.

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:59:39 -04:00
co-authored by Claude Opus 5
parent 1a59b63c7a
commit 0697895e25
7 changed files with 117 additions and 10 deletions
+10
View File
@@ -366,3 +366,13 @@ that reservoir again. Durable conversion sequences, escrow and replay across a
process boundary are M7 and M8. All ten construction and commit guards were
confirmed load-bearing by removing each and observing a failing run. Native
Release, analysis, ASan and formatting passed 35/35; Linux CI has not run yet.
Review of `1a59b63` found one defect, now fixed with a regression confirmed to
fail without it. Commit checked that the destination reservoir existed and that
the registry slot was free, but not that the reservoir was empty, so a conversion
into an occupied reservoir succeeded and mixed inventory it never sampled into the
cohort's backing store. The reported case reproduces exactly: the ledger holds 67
picojoules against a cohort recording 60, so the cohort's reserve understated what
backed it and the surplus belonged to nobody. A destination holding anything is
now refused, a cohort's reserve is the whole of its reservoir rather than a part
of it, and the success test asserts that equality directly.
+15 -3
View File
@@ -60,12 +60,22 @@ ECOLOGY_MODEL locks against.
Ordering inside commit is chosen so no failure can strand inventory. The
destination is checked before anything moves: the registry must not already hold
this habitat and genome and must have room. Only then does the ledger transaction
this habitat and genome and must have room, and the destination reservoir itself
must be empty. An occupied reservoir would mix inventory the conversion never
sampled into the cohort's backing store, so the cohort's recorded reserve would
understate what backs it and the surplus would belong to nobody. A cohort's
reserve is therefore the whole of its reservoir, not a part of it. Only then does the ledger transaction
run, and only then is the cohort installed, which cannot fail because the plan
carries a cohort already validated and the destination was already proved
available. Every rejection therefore leaves the ledger and the registry exactly as
they were.
The reservoir's emptiness is checked after the sample rather than beside the other
destination checks. Both run before anything moves, so this is a reporting choice:
when a committed plan is replayed into a fresh registry both would refuse it, and
the informative answer is that the members no longer hold what was sampled rather
than that this reservoir is occupied.
## Alternatives Considered
Skipping ineligible members instead of refusing would make adversarial selection
@@ -121,8 +131,10 @@ that every ineligible state refuses the whole plan and names the member, that a
foreign habitat or genome, a duplicate identity, an unclassifiable age, an empty
group and a group beyond the transaction limit are each refused. Test that a
committed collapse leaves the ledger's conserved total unchanged, empties every
member reservoir, credits the destination with exactly the planned total and
installs the cohort. Test that a plan which is never committed changes nothing,
member reservoir, credits the destination with exactly the planned total, leaves
the cohort's reserve equal to the whole of that reservoir, and installs the
cohort. Test that a destination reservoir already holding anything is refused, and
that emptying it first makes the same plan committable. Test that a plan which is never committed changes nothing,
that a commit refused at the destination or on a stale balance changes nothing in
either the ledger or the registry, and that committing one plan twice is refused
without moving inventory a second time. Test that the plan is copy-only, since a
+5 -3
View File
@@ -179,9 +179,11 @@ 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.
second tier. The destination is proved available and empty before anything moves,
so a refusal cannot strand biomass in a reservoir nothing owns and a cohort's
recorded reserve is the whole of what backs it rather than a part sharing a
reservoir with inventory it never sampled. 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
+34
View File
@@ -1027,3 +1027,37 @@ 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`.
Review of `1a59b63` found one defect (2026-09-24), now fixed with a regression
confirmed to fail against the unfixed code.
Commit proved the destination reservoir existed and that the registry slot was
free, but never that the reservoir was empty. A conversion into an occupied
reservoir therefore succeeded and mixed inventory it had never sampled into the
cohort's backing store, leaving the cohort's recorded reserve understating what
backed it and the surplus owned by nobody. The reported case was reproduced
against the unfixed code rather than assumed: gathering into reservoir 5, which
the fixture already seeds with seven picojoules, commits successfully and leaves
the ledger holding 67 against a cohort recording 60.
A destination holding anything is now refused. The success test additionally
asserts that the destination balance equals the installed cohort's reserve, so a
cohort's reserve is the whole of its reservoir rather than a part of it, and the
new regression asserts that the refusal leaves the ledger balances, the ledger
action counter and the registry all exactly as they were, then that emptying the
reservoir first makes the same plan committable.
The check runs after the staleness loop rather than beside the other destination
checks. Both run before anything moves, so this is a reporting choice and not a
safety one: replaying a committed plan into a fresh registry would be refused by
either, and that the members no longer hold what was sampled is the more useful
answer than that the reservoir is occupied. The ordering rationale is recorded
beside the check.
The guard was confirmed load-bearing by removing it alone, which fails the new
regression. An earlier attempt to add that mutation reported the guard as not
load-bearing; the result was void and discarded, because a Bash heredoc had
mangled the escaped newlines in the mutation script and the script failed to
parse, so nothing was ever mutated. It is the second time this environment quirk
has produced a false negative in a mutation sweep, and both times the printed
output rather than the exit status is what revealed it.
+8 -4
View File
@@ -46,7 +46,9 @@ struct CollapseRequest {
std::uint64_t genome{};
Tick tick{};
std::uint64_t revision{};
// Where the members' inventory is gathered. Must not be a member's own.
// Where the members' inventory is gathered. Must not be a member's own, and
// must be empty when the plan is committed, so the cohort's recorded reserve
// is the whole of what its reservoir holds.
accounting::ReservoirId destination{};
std::vector<AgeBound> bounds;
ApproximationBound bound{};
@@ -65,6 +67,7 @@ enum class CollapseError : std::uint8_t {
invalid_cohort,
stale_plan,
destination_occupied,
destination_not_empty,
destination_unavailable,
ledger_failure
};
@@ -119,9 +122,10 @@ class CollapsePlan {
[[nodiscard]] std::expected<CollapsePlan, CollapseError>
plan_collapse(std::span<const ActiveMember> members, const CollapseRequest& request);
// Applies exactly that plan. The destination is proved available before anything
// moves, so no rejection can strand inventory in a reservoir nothing owns: every
// failure leaves the ledger and the registry as they were.
// Applies exactly that plan. The destination is proved available and empty before
// anything moves, so no rejection can strand inventory in a reservoir nothing owns
// and the cohort's reserve is exactly what its reservoir holds: every failure
// leaves the ledger and the registry as they were.
[[nodiscard]] std::expected<Cohort, CollapseError>
commit_collapse(accounting::Ledger& ledger, CohortRegistry& registry, const CollapsePlan& plan);
} // namespace evo::ecology
+9
View File
@@ -160,6 +160,15 @@ commit_collapse(accounting::Ledger& ledger, CohortRegistry& registry, const Coll
return std::unexpected{CollapseError::stale_plan};
}
}
// A destination already holding something would mix unrelated inventory into
// the cohort's reservoir while the cohort recorded only what it sampled, so
// its reserve would understate what backs it and the surplus would belong to
// nobody. Checked after the sample, because when a committed plan is replayed
// into a fresh registry the informative answer is that the members no longer
// hold what was sampled, not that this reservoir is occupied.
if (balances[plan.destination().value - 1] != accounting::Inventory{}) {
return std::unexpected{CollapseError::destination_not_empty};
}
if (ledger.last_action() == maximum) {
return std::unexpected{CollapseError::ledger_failure};
}
+36
View File
@@ -219,6 +219,9 @@ void a_committed_collapse_conserves_and_empties_the_members() {
CHECK(found.has_value());
CHECK(*found == plan.cohort());
CHECK(found->reserve() == plan.total());
// The cohort's recorded reserve is the whole of what backs it, not a part of
// it: nothing else shares the reservoir the conversion gathered into.
CHECK(ledger.balances()[destination.value - 1] == found->reserve());
CHECK(*installed == plan.cohort());
}
@@ -275,6 +278,38 @@ void every_rejection_leaves_the_world_as_it_was() {
CHECK(spare.size() == 0);
}
void a_destination_holding_anything_is_refused() {
// Gathering into an occupied reservoir would mix unrelated inventory into the
// cohort's backing store while the cohort recorded only what it sampled, so
// its reserve would understate what backs it and the surplus would be owned
// by nobody. Reservoir 5 already holds something in this fixture.
auto ledger = world();
CohortRegistry registry;
auto elsewhere = request();
elsewhere.destination = {5};
const auto offered = members();
const auto plan = plan_collapse(offered, elsewhere);
CHECK(plan.has_value());
CHECK(plan->total() == held(60, 600));
const auto opening = std::vector<Inventory>{ledger.balances().begin(), ledger.balances().end()};
const auto action = ledger.last_action();
CHECK(refused(commit_collapse(ledger, registry, *plan), CollapseError::destination_not_empty));
// Unfixed this committed, leaving the reservoir holding 67 energy against a
// cohort recording 60. Rejection must leave both sides exactly as they were.
CHECK(std::vector<Inventory>(ledger.balances().begin(), ledger.balances().end()) == opening);
CHECK(ledger.balances()[4] == held(7, 7));
CHECK(ledger.last_action() == action);
CHECK(registry.size() == 0);
// Emptying that reservoir first makes the same plan committable, and then the
// cohort's reserve is the whole of what backs it.
const std::array clear{Transfer{{5}, {4}, held(7, 7)}};
CHECK(ledger.transfer(ledger.last_action() + 1, clear).has_value());
const auto installed = commit_collapse(ledger, registry, *plan);
CHECK(installed.has_value());
CHECK(ledger.balances()[4] == plan->total());
CHECK(ledger.balances()[4] == installed->reserve());
}
void one_plan_cannot_be_committed_twice() {
auto ledger = world();
CohortRegistry registry;
@@ -332,6 +367,7 @@ int main() try {
an_ineligible_member_refuses_the_whole_plan();
a_committed_collapse_conserves_and_empties_the_members();
every_rejection_leaves_the_world_as_it_was();
a_destination_holding_anything_is_refused();
one_plan_cannot_be_committed_twice();
a_moved_from_plan_is_still_a_whole_plan();
std::cout << "PASS collapse sampling, exact conservation and unchanged-on-rejection\n";