M12.4: isolate continued population replay after transfer
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m23s
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 14m44s
Foundation / checks (checks) (push) Canceled after 14m44s
Foundation / checks (network) (push) Canceled after 14m43s
Foundation / checks (postgres) (push) Canceled after 14m42s
Foundation / checks (tsan) (push) Canceled after 14m43s

This commit is contained in:
dingo
2026-10-17 22:07:47 -04:00
parent 1e207b5ee4
commit 89f29fef3a
13 changed files with 209 additions and 10 deletions
@@ -28,7 +28,8 @@ bool canonical(const PopulationPreparedCommit& prepared, const CheckpointManifes
m.begin_tick == m.end_tick && m.batch == BatchDigests{};
const auto trace = server::decode_population_batch(prepared.trace);
const auto digest = sha256(prepared.trace);
if (!trace || !digest || m.profile != CheckpointProfile::cellular_population_v1 ||
if (!trace || !digest || trace->format_version != 1 ||
m.profile != CheckpointProfile::cellular_population_v1 ||
m.batch != BatchDigests{prepared.trace.size(), *digest, 0, {}})
return false;
const auto& h = trace->header;
@@ -6,14 +6,16 @@
namespace evo::server {
namespace {
constexpr std::uint64_t magic = 0x315442504F564541ULL; // "AEVOPBT1"
constexpr std::uint64_t magic = 0x315442504F564541ULL; // "AEVOPBT1"
constexpr std::uint64_t migration_magic = 0x325442504F564541ULL; // "AEVOPBT2"
bool shape(const CellularPopulationBatch& batch, bool recording) {
const auto& h = batch.header;
const auto zero = [](const auto& bytes) {
return std::ranges::all_of(bytes, [](auto byte) { return byte == 0; });
};
if (h.world == 0 || h.region == 0 || h.frame == 0 || zero(h.predecessor) ||
zero(h.predecessor_digest) || h.end_tick < h.begin_tick)
if ((batch.format_version != 1 && batch.format_version != 2) || h.world == 0 || h.region == 0 ||
h.frame == 0 || zero(h.predecessor) || zero(h.predecessor_digest) ||
h.end_tick < h.begin_tick)
return false;
const auto count = batch.conversion ? std::size_t{1} : batch.biology.ticks.size();
if (count == 0 || count > max_cellular_batch_ticks ||
@@ -117,9 +119,9 @@ unattended_population_inputs(const CellularLives& base, const CellularBatchHeade
std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
execute_population_batch(const CellularPopulation& base, CellularPopulationBatch& batch,
bool record) {
// Trace 1 is retained for envelope 1. A future durable migration adapter must
// bind the new owner/envelope tuple explicitly before recording its history.
if (base.format_version() != 1)
// Each trace version retains its exact owner/envelope meaning. Portable trace
// 2 is not admission to an existing durable bundle.
if (base.format_version() != batch.format_version)
return std::unexpected(CellularPopulationError::unsupported);
if (!shape(batch, record) || batch.header.world != base.state().world() ||
batch.header.region != base.state().region() ||
@@ -192,6 +194,7 @@ prepare_population_batch(const CellularPopulation& base, CellularBatch biology)
if (!population_interval_safe(base.state()))
return std::unexpected(CellularPopulationError::ineligible);
CellularPopulationBatch batch{biology.header, std::move(biology), {}, {}};
batch.format_version = base.format_version();
auto state = execute_population_batch(base, batch, true);
if (!state)
return std::unexpected(state.error());
@@ -201,6 +204,7 @@ std::expected<CellularPopulationExecution, CellularPopulationError>
prepare_population_conversion(const CellularPopulation& base, CellularBatchHeader header,
CellularPopulationConversion conversion) {
CellularPopulationBatch batch{header, {}, conversion, {}};
batch.format_version = base.format_version();
auto state = execute_population_batch(base, batch, true);
if (!state)
return std::unexpected(state.error());
@@ -224,8 +228,8 @@ encode_population_batch(const CellularPopulationBatch& batch) {
biological = std::move(*encoded);
}
std::vector<std::uint8_t> out;
put(out, magic);
put(out, 1, 4);
put(out, batch.format_version == 2 ? migration_magic : magic);
put(out, batch.format_version, 4);
put(out, batch.conversion ? 1 : 0, 4);
const auto& h = batch.header;
for (const auto value : {h.world, h.region, h.frame})
@@ -256,10 +260,14 @@ decode_population_batch(std::span<const std::uint8_t> bytes) {
if (bytes.size() < population_batch_header_bytes || bytes.size() > max_population_batch_bytes)
return std::unexpected(CellularPopulationError::format);
Reader in(bytes);
if (in.get() != magic || in.get(4) != 1)
const auto saved_magic = in.get();
const auto version = in.get(4);
if (!((saved_magic == magic && version == 1) ||
(saved_magic == migration_magic && version == 2)))
return std::unexpected(CellularPopulationError::unsupported);
const auto kind = in.get(4);
CellularPopulationBatch batch;
batch.format_version = static_cast<std::uint32_t>(version);
auto& h = batch.header;
h.world = in.get();
h.region = in.get();