Add explicit primitive genesis provisioning
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m57s
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 (client) (push) Canceled after 3m38s
Foundation / checks (checks) (push) Canceled after 3m44s
Foundation / checks (network) (push) Canceled after 1m39s

This commit is contained in:
dingo
2026-10-10 20:31:35 -04:00
parent fb131444c2
commit 7a6867b363
4 changed files with 254 additions and 17 deletions
+127 -17
View File
@@ -9,8 +9,10 @@
// [--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 --pg-* ...
// --objects DIR --build HEX [--retain-build]
// evo-world-clone provision --world W --region R --opening development-v1|primitive-v1
// --pg-* ... --objects DIR --build HEX [--retain-build]
// primitive-v1 also requires --frame N --source-id N, every --funding-*-* channel,
// and one or more ordered --site X,Y values.
// evo-world-clone compare --world A --region R --other-world B --pg-* ...
// --objects DIR [--other-objects DIR] --retained HEX... [--max-commits N]
//
@@ -40,6 +42,8 @@
// records the build identity (the server image digest) in retained_builds. The only
// opening is development-v1 (evo/processes/development_opening.hpp), for dev and
// stage; World0's opening is a separate, reviewed decision.
// primitive-v1 requires operator-supplied frame/source IDs, all five finite source inventory
// channels, and ordered habitat sites; no channel, site or profile is inferred.
// Output: provisioned|already-provisioned world=W region=R sequence=S tick=T
//
// compare (M8.9, ADR-0076) fully audits both regions of one database, then requires
@@ -53,7 +57,9 @@
#include "evo/persistence/region_clone.hpp"
#include "evo/persistence/sha256.hpp"
#include "evo/processes/development_opening.hpp"
#include "evo/server/lifecycle/primitive_lives.hpp"
#include <algorithm>
#include <array>
#include <charconv>
#include <csignal>
@@ -84,6 +90,9 @@ struct Options {
std::optional<persistence::Uuid> commit;
std::uint64_t audit_max{}, max_commits{1u << 20U}, reserve_mib{1024};
std::string opening;
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<persistence::Sha256Digest> build;
bool retain_build{};
bool crash{};
@@ -96,6 +105,19 @@ std::optional<std::uint64_t> number(std::string_view text) {
return std::nullopt;
return value;
}
std::optional<server::SpawnSite> site(std::string_view text) {
const auto comma = text.find(',');
if (comma == std::string_view::npos || text.find(',', comma + 1) != std::string_view::npos)
return std::nullopt;
std::int32_t x{}, y{};
const auto [x_end, x_error] = std::from_chars(text.data(), text.data() + comma, x);
const auto [y_end, y_error] =
std::from_chars(text.data() + comma + 1, text.data() + text.size(), y);
if (x_error != std::errc{} || x_end != text.data() + comma || y_error != std::errc{} ||
y_end != text.data() + text.size())
return std::nullopt;
return server::SpawnSite{x, y};
}
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;
@@ -204,9 +226,29 @@ std::optional<Options> parse(int argc, char** argv) {
o.max_commits = *n;
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")
else if (o.command == "provision" && flag == "--opening" &&
(value == "development-v1" || value == "primitive-v1"))
o.opening = value;
else if (o.command == "provision" && flag == "--build" && hex<32>(value))
else if (o.command == "provision" && flag == "--frame" && n)
o.primitive_frame = *n;
else if (o.command == "provision" && flag == "--source-id" && n)
o.primitive_source = *n;
else if (o.command == "provision" && flag == "--funding-energy-pj" && n)
o.primitive_funding[0] = *n;
else if (o.command == "provision" && flag == "--funding-carbon-fg" && n)
o.primitive_funding[1] = *n;
else if (o.command == "provision" && flag == "--funding-nitrogen-fg" && n)
o.primitive_funding[2] = *n;
else if (o.command == "provision" && flag == "--funding-phosphorus-fg" && n)
o.primitive_funding[3] = *n;
else if (o.command == "provision" && flag == "--funding-other-fg" && n)
o.primitive_funding[4] = *n;
else if (o.command == "provision" && flag == "--site") {
const auto parsed = site(value);
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 == "--build" && hex<32>(value))
o.build = hex<32>(value);
else if (o.command == "provision" && flag == "--retain-build" && value == "true")
o.retain_build = true;
@@ -224,8 +266,23 @@ std::optional<Options> parse(int argc, char** argv) {
o.target.objects = o.source.objects;
}
const bool needs_builds = o.command != "check-store" && o.command != "provision";
if (o.command == "provision" && (o.opening.empty() || !o.build))
return std::nullopt;
if (o.command == "provision") {
if (o.opening.empty() || !o.build)
return std::nullopt;
const bool primitive_options =
o.primitive_frame || o.primitive_source ||
std::ranges::any_of(o.primitive_funding, [](const auto& v) { return v.has_value(); }) ||
!o.primitive_sites.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) {
return std::nullopt;
}
}
if (!complete(o.source) || (needs_builds && o.retained.empty()) ||
(clone && !complete(o.target)))
return std::nullopt;
@@ -292,9 +349,9 @@ const char* name(persistence::CloneError e) {
return "unknown";
}
std::unique_ptr<persistence::FilesystemObjectStore> open_objects(const Side& s) {
auto store = persistence::FilesystemObjectStore::open(s.objects, s.key,
persistence::max_lineage_payload_bytes);
std::unique_ptr<persistence::FilesystemObjectStore>
open_objects(const Side& s, std::size_t max_payload = persistence::max_lineage_payload_bytes) {
auto store = persistence::FilesystemObjectStore::open(s.objects, s.key, max_payload);
if (!store)
return nullptr;
return std::move(*store);
@@ -317,7 +374,10 @@ std::vector<std::uint8_t> probe_bytes() {
}
int provision(const Options& o) {
auto store = open_objects(o.source);
const bool primitive = o.opening == "primitive-v1";
const auto payload_limit =
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");
return 4;
@@ -339,6 +399,24 @@ int provision(const Options& o) {
return 3;
}
}
std::unique_ptr<server::PrimitiveLives> primitive_opening;
if (primitive) {
server::NurseryConfig config{};
config.world = o.source.key.world;
config.region = o.source.key.region;
config.frame = *o.primitive_frame;
config.source = *o.primitive_source;
config.funding.energy.value = *o.primitive_funding[0];
for (std::size_t i = 0; i < 4; ++i)
config.funding.matter[i].value = *o.primitive_funding[i + 1];
config.sites = o.primitive_sites;
auto opening = server::PrimitiveLives::create(std::move(config));
if (!opening) {
std::printf("primitive opening refused %u\n", static_cast<unsigned>(opening.error()));
return 4;
}
primitive_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),
@@ -347,18 +425,50 @@ int provision(const Options& o) {
static_cast<unsigned long long>(head.end_tick));
return 0;
};
// Never re-provision: an existing region, whatever its state, is left alone.
auto existing = persistence::load_region_head(*db, o.source.key, timeout);
if (existing)
return report("already-provisioned", *existing);
// Never re-provision or report success for a different profile/frame.
auto existing = persistence::load_region_checkpoint(*db, o.source.key, timeout);
if (existing) {
const auto manifest = persistence::decode_manifest(existing->manifest);
const auto expected_profile =
primitive ? persistence::CheckpointProfile::primitive_lives_v1
: persistence::CheckpointProfile::environmental_lineage_v1;
const auto expected_frame =
primitive ? *o.primitive_frame : processes::development_opening_frame;
if (!manifest || manifest->profile != expected_profile ||
manifest->frame != expected_frame) {
std::puts("provision refused existing profile/frame mismatch");
return 4;
}
if (primitive) {
const std::array retained{manifest->build};
auto recovered = persistence::recover_primitive_checkpoint(*db, *store, o.source.key,
retained, timeout);
if (!recovered || recovered->state->snapshot() != primitive_opening->snapshot()) {
std::puts("provision refused existing opening mismatch");
return 4;
}
}
return report("already-provisioned", existing->head);
}
if (existing.error().kind != persistence::LeaseStoreError::not_provisioned) {
std::puts("database refused");
return 3;
}
auto opening = processes::development_opening(o.source.key.world);
persistence::Uuid commit{};
if (!opening ||
::getrandom(commit.data(), commit.size(), 0) != static_cast<ssize_t>(commit.size()))
if (::getrandom(commit.data(), commit.size(), 0) != static_cast<ssize_t>(commit.size()))
return 4;
if (primitive) {
auto made =
persistence::provision_primitive_region(*db, *store, o.source.key, *o.primitive_frame,
*primitive_opening, commit, build, timeout);
if (!made) {
std::printf("provision refused %u\n", static_cast<unsigned>(made.error().kind));
return 4;
}
return report("provisioned", made->head);
}
auto opening = processes::development_opening(o.source.key.world);
if (!opening)
return 4;
auto made = persistence::provision_lineage_region(
*db, *store, o.source.key, processes::development_opening_frame, **opening, commit, build,
+7
View File
@@ -106,6 +106,13 @@ Local checks do not close ADR-0097's reference-worker qualification.
host does not advance biology and is not connected to `evo-server` or QUIC yet.
Release/NDEBUG compilation, clang-format/tidy checks and the full PostgreSQL CI
gate passed; the maintainer confirmed success after `4c4ab36`.
- 11.2d-4 implementation: `evo-world-clone provision --opening primitive-v1`
requires owner-supplied frame/source IDs, all five finite funding channels and
ordered habitat sites. It writes profile-3 genesis using the primitive payload
bound and refuses an existing region whose profile or frame differs. A real-
PostgreSQL process test covers runtime-role refusal, owner provisioning, exact
retry, profile/frame mismatch and recovered opening values. No deployed world
was touched. The PostgreSQL CI gate remains to be confirmed.
- Next 11.2d subsection: `evo-server` profile selection and safe provisioning.
Authenticated v5 session admission/routing, process-kill qualification and
readiness integration remain after that; the generic host still serves only
+19
View File
@@ -5741,3 +5741,22 @@ The maintainer confirmed the CI rerun passed after `4c4ab36`; the v17 migration,
reservation contract check and full PostgreSQL gate are green. PostgreSQL remains
unavailable locally. This closes validation for 11.2d-2 and 11.2d-3; the primitive
host is still not connected to `evo-server` or enabled for v5 sessions.
## 2026-10-10 — M11.2d-4 primitive owner provisioning (CI pending)
Extended `evo-world-clone provision` with an explicit `primitive-v1` opening.
The operator must supply the frame, source ID, energy/carbon/nitrogen/phosphorus/
other funding values and ordered habitat sites. The tool uses the profile-3
object limit, refuses a different existing profile/frame or a changed primitive
opening, and only reports an existing primitive opening after full recovery and
state comparison. Added a PostgreSQL process test for runtime-role refusal,
owner provisioning, exact retry, frame/opening mismatch and recovered values.
Executed locally: Visual Studio clang-format 19.1.5 dry-run on both changed C++
files and `git diff --check`; both passed. The Windows environment cannot run the
Linux-only PostgreSQL process test. WSL launch was denied with `E_ACCESSDENIED`,
and the configured Linux compiler is not available directly in PowerShell. The
Windows repository format target stalled in Ninja and was stopped; formatting
was verified directly with the same pinned clang-format version. The primitive
provisioning build and PostgreSQL process test await Linux CI. No deployed world
was provisioned or changed.
+101
View File
@@ -3,7 +3,10 @@
// check-store probe (retention across runs, missing-volume refusal, privilege
// boundary) and a server whose volume is full. Run by tools/ci/postgres-check.sh.
#include "evo/persistence/checkpoint_store.hpp"
#include "evo/persistence/region_checkpoint.hpp"
#include "evo/server/lifecycle/primitive_lives.hpp"
#include "fixtures/server_process.hpp"
#include <algorithm>
#include <csignal>
#include <source_location>
#include <sys/resource.h>
@@ -245,10 +248,108 @@ void provisioning_is_idempotent() {
auto after = run(env("PGUSER"), code);
CHECK(code == 0 && has(after, "already-provisioned world=7 region=86 sequence=1 tick=5"));
}
// M11.2d-4: primitive genesis requires an explicit owner opening, and retries
// cannot mistake a different profile or frame for an idempotent success.
void primitive_provisioning_is_explicit_and_profile_safe() {
using namespace evo::server;
using evo::biology::primitive_endowment;
const ServerRegion r{{7, 87}, fresh("primitive-provision-87")};
const auto endowed = primitive_endowment();
CHECK(endowed);
evo::accounting::Inventory funding = endowed->body;
funding.energy.value += endowed->reserve.energy.value + endowed->construction.value;
const auto run = [&](const std::string& user, std::uint64_t frame, bool complete,
bool retain_build, int& code, std::uint64_t energy_delta = 0) {
std::vector<std::string> args{
env("EVO_WORLD_CLONE_BIN"),
"provision",
"--world",
"7",
"--region",
"87",
"--opening",
"primitive-v1",
"--pg-host",
env("PGHOST"),
"--pg-port",
env("PGPORT"),
"--pg-database",
env("PGDATABASE"),
"--pg-user",
user,
"--objects",
r.root.string(),
"--build",
"c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2c2",
"--frame",
std::to_string(frame),
"--source-id",
"1",
"--funding-energy-pj",
std::to_string(funding.energy.value + energy_delta),
"--funding-carbon-fg",
std::to_string(funding.matter[0].value),
"--funding-nitrogen-fg",
std::to_string(funding.matter[1].value),
"--funding-phosphorus-fg",
std::to_string(funding.matter[2].value),
"--funding-other-fg",
std::to_string(funding.matter[3].value),
"--site",
"0,0",
"--site",
"10000000,0"};
if (retain_build) {
args.insert(args.end() - 6, {"--retain-build", "true"});
}
if (!complete) {
const auto field = std::find(args.begin(), args.end(), "--funding-other-fg");
args.erase(field, field + 2);
}
Child tool{args};
code = tool.wait_exit(30s);
return tool.lines();
};
auto db = owner();
CHECK(db->query("INSERT INTO evolution.retained_builds(build_identity) VALUES "
"(decode(repeat('c2',32),'hex')) ON CONFLICT DO NOTHING",
{}, 5s));
int code = -1;
const auto denied = run(env("EVO_PG_RUNTIME_USER"), 3, true, false, code);
CHECK(code != 0 && !has(denied, "provisioned "));
const auto first = run(env("PGUSER"), 3, true, true, code);
CHECK(code == 0 && has(first, "provisioned world=7 region=87 sequence=0 tick=0"));
const auto retry = run(env("PGUSER"), 3, true, true, code);
CHECK(code == 0 && has(retry, "already-provisioned world=7 region=87 sequence=0 tick=0"));
const auto mismatch = run(env("PGUSER"), 4, true, true, code);
CHECK(code == 4 && has(mismatch, "provision refused existing profile/frame mismatch"));
const auto changed_opening = run(env("PGUSER"), 3, true, true, code, 1);
CHECK(code == 4 && has(changed_opening, "provision refused existing opening mismatch"));
const auto incomplete = run(env("PGUSER"), 3, false, false, code);
CHECK(code == 2);
const auto committed = load_region_checkpoint(*db, r.key, 5s);
CHECK(committed);
const auto manifest = decode_manifest(committed->manifest);
CHECK(manifest && manifest->profile == CheckpointProfile::primitive_lives_v1 &&
manifest->frame == 3);
auto objects =
FilesystemObjectStore::open(r.root, r.key, evo::server::max_primitive_lives_bytes);
CHECK(objects);
Sha256Digest build{};
build.fill(0xC2);
const std::array<Sha256Digest, 1> retained{build};
const auto recovered = recover_primitive_checkpoint(*db, **objects, r.key, retained, 5s);
CHECK(recovered && recovered->state->config().source == 1 &&
recovered->state->config().funding == funding &&
recovered->state->config().sites == std::vector<SpawnSite>{{0, 0}, {10000000, 0}});
}
} // namespace
void run_region_store_tests() {
provisioning_is_idempotent();
primitive_provisioning_is_explicit_and_profile_safe();
full_volumes_publish_nothing();
failing_writes_leave_nothing();
check_store_qualifies_the_stores();