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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user