Complete M7.4b lineage checkpoint profile; M7.4 done
ADR-0062 adds a canonical LineageArchive codec (parents before children, organisms by id, FNV) that decodes by replaying admit/record_birth/ record_death and requires byte-identical re-encoding; it never overwrites an existing archive. LineageRegion binds the environmental producer and consumer accounts to archived organisms with identity high-waters, enforces closure (lifecycle vs deaths, exact living set, tick bounds) and records deaths in the tick that causes them. Checkpoint profile 2 (environmental-lineage-v1, history profile 1) publishes that container; schema v4 admits it with a 4,268,144-byte cap and requires each commit to keep its predecessor's profile, RNG, history and durability declarations. Linux adds provision/publish/recover for the profile on the shared publication path. Qualification found WSL2 stepping CLOCK_REALTIME back ~0.5 s every ~32 s, which made two 1 s-lease tests flaky under ASan. Tests now wait on database-time expiry; ADR-0060 records the slewed-clock requirement. Validated: Windows CTest 57/57; Linux GCC Debug/Release, clang-tidy and ASan/UBSan CTest 57/57 each; PostgreSQL suites 2x Release, 2x analysis, 5x ASan; SQL and C++ mutations each caught. No Docker/Gitea CI, remote store, process kill or deployment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,9 +51,12 @@ class Reader {
|
||||
|
||||
// Every field, independent of which versions this build supports.
|
||||
bool structural(const CheckpointManifest& m) noexcept {
|
||||
// An unknown profile is unsupported, not malformed: bound it by the largest cap.
|
||||
const auto cap = max_payload_bytes(m.profile);
|
||||
const auto limit = cap == 0 ? max_lineage_payload_bytes : cap;
|
||||
if (m.key.world == 0 || m.key.region == 0 || m.frame == 0 || zero(m.commit) ||
|
||||
m.tick_microseconds == 0 || zero(m.build) || m.payload_bytes == 0 ||
|
||||
m.payload_bytes > max_environmental_payload_bytes || zero(m.payload_sha256))
|
||||
m.payload_bytes > limit || zero(m.payload_sha256))
|
||||
return false;
|
||||
if (m.sequence == 0)
|
||||
return zero(m.predecessor_commit) && zero(m.predecessor_digest) && m.begin_tick == 0 &&
|
||||
@@ -65,9 +68,12 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
} // namespace
|
||||
|
||||
bool supported(const CheckpointManifest& m) noexcept {
|
||||
return m.profile == CheckpointProfile::environmental_v1 &&
|
||||
m.versions == environmental_v1_versions && m.rng_streams == 0 &&
|
||||
m.history_profile == 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 &&
|
||||
m.history_profile == lineage_history_profile);
|
||||
return profile && m.versions == environmental_v1_versions && m.rng_streams == 0 &&
|
||||
m.durability == DurabilityPolicy::single_volume_development;
|
||||
}
|
||||
|
||||
std::expected<std::vector<std::uint8_t>, CheckpointError>
|
||||
@@ -150,8 +156,11 @@ decode_manifest(std::span<const std::uint8_t> bytes) {
|
||||
std::expected<CheckpointManifest, CheckpointError>
|
||||
genesis_manifest(RegionKey key, std::uint64_t frame, Uuid commit, std::uint64_t tick_microseconds,
|
||||
const Sha256Digest& build, std::uint64_t payload_bytes,
|
||||
const Sha256Digest& payload_sha256) {
|
||||
const Sha256Digest& payload_sha256, CheckpointProfile profile) {
|
||||
CheckpointManifest m;
|
||||
m.profile = profile;
|
||||
m.history_profile =
|
||||
profile == CheckpointProfile::environmental_lineage_v1 ? lineage_history_profile : 0;
|
||||
m.key = key;
|
||||
m.frame = frame;
|
||||
m.commit = commit;
|
||||
@@ -196,7 +205,7 @@ restore_environmental_payload(std::span<const std::uint8_t> payload, const Check
|
||||
std::size_t budget) {
|
||||
if (!structural(m))
|
||||
return std::unexpected{CheckpointError::format};
|
||||
if (!supported(m))
|
||||
if (!supported(m) || m.profile != CheckpointProfile::environmental_v1)
|
||||
return std::unexpected{CheckpointError::unsupported};
|
||||
if (payload.size() != m.payload_bytes || payload.size() < 16)
|
||||
return std::unexpected{CheckpointError::payload};
|
||||
@@ -217,4 +226,30 @@ restore_environmental_payload(std::span<const std::uint8_t> payload, const Check
|
||||
return std::unexpected{CheckpointError::payload};
|
||||
return std::move(*restored);
|
||||
}
|
||||
|
||||
std::expected<std::unique_ptr<processes::LineageRegion>, CheckpointError>
|
||||
restore_lineage_payload(std::span<const std::uint8_t> payload, const CheckpointManifest& m,
|
||||
std::size_t budget) {
|
||||
if (!structural(m))
|
||||
return std::unexpected{CheckpointError::format};
|
||||
if (!supported(m) || m.profile != CheckpointProfile::environmental_lineage_v1)
|
||||
return std::unexpected{CheckpointError::unsupported};
|
||||
// Container header (56 bytes) and the nested envelope's magic and format.
|
||||
if (payload.size() != m.payload_bytes || payload.size() < 72)
|
||||
return std::unexpected{CheckpointError::payload};
|
||||
Reader container{payload.subspan(8)};
|
||||
Reader nested{payload.subspan(64)};
|
||||
if (container.u(4) != processes::lineage_region_format || nested.u(8) != m.versions.envelope)
|
||||
return std::unexpected{CheckpointError::unsupported};
|
||||
auto restored = processes::LineageRegion::restore(payload, {m.key.world, m.frame}, budget);
|
||||
if (!restored)
|
||||
return std::unexpected{restored.error() == processes::LineageRegionError::version
|
||||
? CheckpointError::unsupported
|
||||
: CheckpointError::payload};
|
||||
const auto& community = (*restored)->community();
|
||||
if (community.progress().tick != m.end_tick ||
|
||||
community.tick_microseconds() != m.tick_microseconds)
|
||||
return std::unexpected{CheckpointError::payload};
|
||||
return std::move(*restored);
|
||||
}
|
||||
} // namespace evo::persistence
|
||||
|
||||
Reference in New Issue
Block a user