Retain cellular death provenance and growth
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (network) (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 41s
Foundation / checks (client) (push) Canceled after 42s
Foundation / checks (ecs) (push) Canceled after 38s

This commit is contained in:
dingo
2026-10-10 22:25:06 -04:00
parent 562781ce77
commit 04cdc1e9c7
4 changed files with 42 additions and 6 deletions
+2 -1
View File
@@ -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 atomically applies living results, death records, corpses, heat and patch stock
only when the region-wide totals still reconcile. The focused test covers only when the region-wide totals still reconcile. The focused test covers
contested intake, a late invalid intention with no partial advance, and both 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 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 compile/run; Debug CTest `cellular-lives-owner` (1/1 passed); CMake configure and
@@ -4,6 +4,7 @@
#include "evo/server/lifecycle/primitive_lives.hpp" #include "evo/server/lifecycle/primitive_lives.hpp"
#include <compare> #include <compare>
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <expected> #include <expected>
#include <memory> #include <memory>
@@ -11,6 +12,9 @@
#include <vector> #include <vector>
namespace evo::server { 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 { struct CellularOwnedLife {
LifeAccount account{}; LifeAccount account{};
LifeAllocation identity{}; LifeAllocation identity{};
@@ -22,9 +26,13 @@ struct CellularOwnedLife {
auto operator<=>(const CellularOwnedLife&) const = default; auto operator<=>(const CellularOwnedLife&) const = default;
}; };
struct CellularOwnedCorpse { struct CellularOwnedCorpse {
std::uint64_t life_id{};
std::uint64_t organism{}; std::uint64_t organism{};
std::uint64_t source{};
std::uint64_t died_tick{}; std::uint64_t died_tick{};
biology::CellularPosition position{}; biology::CellularPosition position{};
biology::GrowthState growth{};
std::uint32_t extent_um{};
accounting::Inventory inventory{}; accounting::Inventory inventory{};
auto operator<=>(const CellularOwnedCorpse&) const = default; auto operator<=>(const CellularOwnedCorpse&) const = default;
}; };
@@ -50,7 +58,11 @@ enum class CellularLivesError : std::uint8_t {
archive, archive,
habitat, habitat,
overflow, overflow,
conservation conservation,
format,
version,
checksum,
noncanonical
}; };
// In-memory authoritative cellular owner. It consumes funded profile-3 opening // 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 heat() const noexcept;
[[nodiscard]] accounting::Inventory opening_total() const noexcept; [[nodiscard]] accounting::Inventory opening_total() const noexcept;
[[nodiscard]] accounting::Inventory current_total() const noexcept; [[nodiscard]] accounting::Inventory current_total() const noexcept;
[[nodiscard]] std::vector<std::uint8_t> snapshot() const;
[[nodiscard]] static std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
restore(std::span<const std::uint8_t> 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 // 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 // stable life ID and must cover the living set exactly. Any refusal leaves
+19 -4
View File
@@ -53,6 +53,7 @@ sum_state(accounting::Inventory nursery, accounting::Inventory heat,
struct CellularLives::State { struct CellularLives::State {
std::uint64_t world{}, region{}, frame{}; std::uint64_t world{}, region{}, frame{};
CellularLivesConfig config{}; CellularLivesConfig config{};
NurseryConfig nursery_config{};
std::unique_ptr<biology::CellularHabitat> habitat; std::unique_ptr<biology::CellularHabitat> habitat;
std::vector<CellularOwnedLife> lives; std::vector<CellularOwnedLife> lives;
std::vector<CellularOwnedCorpse> corpses; std::vector<CellularOwnedCorpse> corpses;
@@ -63,12 +64,13 @@ struct CellularLives::State {
accounting::Inventory current_total{}; accounting::Inventory current_total{};
State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id, State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id,
CellularLivesConfig cfg, std::unique_ptr<biology::CellularHabitat> map, CellularLivesConfig cfg, NurseryConfig nursery, std::unique_ptr<biology::CellularHabitat> map,
std::vector<CellularOwnedLife> living, std::vector<CellularOwnedCorpse> dead, std::vector<CellularOwnedLife> living, std::vector<CellularOwnedCorpse> dead,
const biology::LineageArchive& history, accounting::Inventory source, const biology::LineageArchive& history, accounting::Inventory source,
accounting::Inventory accumulated_heat, accounting::Inventory initial, accounting::Inventory accumulated_heat, accounting::Inventory initial,
accounting::Inventory current) accounting::Inventory current)
: world{world_id}, region{region_id}, frame{frame_id}, config{cfg}, : 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)}, habitat{std::move(map)}, lives{std::move(living)}, corpses{std::move(dead)},
archive{history}, nursery{source}, heat{accumulated_heat}, opening_total{initial}, archive{history}, nursery{source}, heat{accumulated_heat}, opening_total{initial},
current_total{current} {} current_total{current} {}
@@ -83,7 +85,7 @@ CellularLives::create(const PrimitiveLives& opening,
CellularLivesConfig config) { CellularLivesConfig config) {
if (!habitat) if (!habitat)
return std::unexpected{CellularLivesError::invalid_config}; return std::unexpected{CellularLivesError::invalid_config};
const auto& nursery_config = opening.config(); auto nursery_config = opening.config();
const auto& map = habitat->config(); const auto& map = habitat->config();
if (nursery_config.world == 0 || nursery_config.region == 0 || nursery_config.frame == 0 || if (nursery_config.world == 0 || nursery_config.region == 0 || nursery_config.frame == 0 ||
map.world != nursery_config.world || map.region != nursery_config.region || 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())) if (!add_inventory(initial_total, habitat->totals()))
return std::unexpected{CellularLivesError::overflow}; return std::unexpected{CellularLivesError::overflow};
const auto nursery = opening.balances()[0]; const auto nursery = opening.balances()[0];
nursery_config.funding = nursery;
const auto heat = opening.balances()[1]; const auto heat = opening.balances()[1];
const auto current = sum_state(nursery, heat, *habitat, lives, {}); const auto current = sum_state(nursery, heat, *habitat, lives, {});
if (!current) if (!current)
@@ -145,6 +148,7 @@ CellularLives::create(const PrimitiveLives& opening,
auto state = std::make_unique<State>( auto state = std::make_unique<State>(
nursery_config.world, nursery_config.region, nursery_config.frame, config, nursery_config.world, nursery_config.region, nursery_config.frame, config,
std::move(nursery_config),
std::move(habitat), std::move(lives), std::vector<CellularOwnedCorpse>{}, std::move(habitat), std::move(lives), std::vector<CellularOwnedCorpse>{},
opening.archive(), nursery, heat, initial_total, *current); opening.archive(), nursery, heat, initial_total, *current);
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}}; return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
@@ -226,8 +230,18 @@ CellularLives::advance_tick(std::span<const CellularLifeIntent> intents) {
if (found == next_lives.end() || found->identity.life != dead.life_id || if (found == next_lives.end() || found->identity.life != dead.life_id ||
!next_archive.record_death(found->identity.organism, {proposal->end_tick})) !next_archive.record_death(found->identity.organism, {proposal->end_tick}))
return std::unexpected{CellularLivesError::archive}; return std::unexpected{CellularLivesError::archive};
next_corpses.push_back( const auto corpse_budget = budget_for(
{found->identity.organism, proposal->end_tick, dead.position, dead.inventory}); 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); next_lives.erase(found);
} }
std::ranges::sort(next_corpses, {}, &CellularOwnedCorpse::organism); std::ranges::sort(next_corpses, {}, &CellularOwnedCorpse::organism);
@@ -258,6 +272,7 @@ CellularLives::advance_tick(std::span<const CellularLifeIntent> intents) {
state_->world, state_->region, state_->frame, state_->world, state_->region, state_->frame,
CellularLivesConfig{state_->config.area, proposal->end_tick, CellularLivesConfig{state_->config.area, proposal->end_tick,
state_->config.ambient_temperature_millikelvin}, state_->config.ambient_temperature_millikelvin},
state_->nursery_config,
std::move(*next_habitat), std::move(next_lives), std::move(next_corpses), next_archive, std::move(*next_habitat), std::move(next_lives), std::move(next_corpses), next_archive,
state_->nursery, next_heat, state_->opening_total, *total); state_->nursery, next_heat, state_->opening_total, *total);
state_.swap(next); state_.swap(next);
+3
View File
@@ -84,6 +84,9 @@ void owner_advances_and_closes_death_atomically() {
CHECK(owner.lives().empty() && owner.corpses().size() == 2 && steps < 2'000); 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()[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()[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); const auto lineage = owner.archive().organism(101);
CHECK(lineage && !lineage->alive && lineage->died.value == owner.corpses()[0].died_tick); CHECK(lineage && !lineage->alive && lineage->died.value == owner.corpses()[0].died_tick);
const auto second_lineage = owner.archive().organism(102); const auto second_lineage = owner.archive().organism(102);