diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 916a939..2c79a49 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -6037,7 +6037,8 @@ advances a complete stable-ID intention set against one shared habitat, and atomically applies living results, death records, corpses, heat and patch stock only when the region-wide totals still reconcile. The focused test covers contested intake, a late invalid intention with no partial advance, and both -founders reaching terminal death while retaining complete lineage and inventory. +founders reaching terminal death while retaining complete lineage, inventory, +life/source provenance and final growth state in stable-order corpses. Executed locally: direct warning-as-error MSVC 19.44 Debug and Release/NDEBUG compile/run; Debug CTest `cellular-lives-owner` (1/1 passed); CMake configure and diff --git a/include/evo/server/lifecycle/cellular_lives.hpp b/include/evo/server/lifecycle/cellular_lives.hpp index acdd576..ed14def 100644 --- a/include/evo/server/lifecycle/cellular_lives.hpp +++ b/include/evo/server/lifecycle/cellular_lives.hpp @@ -4,6 +4,7 @@ #include "evo/server/lifecycle/primitive_lives.hpp" #include +#include #include #include #include @@ -11,6 +12,9 @@ #include namespace evo::server { +inline constexpr std::uint32_t cellular_lives_format = 1; +inline constexpr std::size_t max_cellular_lives_bytes = std::size_t{8} * 1024 * 1024; + struct CellularOwnedLife { LifeAccount account{}; LifeAllocation identity{}; @@ -22,9 +26,13 @@ struct CellularOwnedLife { auto operator<=>(const CellularOwnedLife&) const = default; }; struct CellularOwnedCorpse { + std::uint64_t life_id{}; std::uint64_t organism{}; + std::uint64_t source{}; std::uint64_t died_tick{}; biology::CellularPosition position{}; + biology::GrowthState growth{}; + std::uint32_t extent_um{}; accounting::Inventory inventory{}; auto operator<=>(const CellularOwnedCorpse&) const = default; }; @@ -50,7 +58,11 @@ enum class CellularLivesError : std::uint8_t { archive, habitat, overflow, - conservation + conservation, + format, + version, + checksum, + noncanonical }; // In-memory authoritative cellular owner. It consumes funded profile-3 opening @@ -79,6 +91,11 @@ class CellularLives { [[nodiscard]] accounting::Inventory heat() const noexcept; [[nodiscard]] accounting::Inventory opening_total() const noexcept; [[nodiscard]] accounting::Inventory current_total() const noexcept; + [[nodiscard]] std::vector snapshot() const; + + [[nodiscard]] static std::expected, CellularLivesError> + restore(std::span bytes, std::uint64_t world, std::uint64_t region, + std::uint64_t frame, std::uint64_t tick); // Advances every living cell exactly one 50 ms tick. Intentions are keyed by // stable life ID and must cover the living set exactly. Any refusal leaves diff --git a/src/server/lifecycle/cellular_lives.cpp b/src/server/lifecycle/cellular_lives.cpp index f4f565f..cfdaa26 100644 --- a/src/server/lifecycle/cellular_lives.cpp +++ b/src/server/lifecycle/cellular_lives.cpp @@ -53,6 +53,7 @@ sum_state(accounting::Inventory nursery, accounting::Inventory heat, struct CellularLives::State { std::uint64_t world{}, region{}, frame{}; CellularLivesConfig config{}; + NurseryConfig nursery_config{}; std::unique_ptr habitat; std::vector lives; std::vector corpses; @@ -63,12 +64,13 @@ struct CellularLives::State { accounting::Inventory current_total{}; State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id, - CellularLivesConfig cfg, std::unique_ptr map, + CellularLivesConfig cfg, NurseryConfig nursery, std::unique_ptr map, std::vector living, std::vector dead, const biology::LineageArchive& history, accounting::Inventory source, accounting::Inventory accumulated_heat, accounting::Inventory initial, accounting::Inventory current) : world{world_id}, region{region_id}, frame{frame_id}, config{cfg}, + nursery_config{std::move(nursery)}, habitat{std::move(map)}, lives{std::move(living)}, corpses{std::move(dead)}, archive{history}, nursery{source}, heat{accumulated_heat}, opening_total{initial}, current_total{current} {} @@ -83,7 +85,7 @@ CellularLives::create(const PrimitiveLives& opening, CellularLivesConfig config) { if (!habitat) return std::unexpected{CellularLivesError::invalid_config}; - const auto& nursery_config = opening.config(); + auto nursery_config = opening.config(); const auto& map = habitat->config(); if (nursery_config.world == 0 || nursery_config.region == 0 || nursery_config.frame == 0 || map.world != nursery_config.world || map.region != nursery_config.region || @@ -136,6 +138,7 @@ CellularLives::create(const PrimitiveLives& opening, if (!add_inventory(initial_total, habitat->totals())) return std::unexpected{CellularLivesError::overflow}; const auto nursery = opening.balances()[0]; + nursery_config.funding = nursery; const auto heat = opening.balances()[1]; const auto current = sum_state(nursery, heat, *habitat, lives, {}); if (!current) @@ -145,6 +148,7 @@ CellularLives::create(const PrimitiveLives& opening, auto state = std::make_unique( nursery_config.world, nursery_config.region, nursery_config.frame, config, + std::move(nursery_config), std::move(habitat), std::move(lives), std::vector{}, opening.archive(), nursery, heat, initial_total, *current); return std::unique_ptr{new CellularLives{std::move(state)}}; @@ -226,8 +230,18 @@ CellularLives::advance_tick(std::span intents) { if (found == next_lives.end() || found->identity.life != dead.life_id || !next_archive.record_death(found->identity.organism, {proposal->end_tick})) return std::unexpected{CellularLivesError::archive}; - next_corpses.push_back( - {found->identity.organism, proposal->end_tick, dead.position, dead.inventory}); + const auto corpse_budget = budget_for( + next_archive, *found, state_->config.ambient_temperature_millikelvin); + if (!corpse_budget) + return std::unexpected{corpse_budget.error()}; + next_corpses.push_back({found->identity.life, + found->identity.organism, + found->source, + proposal->end_tick, + dead.position, + found->growth, + corpse_budget->phenotype.extent, + dead.inventory}); next_lives.erase(found); } std::ranges::sort(next_corpses, {}, &CellularOwnedCorpse::organism); @@ -258,6 +272,7 @@ CellularLives::advance_tick(std::span intents) { state_->world, state_->region, state_->frame, CellularLivesConfig{state_->config.area, proposal->end_tick, state_->config.ambient_temperature_millikelvin}, + state_->nursery_config, std::move(*next_habitat), std::move(next_lives), std::move(next_corpses), next_archive, state_->nursery, next_heat, state_->opening_total, *total); state_.swap(next); diff --git a/tests/cellular_lives_tests.cpp b/tests/cellular_lives_tests.cpp index 5438b7c..a0220fc 100644 --- a/tests/cellular_lives_tests.cpp +++ b/tests/cellular_lives_tests.cpp @@ -84,6 +84,9 @@ void owner_advances_and_closes_death_atomically() { CHECK(owner.lives().empty() && owner.corpses().size() == 2 && steps < 2'000); CHECK(owner.corpses()[0].organism == 101 && owner.corpses()[0].died_tick <= owner.tick()); CHECK(owner.corpses()[1].organism == 102 && owner.corpses()[1].died_tick <= owner.tick()); + CHECK(owner.corpses()[0].life_id == 1 && owner.corpses()[0].source == 17 && + owner.corpses()[0].growth == (evo::biology::GrowthState{1000, 0}) && + owner.corpses()[0].extent_um == 20); const auto lineage = owner.archive().organism(101); CHECK(lineage && !lineage->alive && lineage->died.value == owner.corpses()[0].died_tick); const auto second_lineage = owner.archive().organism(102);