M12.3: publish and recover durable exact populations
Foundation / checks (ecs) (push) Successful in 2m41s
Foundation / checks (tsan) (push) Failing after 18m12s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 20m41s
Foundation / checks (postgres) (push) Canceled after 20m43s
Foundation / checks (checks) (push) Canceled after 20m49s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (client) (push) Failing after 17m4s
Foundation / postgres-tools (push) Canceled after 0s

This commit is contained in:
dingo
2026-10-17 17:10:17 -04:00
parent d5d10a0cc7
commit 627411983f
35 changed files with 2637 additions and 102 deletions
+159
View File
@@ -0,0 +1,159 @@
#include "evo/persistence/region_checkpoint.hpp"
#include "evo/server/lifecycle/cellular_population_batch.hpp"
#include "fixtures/cellular_ecology.hpp"
namespace {
using namespace evo;
using namespace evo::server;
using namespace evo::persistence;
using namespace evo::fixture;
template <std::size_t N> std::array<std::uint8_t, N> filled(std::uint8_t byte) {
std::array<std::uint8_t, N> out{};
out.fill(byte);
return out;
}
CellularBatchHeader header(const CellularPopulation& state, std::uint64_t ticks) {
const auto& s = state.state();
return {s.world(), s.region(), s.frame(), filled<16>(1),
filled<32>(2), s.tick(), s.tick() + ticks};
}
CellularBatch inputs_batch(const CellularPopulation& base) {
CellularBatch batch{header(base, 64), {}};
auto biological = restore(base.state());
for (unsigned tick = 0; tick < 64; ++tick) {
auto inputs =
checked(wildlife_intents(*biological, biological->tick() + 1), "batch wildlife");
for (const auto& life : biological->lives()) {
if (life.account == LifeAccount{})
continue;
CellularLifeIntent frozen{life.identity.life, {}};
frozen.intent.frozen = true;
inputs.push_back(frozen);
}
std::ranges::sort(inputs, {}, &CellularLifeIntent::life_id);
batch.ticks.push_back({inputs, {}, {}});
checked(biological->advance_tick(inputs), "build biological input fixture");
}
return batch;
}
void traces() {
auto population = checked(
CellularPopulation::create(cellular_descendants(), {true, 1200, 1800}), "batch population");
std::uint64_t converted = 0;
for (unsigned interval = 0; interval < 6; ++interval) {
auto inputs = inputs_batch(*population);
require(checked(unattended_population_inputs(population->state(), inputs.header),
"unattended worker batch") == inputs,
"worker interval changed frozen/wildlife input contract");
const auto predecessor = population->snapshot();
auto execution = checked(prepare_population_batch(*population, inputs), "prepare trace");
const auto bytes = checked(encode_population_batch(execution.batch), "encode trace");
const auto decoded = checked(decode_population_batch(bytes), "decode trace");
require(decoded == execution.batch, "population trace round trip");
auto replay = checked(replay_population_batch(*population, decoded), "replay trace");
require(replay->snapshot() == execution.state->snapshot() &&
population->snapshot() == predecessor,
"trace changed predecessor or replay result");
auto altered = decoded;
++altered.boundaries.back().sequence;
require(!replay_population_batch(*population, altered), "altered sequence admitted");
altered = decoded;
altered.biology.ticks.front().lives.front().intent.frozen = false;
require(!replay_population_batch(*population, altered),
"unfrozen controlled step admitted");
for (std::size_t length = 0; length < bytes.size(); length += 113)
require(!decode_population_batch(std::span{bytes}.first(length)),
"truncated trace admitted");
auto extended = bytes;
extended.push_back(0);
require(!decode_population_batch(extended), "appended trace bytes admitted");
converted += replay->members().size();
population = std::move(replay);
}
require(converted > 0 && !population->members().empty(), "batch test has no cohorts");
const auto genome = population->members().front().genome;
const auto before = population->state().snapshot();
auto conversion =
checked(prepare_population_conversion(*population, header(*population, 0), {genome, false}),
"manual trace");
const auto encoded = checked(encode_population_batch(conversion.batch), "manual encode");
const auto decoded = checked(decode_population_batch(encoded), "manual decode");
auto replay = checked(replay_population_batch(*population, decoded), "manual replay");
require(replay->state().snapshot() == before && replay->members().empty(),
"manual materialization changed biology");
}
void manifests() {
auto state = cellular_descendants();
auto population = checked(CellularPopulation::create(restore(*state), {true, 1200, 1800}),
"manifest population");
CheckpointManifest source;
source.profile = CheckpointProfile::cellular_lives_v1;
source.cellular_versions = cellular_v9_versions;
source.history_profile = cellular_revision_history_profile;
source.key = {state->world(), state->region()};
source.frame = state->frame();
source.tick_microseconds = 50000;
source.sequence = 2;
source.commit = filled<16>(1);
source.predecessor_commit = filled<16>(2);
source.predecessor_digest = filled<32>(3);
source.holder = filled<16>(4);
source.epoch = 1;
source.begin_tick = state->tick() - 1;
source.end_tick = state->tick();
source.build = filled<32>(5);
source.payload_bytes = state->snapshot().size();
source.payload_sha256 = filled<32>(6);
source.batch = {128, filled<32>(7), 0, {}};
require(encode_manifest(source).has_value(), "source manifest fixture");
LeaseGrant lease{filled<16>(4), 1, state->frame(), std::chrono::milliseconds{20000}};
auto next = checked(population_profile_transition_manifest(
source, filled<32>(8), filled<16>(9), lease, source.build,
population->snapshot().size(), filled<32>(10)),
"profile transition");
require(next.profile == CheckpointProfile::cellular_population_v1 && supported(next),
"wrong profile");
const auto encoded = checked(encode_manifest(next), "population manifest");
require(checked(decode_manifest(encoded), "manifest decode") == next,
"manifest profile changed");
auto restored_population =
checked(restore_population_payload(population->snapshot(), next), "profile payload");
require(restored_population->snapshot() == population->snapshot(),
"population payload changed");
require(!restore_cellular_payload(population->snapshot(), next),
"population mislabeled as cellular");
auto back = checked(population_profile_transition_manifest(
next, filled<32>(11), filled<16>(12), lease, source.build,
state->snapshot().size(), filled<32>(13)),
"reverse transition");
require(back.end_tick == source.end_tick && back.profile == source.profile &&
checked(restore_cellular_payload(state->snapshot(), back), "unwrapped payload")
->snapshot() == state->snapshot(),
"profile transition changed biology/time");
auto execution = checked(prepare_population_batch(*population, inputs_batch(*population)),
"manifest tick fixture");
const auto trace = checked(encode_population_batch(execution.batch), "manifest trace fixture");
const auto advancing = population_successor_manifest(
next, filled<32>(11), filled<16>(12), lease, execution.state->state().tick(), source.build,
execution.state->snapshot().size(), filled<32>(13), {trace.size(), filled<32>(14), 0, {}});
require(advancing.has_value() &&
restore_population_payload(execution.state->snapshot(), *advancing).has_value(),
"population successor refused");
require(!clone_manifest(next, filled<32>(1), {9999, 1}, filled<16>(3), 100, filled<32>(4), {}),
"population clone admitted without identity remapping");
auto malformed = next;
malformed.sequence = 0;
require(!encode_manifest(malformed), "population genesis admitted");
malformed = next;
malformed.cellular_versions = cellular_v8_versions;
require(!supported(malformed), "unsupported nested rules admitted");
}
} // namespace
int main() try {
traces();
manifests();
return 0;
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}