Add funded cellular birth candidate
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (ecs) (push) Successful in 1m54s
Foundation / checks (postgres) (push) Failing after 51s
Foundation / checks (tsan) (push) Failing after 32s
Foundation / checks (network) (push) Failing after 3m4s
Foundation / checks (client) (push) Failing after 4m35s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-11 00:19:47 -04:00
parent c06ea9023d
commit 81866a6897
6 changed files with 254 additions and 6 deletions
+10
View File
@@ -300,6 +300,16 @@ scoped change before starting the next segment.
retry and refuses nonempty founder/archive state or conflicting reuse. A
PostgreSQL integration check covers exact restore and retry behavior. This
does not provide a player spawn or make 11.3e playable.
- 11.3d-7g: `CellularLives` now builds a detached profile-4 birth candidate
from an allocator-reserved request after the current tick. The owner derives
primitive founder biology, selects the first unoccupied provisioned site,
funds body/reserve/construction from nursery inventory, records the birth in
a copied archive, and preserves energy/matter closure. Refusals leave the
committed owner unchanged. Focused tests cover funding, placement, duplicate
account, identity/tick validation, canonical restore and first action on the
following tick. This remains in-memory: canonical birth trace, durable
publication/recovery and session scheduling remain open, so 11.3e is not
playable yet.
## Exit boundary
+24
View File
@@ -6374,3 +6374,27 @@ environment because `sys/random.h` is unavailable. The local CMake debug build
of `evo-cellular-lives-tests` remains running without output; it is not counted
as a pass. No PostgreSQL integration execution, CTest, clang-format or CI result
is claimed. The Linux/PostgreSQL qualification remains pending CI.
## 2026-10-11 — M11.3d-7g detached cellular birth candidate
Added `CellularLives::birth_candidate`, which derives primitive-founder
biology from a reserved identity, chooses the first unoccupied provisioned site,
debits body/reserve/construction funding from the nursery, records the founder
in a copied archive, and returns a validated detached candidate. The committed
owner is unchanged on both success and refusal. The focused lifecycle test
covers a funded birth, conservation, restore, duplicate account, invalid
identity/tick, insufficient funding, occupied-site refusal, and first action
on the following tick. `cellular_batch.cpp` also avoids a GCC 13
`maybe-uninitialized` false positive for an optional intake target under
optimized `NDEBUG` builds.
The focused test executable was manually compiled and run with GCC 13.2 in
debug (`-O0 -g`) and release (`-O2 -DNDEBUG`) modes; both print PASS. The
pre-existing missing-field initializer warning in
`cellular_region_step.cpp:29` is demoted for these builds; other warnings remain
errors. `git diff --check` passes. CMake/CTest, sanitizers, clang-format,
PostgreSQL integration and CI have not run for this segment; the local CMake
jobs remain stalled without output and do not count as validation. The current
Windows environment also lacks `clang-format`. Durable birth trace and server
integration remain unimplemented, so this does not make the cellular stage
playable.
@@ -50,6 +50,9 @@ enum class CellularLivesError : std::uint8_t {
identity,
invalid_config,
invalid_life,
life_exists,
no_placement,
insufficient_funding,
duplicate_life,
invalid_tick,
invalid_intents,
@@ -98,6 +101,13 @@ class CellularLives {
CellularLivesError>
perceive(std::uint64_t life_id) const;
// Returns a detached post-birth candidate for an allocator-reserved request.
// The caller supplies the durable identity; the owner derives founder biology,
// funding, source and the first unoccupied provisioned site. Birth must occur
// at the current checkpoint tick, after that tick's existing-life step.
[[nodiscard]] std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
birth_candidate(LifeRequest request, LifeAllocation allocation) 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);
+6 -6
View File
@@ -3,6 +3,7 @@
#include <algorithm>
#include <array>
#include <bit>
#include <optional>
#include <ranges>
#include <tuple>
#include <utility>
@@ -280,12 +281,11 @@ match_cellular_actions_to_trace(const CellularLives& predecessor, const Cellular
if (intent == intents.end() || intent->life_id != life->identity.life)
return std::unexpected{CellularActionBlockError::mismatch};
const auto input = std::span<const std::uint8_t>{action.input};
const auto target = input[12] == 0
? std::optional<biology::CellularPatchAddress>{}
: std::optional<biology::CellularPatchAddress>{
biology::CellularPatchAddress{
static_cast<std::uint32_t>(get(input, 16, 4)),
static_cast<std::uint32_t>(get(input, 20, 4))}};
std::optional<biology::CellularPatchAddress> target;
if (input[12] != 0)
target = biology::CellularPatchAddress{
static_cast<std::uint32_t>(get(input, 16, 4)),
static_cast<std::uint32_t>(get(input, 20, 4))};
if (intent->intent.movement.x != std::bit_cast<std::int16_t>(
static_cast<std::uint16_t>(get(input, 8, 2))) ||
intent->intent.movement.y != std::bit_cast<std::int16_t>(
+127
View File
@@ -1,4 +1,5 @@
#include "evo/server/lifecycle/cellular_lives.hpp"
#include "evo/biology/founder.hpp"
#include <algorithm>
#include <bit>
@@ -100,6 +101,19 @@ bool add_inventory(accounting::Inventory& total, const accounting::Inventory& va
return true;
}
bool subtract_inventory(accounting::Inventory& total,
const accounting::Inventory& value) noexcept {
if (value.energy.value > total.energy.value)
return false;
for (std::size_t channel = 0; channel < total.matter.size(); ++channel)
if (value.matter[channel].value > total.matter[channel].value)
return false;
total.energy.value -= value.energy.value;
for (std::size_t channel = 0; channel < total.matter.size(); ++channel)
total.matter[channel].value -= value.matter[channel].value;
return true;
}
std::expected<biology::MetabolicBudget, CellularLivesError>
budget_for(const biology::LineageArchive& archive, const CellularOwnedLife& life,
std::uint32_t temperature) {
@@ -474,6 +488,119 @@ CellularLives::perceive(std::uint64_t life_id) const {
return std::move(*view);
}
std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) const {
if (request.action == 0 ||
std::ranges::all_of(request.account, [](std::uint8_t value) { return value == 0; }))
return std::unexpected{CellularLivesError::invalid_life};
if (allocation.life == 0 || allocation.life != allocation.organism ||
allocation.life != allocation.genome || allocation.life != allocation.event)
return std::unexpected{CellularLivesError::identity};
if (allocation.born.value == 0 || allocation.born.value != state_->config.tick)
return std::unexpected{CellularLivesError::invalid_tick};
if (state_->lives.size() >= biology::max_cellular_tick_lives)
return std::unexpected{CellularLivesError::no_placement};
if (std::ranges::any_of(state_->lives, [&](const CellularOwnedLife& life) {
return life.account == request.account;
}))
return std::unexpected{CellularLivesError::life_exists};
if (std::ranges::any_of(state_->lives, [&](const CellularOwnedLife& life) {
return life.identity.life == allocation.life ||
life.identity.organism == allocation.organism ||
life.identity.genome == allocation.genome ||
life.identity.event == allocation.event;
}) ||
std::ranges::any_of(state_->corpses, [&](const CellularOwnedCorpse& corpse) {
return corpse.life_id == allocation.life || corpse.organism == allocation.organism;
}) || state_->archive.find(allocation.genome) || state_->archive.organism(allocation.organism))
return std::unexpected{CellularLivesError::duplicate_life};
const auto endowed = biology::primitive_endowment();
const auto genome = biology::primitive_founder(allocation.genome, allocation.event);
if (!endowed || !genome)
return std::unexpected{CellularLivesError::biology};
const auto budget = biology::metabolic_budget(
*genome, endowed->growth,
{state_->config.ambient_temperature_millikelvin, {}});
if (!budget || budget->body != endowed->body)
return std::unexpected{CellularLivesError::biology};
std::optional<biology::CellularPosition> position;
for (const auto site : state_->nursery_config.sites) {
if (site.x_um < 0 || site.y_um < 0)
return std::unexpected{CellularLivesError::invalid_config};
const biology::CellularPosition candidate{static_cast<std::uint64_t>(site.x_um),
static_cast<std::uint64_t>(site.y_um)};
bool occupied = false;
for (const auto& living : state_->lives) {
const auto living_budget = budget_for(
state_->archive, living, state_->config.ambient_temperature_millikelvin);
if (!living_budget)
return std::unexpected{living_budget.error()};
const auto separated = [](std::uint64_t left, std::uint64_t right,
std::uint32_t left_extent,
std::uint32_t right_extent) noexcept {
return left < right ? right - left >= left_extent : left - right >= right_extent;
};
if (!separated(candidate.x_um, living.position.x_um, budget->phenotype.extent,
living_budget->phenotype.extent) &&
!separated(candidate.y_um, living.position.y_um, budget->phenotype.extent,
living_budget->phenotype.extent)) {
occupied = true;
break;
}
}
if (!occupied) {
position = candidate;
break;
}
}
if (!position)
return std::unexpected{CellularLivesError::no_placement};
auto nursery = state_->nursery;
if (!subtract_inventory(nursery, endowed->body) ||
!subtract_inventory(nursery, endowed->reserve) ||
endowed->construction.value > nursery.energy.value)
return std::unexpected{CellularLivesError::insufficient_funding};
nursery.energy.value -= endowed->construction.value;
auto heat = state_->heat;
if (endowed->construction.value >
std::numeric_limits<std::uint64_t>::max() - heat.energy.value)
return std::unexpected{CellularLivesError::overflow};
heat.energy.value += endowed->construction.value;
auto archive = state_->archive;
if (!archive.admit(*genome) ||
!archive.record_birth(allocation.organism, allocation.genome, allocation.born))
return std::unexpected{CellularLivesError::archive};
auto lives = state_->lives;
lives.push_back({request.account, allocation, state_->nursery_config.source, endowed->growth,
*position, endowed->body, endowed->reserve});
std::ranges::sort(lives, {}, [](const CellularOwnedLife& life) {
return life.identity.life;
});
auto nursery_config = state_->nursery_config;
nursery_config.funding = nursery;
auto habitat = biology::CellularHabitat::restore(state_->habitat->snapshot(), state_->world,
state_->region, state_->frame);
if (!habitat)
return std::unexpected{CellularLivesError::habitat};
const auto current = validate_state(state_->world, state_->region, state_->frame,
state_->config, nursery_config, **habitat, lives,
state_->corpses, archive, nursery, heat,
state_->opening_total);
if (!current)
return std::unexpected{current.error()};
auto candidate = std::unique_ptr<CellularLives>{new CellularLives{std::make_unique<State>(
state_->world, state_->region, state_->frame, state_->config,
std::move(nursery_config), std::move(*habitat), std::move(lives), state_->corpses,
archive, nursery, heat, state_->opening_total, *current)}};
return candidate;
}
std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
std::uint64_t region, std::uint64_t frame, std::uint64_t tick) {
+77
View File
@@ -45,6 +45,82 @@ void refresh_checksum(std::vector<std::uint8_t>& bytes) {
bytes[bytes.size() - 8 + i] = static_cast<std::uint8_t>(value >> (i * 8U));
}
std::unique_ptr<CellularLives> empty_cellular_owner(Inventory funding,
std::vector<SpawnSite> sites) {
auto primitive = PrimitiveLives::create({91, 1, 1, 17, funding, std::move(sites)});
CHECK(primitive);
auto habitat = evo::biology::CellularHabitat::create({91, 1, 1, 1'000, 1'000, {}});
CHECK(habitat);
auto owner = CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150});
CHECK(owner);
return std::move(*owner);
}
void reserved_birth_is_funded_and_detached() {
auto opening = empty_cellular_owner(founder_price(1), {{0, 0}, {20, 0}});
const std::span<const CellularLifeIntent> no_lives{};
CHECK(opening->advance_tick(no_lives));
const auto predecessor = opening->snapshot();
LifeRequest request{};
request.account.back() = 9;
request.action = 17;
const LifeAllocation allocation{501, 501, 501, 501, {1}};
auto born = opening->birth_candidate(request, allocation);
CHECK(born && opening->tick() == 1 && opening->lives().empty());
CHECK((*born)->tick() == opening->tick() && (*born)->lives().size() == 1 &&
(*born)->lives()[0].account == request.account &&
(*born)->lives()[0].identity == allocation && (*born)->lives()[0].source == 17 &&
(*born)->lives()[0].position == (evo::biology::CellularPosition{0, 0}));
const auto endowment = evo::biology::primitive_endowment();
CHECK(endowment);
CHECK((*born)->nursery().energy.value == opening->nursery().energy.value -
endowment->reserve.energy.value -
endowment->construction.value);
CHECK((*born)->heat().energy.value == endowment->construction.value &&
(*born)->current_total() == (*born)->opening_total() &&
(*born)->archive().recorded() == 1);
CHECK(opening->snapshot() == predecessor);
const auto recovered = CellularLives::restore((*born)->snapshot(), 91, 1, 1, 1);
CHECK(recovered && (*recovered)->snapshot() == (*born)->snapshot());
auto retry_account = request;
retry_account.action++;
CHECK((*born)->birth_candidate(retry_account, {502, 502, 502, 502, {1}}).error() ==
CellularLivesError::life_exists);
CHECK(opening->birth_candidate(request, {502, 503, 502, 502, {1}}).error() ==
CellularLivesError::identity);
CHECK(opening->birth_candidate(request, {502, 502, 502, 502, {2}}).error() ==
CellularLivesError::invalid_tick);
const std::array next_tick{CellularLifeIntent{allocation.life, {}}};
CHECK((*born)->advance_tick(next_tick) && (*born)->tick() == 2 &&
(*born)->lives().size() == 1);
auto unfunded = empty_cellular_owner({}, {{0, 0}});
CHECK(unfunded->advance_tick(no_lives));
const auto unfunded_snapshot = unfunded->snapshot();
CHECK(unfunded->birth_candidate(request, {601, 601, 601, 601, {1}}).error() ==
CellularLivesError::insufficient_funding);
CHECK(unfunded->snapshot() == unfunded_snapshot && unfunded->lives().empty());
auto occupied_primitive =
PrimitiveLives::create({92, 1, 1, 17, founder_price(2), {{0, 0}}});
CHECK(occupied_primitive);
LifeRequest existing{};
existing.account.back() = 11;
existing.action = 1;
CHECK((*occupied_primitive)->spawn(existing, {701, 701, 701, 701, {1}}));
auto occupied_habitat =
evo::biology::CellularHabitat::create({92, 1, 1, 1'000, 1'000, {}});
CHECK(occupied_habitat);
auto occupied = CellularLives::create(**occupied_primitive, std::move(*occupied_habitat),
{{1'000, 1'000}, 1, 293'150});
CHECK(occupied);
LifeRequest arriving{};
arriving.account.back() = 12;
arriving.action = 2;
CHECK((*occupied)->birth_candidate(arriving, {702, 702, 702, 702, {1}}).error() ==
CellularLivesError::no_placement);
}
void owner_advances_and_closes_death_atomically() {
auto primitive = PrimitiveLives::create({90, 1, 7, 17, founder_price(2), {{0, 0}, {20, 0}}});
CHECK(primitive);
@@ -197,6 +273,7 @@ void owner_advances_and_closes_death_atomically() {
int main() {
try {
reserved_birth_is_funded_and_detached();
owner_advances_and_closes_death_atomically();
std::puts("PASS cellular lives: feeding, tick ownership and terminal closure");
} catch (const std::exception& error) {