From 37368ab6d1533e8187a41aa5db49b3638acb6bfd Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 11 Oct 2026 00:06:19 -0400 Subject: [PATCH] Provision empty cellular profile genesis --- README.md | 6 +- apps/evo-world-clone/main.cpp | 137 ++++++++++++++++-- docs/engineering/M11_3_DELIVERY_PLAN.md | 8 + docs/engineering/VALIDATION.md | 17 +++ include/evo/persistence/checkpoint_store.hpp | 6 + schemas/cellular-lives-v1.md | 7 +- src/persistence/cellular_checkpoint_store.cpp | 61 ++++++++ tests/cellular_publication_tests.cpp | 37 ++++- 8 files changed, 262 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b2e3bcd..97dd060 100644 --- a/README.md +++ b/README.md @@ -130,8 +130,10 @@ process fixtures remain separate from organism biology. and reporting. `tests` holds contract, fuzz and measurement programs. `src/server/lifecycle` owns funded primitive founder creation and an in-memory cellular tick owner over the finite habitat. -The cellular owner is not yet wired to durable profile-4 recovery or session -intentions, so it is not a playable client path. `evo::simulation` remains +The cellular owner now has durable profile-4 recovery/publication and an +adapter for reliable v7 session actions. `evo-server` still lacks the cellular +scheduler, player-life entry operation, and cellular view replication, so this +is not yet a playable client path. `evo::simulation` remains graphics-, network- and database-independent. World0 is persistent state. No normal configure, build, test or CI job may create, diff --git a/apps/evo-world-clone/main.cpp b/apps/evo-world-clone/main.cpp index 0d0bfef..e6cce4c 100644 --- a/apps/evo-world-clone/main.cpp +++ b/apps/evo-world-clone/main.cpp @@ -9,10 +9,12 @@ // [--max-commits N] // evo-world-clone check-store --world W --region R --pg-* ... --objects DIR // [--reserve-mib N] -// evo-world-clone provision --world W --region R --opening development-v1|primitive-v1 -// --pg-* ... --objects DIR --build HEX [--retain-build] +// evo-world-clone provision --world W --region R --opening development-v1|primitive-v1|cellular-v1 +// --pg-* ... --objects DIR --build HEX [--commit HEX32] [--retain-build] // primitive-v1 also requires --frame N --source-id N, every --funding-*-* channel, // and one or more ordered --site X,Y values. +// cellular-v1 also requires --width-um N --height-um N --ambient-temperature-mk N +// and one or more ordered --patch X,Y,SOURCE,ENERGY,C,N,P,O values plus a stable --commit HEX32. // evo-world-clone compare --world A --region R --other-world B --pg-* ... // --objects DIR [--other-objects DIR] --retained HEX... [--max-commits N] // @@ -57,6 +59,8 @@ #include "evo/persistence/region_clone.hpp" #include "evo/persistence/sha256.hpp" #include "evo/processes/development_opening.hpp" +#include "evo/biology/cellular_habitat.hpp" +#include "evo/server/lifecycle/cellular_lives.hpp" #include "evo/server/lifecycle/primitive_lives.hpp" #include @@ -65,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -93,6 +98,9 @@ struct Options { std::optional primitive_frame, primitive_source; std::array, 5> primitive_funding; std::vector primitive_sites; + std::optional cellular_width_um, cellular_height_um, + cellular_temperature_mk; + std::vector cellular_patches; std::optional build; bool retain_build{}; bool crash{}; @@ -118,6 +126,34 @@ std::optional site(std::string_view text) { return std::nullopt; return server::SpawnSite{x, y}; } +std::optional cellular_patch(std::string_view text) { + std::array fields{}; + for (std::size_t i = 0; i < fields.size(); ++i) { + const auto comma = text.find(','); + const auto field = i + 1 == fields.size() ? text : text.substr(0, comma); + if (field.empty() || (i + 1 != fields.size() && comma == std::string_view::npos)) + return std::nullopt; + const auto [end, error] = + std::from_chars(field.data(), field.data() + field.size(), fields[i]); + if (error != std::errc{} || end != field.data() + field.size()) + return std::nullopt; + if (i + 1 != fields.size()) + text.remove_prefix(comma + 1); + else if (comma != std::string_view::npos) + return std::nullopt; + } + if (fields[0] > std::numeric_limits::max() || + fields[1] > std::numeric_limits::max()) + return std::nullopt; + biology::CellularPatch result{}; + result.address = {static_cast(fields[0]), + static_cast(fields[1])}; + result.source = fields[2]; + result.stock.energy.value = fields[3]; + for (std::size_t i = 0; i < result.stock.matter.size(); ++i) + result.stock.matter[i].value = fields[4 + i]; + return result; +} template std::optional> hex(std::string_view text) { if (text.size() != N * 2) return std::nullopt; @@ -215,7 +251,7 @@ std::optional parse(int argc, char** argv) { else if ((clone && flag == "--target-objects") || (o.command == "compare" && flag == "--other-objects")) o.target.objects = value; - else if (clone && flag == "--commit" && hex<16>(value)) + else if ((clone || o.command == "provision") && flag == "--commit" && hex<16>(value)) o.commit = hex<16>(value); else if (clone && flag == "--audit-max" && n && *n > 0) o.audit_max = *n; @@ -227,7 +263,8 @@ std::optional parse(int argc, char** argv) { else if (o.command == "check-store" && flag == "--reserve-mib" && n && *n <= 1048576) o.reserve_mib = *n; else if (o.command == "provision" && flag == "--opening" && - (value == "development-v1" || value == "primitive-v1")) + (value == "development-v1" || value == "primitive-v1" || + value == "cellular-v1")) o.opening = value; else if (o.command == "provision" && flag == "--frame" && n) o.primitive_frame = *n; @@ -248,6 +285,20 @@ std::optional parse(int argc, char** argv) { if (!parsed || o.primitive_sites.size() == server::max_primitive_lives) return std::nullopt; o.primitive_sites.push_back(*parsed); + } else if (o.command == "provision" && flag == "--width-um" && n && + *n <= std::numeric_limits::max()) + o.cellular_width_um = static_cast(*n); + else if (o.command == "provision" && flag == "--height-um" && n && + *n <= std::numeric_limits::max()) + o.cellular_height_um = static_cast(*n); + else if (o.command == "provision" && flag == "--ambient-temperature-mk" && n && + *n <= std::numeric_limits::max()) + o.cellular_temperature_mk = static_cast(*n); + else if (o.command == "provision" && flag == "--patch") { + const auto parsed = cellular_patch(value); + if (!parsed || o.cellular_patches.size() == biology::max_cellular_patches) + return std::nullopt; + o.cellular_patches.push_back(*parsed); } else if (o.command == "provision" && flag == "--build" && hex<32>(value)) o.build = hex<32>(value); else if (o.command == "provision" && flag == "--retain-build" && value == "true") @@ -273,13 +324,30 @@ std::optional parse(int argc, char** argv) { o.primitive_frame || o.primitive_source || std::ranges::any_of(o.primitive_funding, [](const auto& v) { return v.has_value(); }) || !o.primitive_sites.empty(); + const bool cellular_options = o.cellular_width_um || o.cellular_height_um || + o.cellular_temperature_mk || !o.cellular_patches.empty(); if (o.opening == "primitive-v1") { if (!o.primitive_frame || *o.primitive_frame == 0 || !o.primitive_source || *o.primitive_source == 0 || o.primitive_sites.empty() || !std::ranges::all_of(o.primitive_funding, [](const auto& v) { return v.has_value(); })) return std::nullopt; - } else if (primitive_options) { + if (cellular_options) + return std::nullopt; + } else if (o.opening == "cellular-v1") { + const bool has_stock = std::ranges::any_of(o.cellular_patches, [](const auto& patch) { + return patch.stock.energy.value != 0 || + std::ranges::any_of(patch.stock.matter, + [](const auto& amount) { return amount.value != 0; }); + }); + if (!o.primitive_frame || *o.primitive_frame == 0 || !o.primitive_source || + *o.primitive_source == 0 || o.primitive_sites.empty() || + !std::ranges::all_of(o.primitive_funding, + [](const auto& v) { return v.has_value(); }) || + !o.cellular_width_um || !o.cellular_height_um || !o.cellular_temperature_mk || + o.cellular_patches.empty() || !has_stock || !o.commit) + return std::nullopt; + } else if (primitive_options || cellular_options) { return std::nullopt; } } @@ -375,8 +443,10 @@ std::vector probe_bytes() { int provision(const Options& o) { const bool primitive = o.opening == "primitive-v1"; - const auto payload_limit = - primitive ? server::max_primitive_lives_bytes : persistence::max_lineage_payload_bytes; + const bool cellular = o.opening == "cellular-v1"; + const auto payload_limit = cellular ? server::max_cellular_lives_bytes + : primitive ? server::max_primitive_lives_bytes + : persistence::max_lineage_payload_bytes; auto store = open_objects(o.source, payload_limit); if (!store) { std::puts("objects refused"); @@ -400,7 +470,8 @@ int provision(const Options& o) { } } std::unique_ptr primitive_opening; - if (primitive) { + std::unique_ptr cellular_opening; + if (primitive || cellular) { server::NurseryConfig config{}; config.world = o.source.key.world; config.region = o.source.key.region; @@ -417,6 +488,28 @@ int provision(const Options& o) { } primitive_opening = std::move(*opening); } + if (cellular) { + biology::CellularHabitatConfig habitat_config{}; + habitat_config.world = o.source.key.world; + habitat_config.region = o.source.key.region; + habitat_config.frame = *o.primitive_frame; + habitat_config.width_um = *o.cellular_width_um; + habitat_config.height_um = *o.cellular_height_um; + habitat_config.patches = o.cellular_patches; + auto habitat = biology::CellularHabitat::create(std::move(habitat_config)); + if (!habitat) { + std::printf("cellular habitat refused %u\n", static_cast(habitat.error())); + return 4; + } + auto opening = server::CellularLives::create( + **primitive_opening, std::move(*habitat), + {{*o.cellular_width_um, *o.cellular_height_um}, 0, *o.cellular_temperature_mk}); + if (!opening) { + std::printf("cellular opening refused %u\n", static_cast(opening.error())); + return 4; + } + cellular_opening = std::move(*opening); + } const auto report = [&](const char* what, const persistence::RegionHead& head) { std::printf("%s world=%llu region=%llu sequence=%llu tick=%llu\n", what, static_cast(o.source.key.world), @@ -425,9 +518,25 @@ int provision(const Options& o) { static_cast(head.end_tick)); return 0; }; + persistence::Uuid commit{}; + if (o.commit) { + commit = *o.commit; + } else if (::getrandom(commit.data(), commit.size(), 0) != + static_cast(commit.size())) { + return 4; + } // Never re-provision or report success for a different profile/frame. auto existing = persistence::load_region_checkpoint(*db, o.source.key, timeout); if (existing) { + if (cellular) { + auto same_genesis = persistence::provision_cellular_region( + *db, *store, o.source.key, *o.primitive_frame, *cellular_opening, commit, build, + timeout); + if (same_genesis) + return report("already-provisioned", same_genesis->head); + std::puts("provision refused existing cellular region; use its original --commit to resolve genesis"); + return 4; + } const auto manifest = persistence::decode_manifest(existing->manifest); const auto expected_profile = primitive ? persistence::CheckpointProfile::primitive_lives_v1 @@ -454,9 +563,15 @@ int provision(const Options& o) { std::puts("database refused"); return 3; } - persistence::Uuid commit{}; - if (::getrandom(commit.data(), commit.size(), 0) != static_cast(commit.size())) - return 4; + if (cellular) { + auto made = persistence::provision_cellular_region( + *db, *store, o.source.key, *o.primitive_frame, *cellular_opening, commit, build, timeout); + if (!made) { + std::printf("cellular provision refused %u\n", static_cast(made.error().kind)); + return 4; + } + return report("provisioned", made->head); + } if (primitive) { auto made = persistence::provision_primitive_region(*db, *store, o.source.key, *o.primitive_frame, diff --git a/docs/engineering/M11_3_DELIVERY_PLAN.md b/docs/engineering/M11_3_DELIVERY_PLAN.md index dd2c3a6..1937369 100644 --- a/docs/engineering/M11_3_DELIVERY_PLAN.md +++ b/docs/engineering/M11_3_DELIVERY_PLAN.md @@ -292,6 +292,14 @@ scoped change before starting the next segment. same-biological-tick checkpoint publication. This remains a proposal; no profile-4 entry path or 11.3e playtest is available until the contract is accepted, implemented and qualified. +- 11.3d-7f: the owner persistence API and `evo-world-clone provision + --opening cellular-v1` now create only an empty profile-4 genesis. The CLI + requires explicit arena dimensions, temperature, nursery funding, ordered + spawn sites, finite patch stocks and a stable commit ID; the owner helper + verifies the payload, provisions sequence 0/tick 0, resolves an exact genesis + 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. ## Exit boundary diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 58ccdf4..b639d13 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -6357,3 +6357,20 @@ GCC 13.2 strict-warning syntax checks pass for the lifecycle, session adapter and focused tests in debug and `NDEBUG`; `git diff --check` passes. Runtime test execution and full CI are pending; local CMake remains blocked by its cached MSVC C++23 feature detection. + +## 2026-10-10 — M11.3d-7f empty cellular genesis (CI pending) + +Added an owner-only profile-4 genesis API and `evo-world-clone` configuration +for an explicitly supplied empty cellular opening. No life, identity or +founder is invented by provisioning. PostgreSQL integration coverage verifies +sequence-0/tick-0 publication, restored habitat/nursery closure, exact retry +and refusal of conflicting genesis. + +GCC 13.2 strict-warning syntax checks pass for +`src/persistence/cellular_checkpoint_store.cpp` and +`tests/cellular_publication_tests.cpp`; `git diff --check` passes. The +Linux-only `evo-world-clone` translation unit cannot compile in this Windows +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. diff --git a/include/evo/persistence/checkpoint_store.hpp b/include/evo/persistence/checkpoint_store.hpp index 1219698..6f7af0a 100644 --- a/include/evo/persistence/checkpoint_store.hpp +++ b/include/evo/persistence/checkpoint_store.hpp @@ -197,6 +197,12 @@ recover_primitive_checkpoint(Postgres& db, const FilesystemObjectStore& objects, // Profile 4 publication replays the bounded cellular trace from the verified // predecessor and requires exact candidate bytes and action-to-life agreement. +// Owner-only genesis provisioning accepts an empty profile-4 state. Player births +// are durable runtime operations and cannot be smuggled into genesis. +[[nodiscard]] std::expected +provision_cellular_region(Postgres& owner, const FilesystemObjectStore& objects, RegionKey key, + std::uint64_t frame, const server::CellularLives& opening, Uuid commit, + const Sha256Digest& build, std::chrono::milliseconds timeout); [[nodiscard]] std::expected publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease, const CommittedCheckpoint& predecessor, diff --git a/schemas/cellular-lives-v1.md b/schemas/cellular-lives-v1.md index ac1e049..a59e0d9 100644 --- a/schemas/cellular-lives-v1.md +++ b/schemas/cellular-lives-v1.md @@ -68,6 +68,7 @@ recomputes phenotype and body from archived genomes, verifies positions and footprints, verifies exact living-set/archive closure and unique life/account identities, and reconciles every current channel (nursery, heat, habitat, lives, corpses) to the explicit opening total. It accepts only byte-identical -canonical re-encoding. The codec is an in-memory profile contract: manifest -allowlisting, PostgreSQL publication and process recovery are separate M11.3d -gates and remain required before this profile is durably playable. +canonical re-encoding. Empty profile-4 genesis has zero living and corpse +records, an empty lineage archive, and an explicit finite habitat/nursery +opening. Owner provisioning does not add player lives; they require a separate +durable birth operation. diff --git a/src/persistence/cellular_checkpoint_store.cpp b/src/persistence/cellular_checkpoint_store.cpp index ae746ef..2e3c37f 100644 --- a/src/persistence/cellular_checkpoint_store.cpp +++ b/src/persistence/cellular_checkpoint_store.cpp @@ -2,6 +2,9 @@ #include "evo/persistence/sha256.hpp" #include +#include +#include +#include #include namespace evo::persistence { @@ -67,6 +70,64 @@ bool prepared_is_canonical(const CellularPreparedCommit& prepared, } } // namespace +std::expected +provision_cellular_region(Postgres& owner, const FilesystemObjectStore& objects, RegionKey key, + std::uint64_t frame, const server::CellularLives& opening, Uuid commit, + const Sha256Digest& build, milliseconds timeout) { + const auto payload = opening.snapshot(); + if (opening.world() != key.world || opening.region() != key.region || opening.frame() != frame || + opening.tick() != 0 || !opening.lives().empty() || !opening.corpses().empty() || + opening.archive().recorded() != 0 || opening.archive().archived() != 0) + return std::unexpected{failure(PublicationError::candidate)}; + const auto digest = sha256(payload); + if (!digest) + return std::unexpected{failure(PublicationError::digest)}; + auto manifest = genesis_manifest(key, frame, commit, biology::cellular_motion_tick_microseconds, + build, payload.size(), *digest, + CheckpointProfile::cellular_lives_v1); + auto encoded = manifest ? encode_manifest(*manifest) + : std::expected, CheckpointError>{ + std::unexpected{CheckpointError::format}}; + if (!encoded || !restore_cellular_payload(payload, *manifest)) + return std::unexpected{failure(PublicationError::candidate)}; + if (auto stored = put_verified(objects, payload, {*digest, payload.size()}); !stored) + return std::unexpected{stored.error()}; + + std::string manifest_hex = "\\x"; + constexpr std::string_view digits = "0123456789abcdef"; + manifest_hex.reserve(2 + encoded->size() * 2); + for (const auto byte : *encoded) { + manifest_hex.push_back(digits[byte >> 4U]); + manifest_hex.push_back(digits[byte & 0x0fU]); + } + const std::array parameters{std::move(manifest_hex)}; + auto inserted = + owner.query("SELECT evolution.provision_region_checkpoint($1::bytea)", parameters, timeout); + if (!inserted) { + auto existing = load_region_checkpoint(owner, key, timeout); + if (existing && existing->manifest == *encoded) + return confirm(existing->head, CellularPreparedCommit{key, commit, *encoded, {}, {}}, + *manifest); + if (existing) + return std::unexpected{failure(PublicationError::rejected)}; + if (existing.error().kind != LeaseStoreError::not_provisioned && + inserted.error().kind == PgError::unknown) + return std::unexpected{failure(PublicationError::unknown, {}, existing.error())}; + const bool unknown = inserted.error().kind == PgError::unknown; + return std::unexpected{failure( + unknown ? PublicationError::unknown : PublicationError::rejected, {}, + {unknown ? LeaseStoreError::unknown : LeaseStoreError::store, inserted.error()})}; + } + auto committed = load_region_checkpoint(owner, key, timeout); + if (!committed) + return std::unexpected{failure(PublicationError::unknown, {}, committed.error())}; + CellularPreparedCommit prepared{key, commit, *encoded, {}, {}}; + auto confirmed = confirm(committed->head, prepared, *manifest); + if (!confirmed) + return std::unexpected{confirmed.error()}; + return *confirmed; +} + std::expected retry_cellular_prepared(Postgres& db, const CellularPreparedCommit& prepared, milliseconds timeout) { diff --git a/tests/cellular_publication_tests.cpp b/tests/cellular_publication_tests.cpp index d6abe53..000cd6f 100644 --- a/tests/cellular_publication_tests.cpp +++ b/tests/cellular_publication_tests.cpp @@ -47,12 +47,47 @@ std::string hex(std::span bytes) { void run_cellular_publication_tests() { auto owner = connect_as(env("PGUSER")); - constexpr RegionKey key{9756, 1}; const auto build = filled<32>(0xD9); CHECK(owner->query("INSERT INTO evolution.retained_builds(build_identity) VALUES " "(decode(repeat('d9',32),'hex')) ON CONFLICT DO NOTHING", {}, 5s)); + constexpr RegionKey empty_key{9757, 1}; + auto empty_nursery = PrimitiveLives::create({empty_key.world, empty_key.region, 1, 17, {}, + {{0, 0}}}); + CHECK(empty_nursery); + auto empty_habitat = evo::biology::CellularHabitat::create( + {empty_key.world, empty_key.region, 1, 1'000, 1'000, + {{{0, 0}, 19, {{12'000}, {{{10}, {20}, {30}, {40}}}}}}}); + CHECK(empty_habitat); + auto empty_opening = CellularLives::create(**empty_nursery, std::move(*empty_habitat), + {{1'000, 1'000}, 0, 293'150}); + CHECK(empty_opening && (*empty_opening)->lives().empty()); + auto empty_objects = FilesystemObjectStore::open(env("PGHOST"), empty_key, + max_cellular_lives_bytes); + CHECK(empty_objects); + const auto empty_commit = filled<16>(0x20); + auto provisioned = provision_cellular_region(*owner, **empty_objects, empty_key, 1, + **empty_opening, empty_commit, build, 5s); + CHECK(provisioned && provisioned->head.sequence == 0 && provisioned->head.end_tick == 0); + auto empty_manifest = decode_manifest(provisioned->manifest); + CHECK(empty_manifest && empty_manifest->profile == CheckpointProfile::cellular_lives_v1 && + empty_manifest->payload_bytes == (*empty_opening)->snapshot().size()); + auto genesis_payload = (*empty_objects)->get( + {empty_manifest->payload_sha256, empty_manifest->payload_bytes}); + CHECK(genesis_payload); + auto restored_genesis = restore_cellular_payload(*genesis_payload, *empty_manifest); + CHECK(restored_genesis && (*restored_genesis)->lives().empty() && + (*restored_genesis)->nursery() == (*empty_opening)->nursery() && + (*restored_genesis)->habitat().snapshot() == (*empty_opening)->habitat().snapshot()); + auto exact_retry = provision_cellular_region(*owner, **empty_objects, empty_key, 1, + **empty_opening, empty_commit, build, 5s); + CHECK(exact_retry && exact_retry->manifest == provisioned->manifest); + CHECK(!provision_cellular_region(*owner, **empty_objects, empty_key, 1, **empty_opening, + filled<16>(0x22), build, 5s)); + + constexpr RegionKey key{9756, 1}; + auto endowed = evo::biology::primitive_endowment(); CHECK(endowed); auto funding = endowed->body;