From 9984f78940a53dd4dd9d3b42d7b3c8f23617732c Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 10 Oct 2026 21:55:07 -0400 Subject: [PATCH] Close cellular starvation into corpse transfer --- .../0104-cellular-single-life-tick-order.md | 7 +-- ...cellular-starvation-and-corpse-transfer.md | 49 +++++++++++++++++++ docs/adr/README.md | 1 + docs/engineering/M11_3_DELIVERY_PLAN.md | 3 ++ docs/engineering/VALIDATION.md | 16 ++++++ include/evo/biology/cellular_region_step.hpp | 18 ++++++- src/biology/cellular_region_step.cpp | 22 +++++++++ tests/cellular_region_step_tests.cpp | 28 +++++++---- 8 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 docs/adr/0107-cellular-starvation-and-corpse-transfer.md diff --git a/docs/adr/0104-cellular-single-life-tick-order.md b/docs/adr/0104-cellular-single-life-tick-order.md index e30b983..1f15ce7 100644 --- a/docs/adr/0104-cellular-single-life-tick-order.md +++ b/docs/adr/0104-cellular-single-life-tick-order.md @@ -55,6 +55,7 @@ shared candidate habitat before invoking or replacing this single-life helper. The pure biology resolver composes rate conversion, movement affordability, heat transfer and one contact-gated patch intake into a detached value. ADR-0106 adds shared-stock arbitration around this single-life proposal. Neither -helper is yet connected to life ownership, the cellular checkpoint, network -intentions or durable outcomes. Those integrations are required before the -exploratory hands-on probe. +helper is a complete region owner. ADR-0107 closes maintenance failure with a +same-tick corpse candidate. Life ownership, heat publication, the cellular +checkpoint, network intention consumption and durable outcomes remain open. +Those integrations are required before the exploratory hands-on probe. diff --git a/docs/adr/0107-cellular-starvation-and-corpse-transfer.md b/docs/adr/0107-cellular-starvation-and-corpse-transfer.md new file mode 100644 index 0000000..16549fd --- /dev/null +++ b/docs/adr/0107-cellular-starvation-and-corpse-transfer.md @@ -0,0 +1,49 @@ +# ADR-0107: Cellular starvation and corpse transfer trial + +## Status + +Accepted for the M11.3 exploratory slice (2026-10-10). It implements the +maintenance failure already specified by ADR-0104 and the inventory-retention +requirement from ADR-0098; the player-facing starvation message and later corpse +decay remain open. + +## Context + +ADR-0104 says maintenance is paid first and an organism that cannot pay must die +in the same tick. ADR-0098 says death retains a corpse or detritus with the +organism's inventory. The cellular tick must not leave a permanently starving +life active, partially debit it, or lose usable reserve/body mass. Movement costs +already credited to heat need a destination distinct from the corpse's usable +inventory. + +## Decision + +- If starting reserve cannot pay the full rounded-up maintenance cost, the life + dies before movement or intake in that tick. No partial maintenance is charged. +- Transfer body matter and reserve energy/matter exactly once into one corpse + candidate at the death position. The body contains matter only. +- Transfer the life's accumulated energy-only heat separately to the region heat + owner. Heat is not made ingestible corpse energy. +- Resolve all survivors, corpses, patch updates and heat outputs in one detached + region candidate. Any invalid identity, overflow or other refused life step + returns no candidate, so the host publishes nothing. +- This trial adds no decay, scavenging, engulfment or corpse timer. The life owner + records terminal lineage and atomically publishes the candidate later. + +## Alternatives considered + +- **Leave an unpaid life active:** rejected because it skips the selected upkeep + rule and permits free offline survival. +- **Charge a partial upkeep:** rejected because it gives maintenance a new + partial-payment rule and creates ambiguity about what the organism dies with. +- **Put heat in the corpse:** rejected because that would make already-spent + movement/maintenance energy usable again through feeding. +- **Discard heat:** rejected because ADR-0058 requires accounted heat to remain in + the closed inventory total. + +## Consequences + +The pure candidate can close starvation without mutating the source habitat or +life inputs. The durable owner still needs a heat destination and a transaction +that publishes life death, corpse, patch changes, heat, checkpoint and outcomes +together. No persistence or player-facing behavior is claimed here. diff --git a/docs/adr/README.md b/docs/adr/README.md index 6ae0db5..992a562 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -7,6 +7,7 @@ - [ADR-0104: Cellular single-life tick order trial](0104-cellular-single-life-tick-order.md) - accepted M11.3 order for maintenance, funded movement and one contact-gated intake proposal; life ownership and durable publication remain open. - [ADR-0105: Cellular session intention protocol v6](0105-cellular-session-intention-v6.md) - accepted M11.3 wire direction for movement plus an optional food-patch target; v1-v5 remain frozen and v6 has an opt-in admission path. - [ADR-0106: Cellular contested patch arbitration trial](0106-cellular-contested-patch-arbitration.md) - accepted M11.3 trial resolves same-tick finite-stock claims by stable life identity, independent of connection order. +- [ADR-0107: Cellular starvation and corpse transfer trial](0107-cellular-starvation-and-corpse-transfer.md) - accepted M11.3 death closure transfers body/reserve to a corpse and accumulated heat to the region heat owner. - [ADR-0058: Region durability contract](0058-region-durability-contract.md) - accepted M7.1 full checkpoint batches and explicit state closure; storage implementation follows. diff --git a/docs/engineering/M11_3_DELIVERY_PLAN.md b/docs/engineering/M11_3_DELIVERY_PLAN.md index 745166f..bedab87 100644 --- a/docs/engineering/M11_3_DELIVERY_PLAN.md +++ b/docs/engineering/M11_3_DELIVERY_PLAN.md @@ -142,6 +142,9 @@ scoped change before starting the next segment. contention. A detached multi-life candidate resolves all claims against each patch's remaining per-channel stock; starvation still refuses the candidate pending same-tick death/corpse closure. +- 11.3c-5: ADR-0107 closes unaffordable maintenance in the same tick, moving body + and reserve into a corpse candidate and accumulated heat to an explicit output. + The durable heat owner and lineage/checkpoint publication remain open. ## Exit boundary diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index e973515..3e769a4 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -6003,3 +6003,19 @@ implementation and test; and `git diff --check`. The tests confirm input-order independent arbitration, per-channel conservation, no mutation of the source habitat and no partial result for duplicate identities or starvation. CTest and Linux sanitizer/CI qualification remain pending. + +## 2026-10-10 — M11.3c-5 starvation and corpse transfer (CI pending) + +ADR-0107 closes unaffordable maintenance in the same tick. The detached region +candidate removes the starved life, transfers its body and reserve matter to a +corpse, and reports accumulated heat separately. The helper still does not own +or durably publish the heat ledger, lineage outcome, habitat, or action result. + +Executed locally: warning-as-error MSVC 19.44 Debug and Release/NDEBUG direct +compile/run of the focused region-step regression; the regression confirms +same-tick death, exact body/reserve transfer, separate heat output, no patch +mutation, and unchanged all-or-nothing handling of duplicate identities; +and `git diff --check`. `clang-format` and `clang-tidy` were not installed or +available on PATH in this Windows environment. CTest, Linux sanitizer/CI +qualification, durable heat ownership, lineage and checkpoint publication +remain pending. diff --git a/include/evo/biology/cellular_region_step.hpp b/include/evo/biology/cellular_region_step.hpp index 9d6c7de..79b1288 100644 --- a/include/evo/biology/cellular_region_step.hpp +++ b/include/evo/biology/cellular_region_step.hpp @@ -17,8 +17,9 @@ struct CellularLifeStepInput { CellularPosition position; std::uint32_t extent_um{}; CellularStepIntent intent; + accounting::Inventory body; // Structural matter; energy must be zero. accounting::Inventory reserve; - accounting::Inventory heat; + accounting::Inventory heat; // Energy-only owner; matter channels must be zero. MetabolicBudget budget; auto operator<=>(const CellularLifeStepInput&) const = default; }; @@ -32,11 +33,19 @@ struct CellularPatchStockUpdate { accounting::Inventory stock; auto operator<=>(const CellularPatchStockUpdate&) const = default; }; +struct CellularCorpseCandidate { + std::uint64_t life_id{}; + CellularPosition position; + accounting::Inventory inventory; // Body and reserve; accumulated heat is transferred out. + auto operator<=>(const CellularCorpseCandidate&) const = default; +}; struct CellularRegionStepCandidate { std::uint64_t begin_tick{}, end_tick{}; // Sorted by stable life_id, independent of connection or input order. std::vector lives; std::vector patches; + std::vector starved; + accounting::Picojoules heat_released{}; auto operator<=>(const CellularRegionStepCandidate&) const = default; }; enum class CellularRegionStepError : std::uint8_t { @@ -44,13 +53,18 @@ enum class CellularRegionStepError : std::uint8_t { too_many_lives, invalid_life_id, duplicate_life_id, + invalid_body, + invalid_heat, + overflow, life_step, habitat }; // Detached shared-habitat candidate. Same-tick claims resolve by ascending stable life id; // the first valid claimant spends from each patch's remaining per-channel stock. Any refused -// life step rejects the complete candidate; the caller publishes nothing. +// life step rejects the complete candidate; the caller publishes nothing. If maintenance +// cannot be paid, the life dies in this tick: body and reserve move to one corpse candidate, +// and its accumulated heat is reported separately for transfer to the world heat owner. [[nodiscard]] std::expected propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area, std::span lives, diff --git a/src/biology/cellular_region_step.cpp b/src/biology/cellular_region_step.cpp index 69d165f..8c8b8d7 100644 --- a/src/biology/cellular_region_step.cpp +++ b/src/biology/cellular_region_step.cpp @@ -28,18 +28,40 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area, CellularRegionStepCandidate candidate{begin_tick, begin_tick + 1, {}, {}}; candidate.lives.reserve(ordered.size()); + candidate.starved.reserve(ordered.size()); std::vector patch_stock; patch_stock.reserve(habitat.patches().size()); for (const auto& patch : habitat.patches()) patch_stock.push_back(patch.stock); for (const auto* life : ordered) { + if (life->body.energy.value != 0) + return std::unexpected{CellularRegionStepError::invalid_body}; + if (std::ranges::any_of(life->heat.matter, + [](const auto& channel) { return channel.value != 0; })) + return std::unexpected{CellularRegionStepError::invalid_heat}; auto intent = life->intent; const auto target = intent.intake_target; intent.intake_target.reset(); const auto step = propose_cellular_step(begin_tick, area, life->position, life->extent_um, intent, life->reserve, life->heat, life->budget, habitat); + if (!step && step.error() == CellularStepError::insufficient_maintenance) { + CellularCorpseCandidate corpse{life->life_id, life->position, life->reserve}; + for (std::size_t channel = 0; channel < corpse.inventory.matter.size(); ++channel) { + const auto body_matter = life->body.matter[channel].value; + const auto reserve_matter = life->reserve.matter[channel].value; + if (reserve_matter > std::numeric_limits::max() - body_matter) + return std::unexpected{CellularRegionStepError::overflow}; + corpse.inventory.matter[channel].value = body_matter + reserve_matter; + } + if (life->heat.energy.value > + std::numeric_limits::max() - candidate.heat_released.value) + return std::unexpected{CellularRegionStepError::overflow}; + candidate.heat_released.value += life->heat.energy.value; + candidate.starved.push_back(corpse); + continue; + } if (!step) return std::unexpected{CellularRegionStepError::life_step}; auto result = *step; diff --git a/tests/cellular_region_step_tests.cpp b/tests/cellular_region_step_tests.cpp index c9fdf10..b77b8c6 100644 --- a/tests/cellular_region_step_tests.cpp +++ b/tests/cellular_region_step_tests.cpp @@ -34,10 +34,10 @@ std::unique_ptr habitat() { void shared_patch_claims_are_identity_ordered_and_conserved() { const auto map = habitat(); - const CellularLifeStepInput later{ - 20, {0, 0}, 20, {{0, 0}, CellularPatchAddress{0, 0}}, {{100}, {}}, {}, budget()}; - const CellularLifeStepInput earlier{ - 10, {0, 0}, 20, {{0, 0}, CellularPatchAddress{0, 0}}, {{100}, {}}, {}, budget()}; + const CellularLifeStepInput later{20, {0, 0}, 20, {{0, 0}, CellularPatchAddress{0, 0}}, + {}, {{100}, {}}, {}, budget()}; + const CellularLifeStepInput earlier{10, {0, 0}, 20, {{0, 0}, CellularPatchAddress{0, 0}}, + {}, {{100}, {}}, {}, budget()}; const std::array input{later, earlier}; // Deliberately opposite the arbitration order. const auto candidate = propose_cellular_region_step(4, {3'000, 2'000}, input, *map); CHECK(candidate); @@ -73,18 +73,26 @@ void shared_patch_claims_are_identity_ordered_and_conserved() { void refusal_never_returns_partial_tick_state() { const auto map = habitat(); - const std::array duplicate{CellularLifeStepInput{1, {0, 0}, 20, {}, {{100}, {}}, {}, budget()}, - CellularLifeStepInput{1, {0, 0}, 20, {}, {{100}, {}}, {}, budget()}}; + const std::array duplicate{ + CellularLifeStepInput{1, {0, 0}, 20, {}, {}, {{100}, {}}, {}, budget()}, + CellularLifeStepInput{1, {0, 0}, 20, {}, {}, {{100}, {}}, {}, budget()}}; const auto repeated = propose_cellular_region_step(4, {3'000, 2'000}, duplicate, *map); CHECK(!repeated && repeated.error() == CellularRegionStepError::duplicate_life_id); - auto starved_life = CellularLifeStepInput{2, {0, 0}, 20, {}, {{0}, {}}, {}, budget()}; + auto starved_life = CellularLifeStepInput{ + 2, {0, 0}, 20, {}, {{0}, {{{1}, {2}, {3}, {4}}}}, {{0}, {{{1}, {1}, {1}, {1}}}}, + {{17}, {}}, budget()}; auto starved_budget = budget(); starved_budget.maintenance = {1'000}; starved_life.budget = starved_budget; const std::array starved{starved_life}; - const auto refused = propose_cellular_region_step(4, {3'000, 2'000}, starved, *map); - CHECK(!refused && refused.error() == CellularRegionStepError::life_step); + const auto result = propose_cellular_region_step(4, {3'000, 2'000}, starved, *map); + CHECK(result); + CHECK(result->begin_tick == 4 && result->end_tick == 5); + CHECK(result->lives.empty() && result->starved.size() == 1); + CHECK(result->starved[0] == CellularCorpseCandidate{2, {0, 0}, {{0}, {{{2}, {3}, {4}, {5}}}}}); + CHECK(result->heat_released.value == 17); + CHECK(result->patches.empty()); CHECK(map->patches()[0].stock == Inventory{{5}, {{{2}, {2}, {2}, {2}}}}); } } // namespace @@ -93,7 +101,7 @@ int main() { try { shared_patch_claims_are_identity_ordered_and_conserved(); refusal_never_returns_partial_tick_state(); - std::puts("PASS cellular region step: deterministic shared-stock candidate"); + std::puts("PASS cellular region step: shared claims and starvation closure"); } catch (const std::exception& error) { std::fprintf(stderr, "%s\n", error.what()); return 1;