Add cellular checkpoint manifest profile
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 40s
Foundation / checks (ecs) (push) Successful in 1m49s
Foundation / checks (postgres) (push) Failing after 51s
Foundation / checks (tsan) (push) Failing after 32s
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 3m42s
Foundation / checks (network) (push) Canceled after 3m4s

This commit is contained in:
dingo
2026-10-10 22:45:29 -04:00
parent 181b9aeec2
commit 3931fcfbe6
7 changed files with 163 additions and 19 deletions
+60 -9
View File
@@ -1,5 +1,6 @@
#include "evo/persistence/region_checkpoint.hpp"
#include <algorithm>
#include <array>
#include <ranges>
namespace evo::persistence {
@@ -59,9 +60,15 @@ bool structural(const CheckpointManifest& m) noexcept {
return false;
const auto& b = m.batch;
const bool primitive = m.profile == CheckpointProfile::primitive_lives_v1;
const bool cellular = m.profile == CheckpointProfile::cellular_lives_v1;
if ((!cellular && m.cellular_versions != cellular_v1_versions) ||
(cellular && m.versions != environmental_v1_versions))
return false;
if (primitive && (m.manifest_version != 2 || m.tick_microseconds != 50000 ||
b.decision_count != 0 || !zero(b.decisions_sha256)))
return false;
if (cellular && (m.manifest_version != 2 || m.tick_microseconds != 50000))
return false;
if (m.manifest_version != 1 && m.manifest_version != 2)
return false;
const bool no_batch = b == BatchDigests{};
@@ -70,8 +77,8 @@ bool structural(const CheckpointManifest& m) noexcept {
b.trace_bytes == 0 && zero(b.trace_sha256);
if (zero(m.predecessor_commit) && zero(m.predecessor_digest))
return genesis && m.end_tick == 0 && no_batch;
// Primitive cloning needs explicit life-binding remapping; not admitted yet.
if (primitive)
// Primitive and cellular cloning need explicit identity remapping; not admitted yet.
if (primitive || cellular)
return false;
// Clone genesis (ADR-0067, v2 only): the origin is the source commit and
// manifest digest; the block digests inherited permanent outcomes.
@@ -104,6 +111,11 @@ bool supported(const CheckpointManifest& m) noexcept {
return m.manifest_version == 2 && m.history_profile == primitive_history_profile &&
m.versions == primitive_v1_versions && m.tick_microseconds == 50000 &&
m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development;
if (m.profile == CheckpointProfile::cellular_lives_v1)
return m.manifest_version == 2 && m.history_profile == cellular_history_profile &&
m.cellular_versions == cellular_v1_versions &&
m.versions == environmental_v1_versions && m.tick_microseconds == 50000 &&
m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development;
const bool profile =
(m.profile == CheckpointProfile::environmental_v1 && m.history_profile == 0) ||
(m.profile == CheckpointProfile::environmental_lineage_v1 &&
@@ -134,9 +146,16 @@ encode_manifest(const CheckpointManifest& m) {
w.bytes(m.holder);
w.u(m.epoch, 8);
w.u(m.tick_microseconds, 8);
for (const auto v : {m.versions.rules, m.versions.envelope, m.versions.resources,
const auto versions =
m.profile == CheckpointProfile::cellular_lives_v1
? std::array{m.cellular_versions.rules, m.cellular_versions.envelope,
m.cellular_versions.habitat, m.cellular_versions.coordinate,
m.cellular_versions.genome, m.cellular_versions.development,
m.cellular_versions.founder, m.cellular_versions.archive, 0U}
: std::array{m.versions.rules, m.versions.envelope, m.versions.resources,
m.versions.fields, m.versions.terrain, m.versions.coordinate,
m.versions.generator, m.versions.material, m.versions.interval_adapter})
m.versions.generator, m.versions.material, m.versions.interval_adapter};
for (const auto v : versions)
w.u(v, 4);
w.bytes(m.build);
w.u(m.rng_streams, 4);
@@ -181,10 +200,18 @@ decode_manifest(std::span<const std::uint8_t> bytes) {
m.holder = r.bytes<16>();
m.epoch = r.u(8);
m.tick_microseconds = r.u(8);
for (auto* v : {&m.versions.rules, &m.versions.envelope, &m.versions.resources,
&m.versions.fields, &m.versions.terrain, &m.versions.coordinate,
&m.versions.generator, &m.versions.material, &m.versions.interval_adapter})
*v = static_cast<std::uint32_t>(r.u(4));
std::array<std::uint32_t, 9> versions{};
for (auto& v : versions)
v = static_cast<std::uint32_t>(r.u(4));
if (m.profile == CheckpointProfile::cellular_lives_v1) {
m.cellular_versions = {versions[0], versions[1], versions[2], versions[3], versions[4],
versions[5], versions[6], versions[7]};
if (versions[8] != 0)
return std::unexpected{CheckpointError::format};
} else {
m.versions = {versions[0], versions[1], versions[2], versions[3], versions[4],
versions[5], versions[6], versions[7], versions[8]};
}
m.build = r.bytes<32>();
m.rng_streams = static_cast<std::uint32_t>(r.u(4));
m.history_profile = static_cast<std::uint32_t>(r.u(4));
@@ -218,6 +245,10 @@ genesis_manifest(RegionKey key, std::uint64_t frame, Uuid commit, std::uint64_t
m.history_profile = primitive_history_profile;
m.versions = primitive_v1_versions;
}
if (profile == CheckpointProfile::cellular_lives_v1) {
m.history_profile = cellular_history_profile;
m.cellular_versions = cellular_v1_versions;
}
m.key = key;
m.frame = frame;
m.commit = commit;
@@ -234,7 +265,8 @@ std::expected<CheckpointManifest, CheckpointError>
clone_manifest(const CheckpointManifest& source, const Sha256Digest& source_digest,
RegionKey target, Uuid commit, std::uint64_t payload_bytes,
const Sha256Digest& payload_sha256, const BatchDigests& inherited) {
if (!supported(source) || source.profile == CheckpointProfile::primitive_lives_v1)
if (!supported(source) || source.profile == CheckpointProfile::primitive_lives_v1 ||
source.profile == CheckpointProfile::cellular_lives_v1)
return std::unexpected{CheckpointError::unsupported};
if (!structural(source) || target.world == source.key.world || commit == source.commit ||
inherited.trace_bytes != 0 || !zero(inherited.trace_sha256))
@@ -362,4 +394,23 @@ restore_primitive_payload(std::span<const std::uint8_t> payload, const Checkpoin
return std::unexpected{CheckpointError::payload};
return std::move(*restored);
}
std::expected<std::unique_ptr<server::CellularLives>, CheckpointError>
restore_cellular_payload(std::span<const std::uint8_t> payload, const CheckpointManifest& m) {
if (!structural(m))
return std::unexpected{CheckpointError::format};
if (!supported(m) || m.profile != CheckpointProfile::cellular_lives_v1)
return std::unexpected{CheckpointError::unsupported};
if (payload.size() != m.payload_bytes)
return std::unexpected{CheckpointError::payload};
auto restored = server::CellularLives::restore(payload, m.key.world, m.key.region, m.frame,
m.end_tick);
if (!restored)
return std::unexpected{restored.error() == server::CellularLivesError::version
? CheckpointError::unsupported
: CheckpointError::payload};
if (m.sequence == 0 && (!(*restored)->lives().empty() || !(*restored)->corpses().empty()))
return std::unexpected{CheckpointError::payload};
return std::move(*restored);
}
} // namespace evo::persistence