Provision empty cellular profile genesis
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 40s
Foundation / checks (ecs) (push) Successful in 1m55s
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 (postgres) (push) Canceled after 21s
Foundation / checks (client) (push) Canceled after 2m24s
Foundation / checks (network) (push) Canceled after 1m49s

This commit is contained in:
dingo
2026-10-11 00:06:19 -04:00
parent 140687da97
commit 37368ab6d1
8 changed files with 262 additions and 17 deletions
+126 -11
View File
@@ -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 <algorithm>
@@ -65,6 +69,7 @@
#include <csignal>
#include <cstdio>
#include <filesystem>
#include <limits>
#include <optional>
#include <string>
#include <string_view>
@@ -93,6 +98,9 @@ struct Options {
std::optional<std::uint64_t> primitive_frame, primitive_source;
std::array<std::optional<std::uint64_t>, 5> primitive_funding;
std::vector<server::SpawnSite> primitive_sites;
std::optional<std::uint32_t> cellular_width_um, cellular_height_um,
cellular_temperature_mk;
std::vector<biology::CellularPatch> cellular_patches;
std::optional<persistence::Sha256Digest> build;
bool retain_build{};
bool crash{};
@@ -118,6 +126,34 @@ std::optional<server::SpawnSite> site(std::string_view text) {
return std::nullopt;
return server::SpawnSite{x, y};
}
std::optional<biology::CellularPatch> cellular_patch(std::string_view text) {
std::array<std::uint64_t, 8> 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<std::uint32_t>::max() ||
fields[1] > std::numeric_limits<std::uint32_t>::max())
return std::nullopt;
biology::CellularPatch result{};
result.address = {static_cast<std::uint32_t>(fields[0]),
static_cast<std::uint32_t>(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::size_t N> std::optional<std::array<std::uint8_t, N>> hex(std::string_view text) {
if (text.size() != N * 2)
return std::nullopt;
@@ -215,7 +251,7 @@ std::optional<Options> 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<Options> 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<Options> 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<std::uint32_t>::max())
o.cellular_width_um = static_cast<std::uint32_t>(*n);
else if (o.command == "provision" && flag == "--height-um" && n &&
*n <= std::numeric_limits<std::uint32_t>::max())
o.cellular_height_um = static_cast<std::uint32_t>(*n);
else if (o.command == "provision" && flag == "--ambient-temperature-mk" && n &&
*n <= std::numeric_limits<std::uint32_t>::max())
o.cellular_temperature_mk = static_cast<std::uint32_t>(*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<Options> 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<std::uint8_t> 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<server::PrimitiveLives> primitive_opening;
if (primitive) {
std::unique_ptr<server::CellularLives> 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<unsigned>(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<unsigned>(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<unsigned long long>(o.source.key.world),
@@ -425,9 +518,25 @@ int provision(const Options& o) {
static_cast<unsigned long long>(head.end_tick));
return 0;
};
persistence::Uuid commit{};
if (o.commit) {
commit = *o.commit;
} else if (::getrandom(commit.data(), commit.size(), 0) !=
static_cast<ssize_t>(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<ssize_t>(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<unsigned>(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,