feat(persistence): admit durable cellular environment profile
Foundation / checks (ecs) (push) Successful in 2m24s
Foundation / checks (deploy) (push) Successful in 4m51s
Foundation / checks (network) (push) Successful in 20m42s
Foundation / checks (client) (push) Successful in 21m53s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 40m19s
Foundation / checks (postgres) (push) Canceled after 40m9s
Foundation / checks (tsan) (push) Canceled after 37m53s

ADR-0174 and schema 56 add checkpoint profile 6, which stores the joint
cell/environment envelope nesting population envelope 2 (bundles 10 and
11). Entry from a committed population head is explicit, one-way and
no-tick, with the source commit, manifest and payload digests bound in
immutable evidence. Joint intervals use schema 45's owned admission and
settlement; conversions cannot overtake a pending interval. The fenced
publisher validates the joint trace structurally, including the complete
nested population batch, and records per-commit imported and radiated
totals. Recovery replays the head's link and requires the payload
exactly, refusing a forged but structurally valid trace. A trigger
refuses profile-6 commits from every other publisher; profile 4/5 bytes,
parsers and rules are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-19 17:16:50 -04:00
co-authored by Claude Opus 5.5
parent fc6d26d7d6
commit 51991ac7ff
25 changed files with 1599 additions and 63 deletions
@@ -0,0 +1,41 @@
#pragma once
#include "evo/persistence/population_checkpoint_store.hpp"
namespace evo::persistence {
// ADR-0174 / schema 56. Prepared joint commits reuse the population shape: an empty
// trace is the no-tick profile 5 -> 6 transition, otherwise a joint batch.
struct RecoveredEnvironmentCheckpoint {
CommittedCheckpoint committed;
CheckpointManifest manifest;
std::unique_ptr<server::CellularEnvironment> state;
};
// Explicit, one-way and no-tick: wraps the identical committed population with its
// declared environment under the same lease/head fence. No biology advances.
[[nodiscard]] std::expected<CommittedCheckpoint, PopulationPublicationFailure>
migrate_population_to_environment(Postgres&, const FilesystemObjectStore&, const LeaseGrant&,
const CommittedCheckpoint& predecessor, Uuid commit,
const Sha256Digest& build, server::CellularEnvironmentConfig,
std::chrono::milliseconds timeout,
const PublishHooks& hooks = {});
// A joint interval (after an owned admission) or whole-group conversion. The batch is
// replayed from the committed predecessor and must reproduce `candidate` exactly.
[[nodiscard]] std::expected<CommittedCheckpoint, PopulationPublicationFailure>
publish_environment_batch(Postgres&, const FilesystemObjectStore&, const LeaseGrant&,
const CommittedCheckpoint& predecessor,
const server::CellularEnvironmentBatch& batch,
const server::CellularEnvironment& candidate, Uuid commit,
const Sha256Digest& build, std::chrono::milliseconds timeout,
const PublishHooks& hooks = {});
[[nodiscard]] std::expected<CommittedCheckpoint, PopulationPublicationFailure>
retry_environment_prepared(Postgres&, const PopulationPreparedCommit&,
std::chrono::milliseconds timeout);
[[nodiscard]] std::expected<ResolvedCommit, LeaseStoreFailure>
resolve_environment_prepared(Postgres&, const PopulationPreparedCommit&,
std::chrono::milliseconds timeout);
// Loads the head, requires its complete evidence and replays its link exactly.
[[nodiscard]] std::expected<RecoveredEnvironmentCheckpoint, RecoveryFailure>
recover_environment_checkpoint(Postgres&, const FilesystemObjectStore&, RegionKey,
const LeaseGrant&, std::span<const Sha256Digest> retained_builds,
std::chrono::milliseconds timeout);
} // namespace evo::persistence
@@ -4,6 +4,7 @@
#include "evo/processes/environmental_community.hpp"
#include "evo/processes/lineage_region.hpp"
#include "evo/server/lifecycle/cellular_batch.hpp"
#include "evo/server/lifecycle/cellular_environment.hpp"
#include "evo/server/lifecycle/cellular_lives.hpp"
#include "evo/server/lifecycle/cellular_population_batch.hpp"
#include "evo/server/lifecycle/primitive_batch.hpp"
@@ -27,13 +28,22 @@ enum class CheckpointProfile : std::uint8_t {
primitive_lives_v1 = 3, // Funded creation state; history_profile 2.
cellular_lives_v1 = 4, // Complete cellular state; history_profile 3 or 4.
cellular_population_v1 = 5, // Exact populations; cellular bundle 9, 10 or 11.
cellular_environment_v1 = 6, // ADR-0174: cells with their environment; bundle 10 or 11.
};
// Profiles whose manifests carry a CellularVersionBundle.
[[nodiscard]] constexpr bool cellular_profile(CheckpointProfile profile) noexcept {
return profile == CheckpointProfile::cellular_lives_v1 ||
profile == CheckpointProfile::cellular_population_v1 ||
profile == CheckpointProfile::cellular_environment_v1;
}
// history_profile 1: lineage archive format 1 with genome schema 1.
inline constexpr std::uint32_t lineage_history_profile = 1;
// Archive format 1, genome schema 2, development 2, founder-life rules 1.
inline constexpr std::uint32_t primitive_history_profile = 2;
inline constexpr std::uint32_t cellular_history_profile = 3;
inline constexpr std::uint32_t population_history_profile = 5;
// ADR-0174: joint envelope 1 nesting population envelope 2 and its lineage archive.
inline constexpr std::uint32_t environment_history_profile = 6;
inline constexpr std::uint32_t cellular_revision_history_profile = 4;
// Declared durability, verified at deployment. Development: one volume, no host-loss claim.
enum class DurabilityPolicy : std::uint8_t { unknown = 0, single_volume_development = 1 };
@@ -146,6 +156,8 @@ inline constexpr std::size_t max_lineage_payload_bytes = processes::max_lineage_
: profile == CheckpointProfile::cellular_lives_v1 ? server::max_cellular_lives_bytes
: profile == CheckpointProfile::cellular_population_v1
? server::max_cellular_population_bytes
: profile == CheckpointProfile::cellular_environment_v1
? server::max_cellular_environment_bytes
: 0;
}
inline constexpr std::uint64_t max_checkpoint_ticks = 64;
@@ -263,6 +275,22 @@ cellular_inheritance_upgrade_manifest(const CheckpointManifest& predecessor,
[[nodiscard]] std::expected<std::vector<std::uint8_t>, CheckpointError>
cellular_inheritance_upgrade_payload(std::span<const std::uint8_t> payload,
const CheckpointManifest& predecessor);
// ADR-0174: explicit one-way, no-tick profile 5 -> 6 transition. The payload wraps the
// identical population with its declared environment; bundle and policy are unchanged.
[[nodiscard]] std::expected<CheckpointManifest, CheckpointError>
environment_profile_transition_manifest(const CheckpointManifest& predecessor,
const Sha256Digest& predecessor_digest, Uuid commit,
const LeaseGrant& lease, const Sha256Digest& build,
std::uint64_t payload_bytes,
const Sha256Digest& payload_sha256);
// Joint interval or whole-group conversion; a conversion keeps the tick with a trace.
[[nodiscard]] std::expected<CheckpointManifest, CheckpointError> environment_successor_manifest(
const CheckpointManifest& predecessor, const Sha256Digest& predecessor_digest, Uuid commit,
const LeaseGrant& lease, std::uint64_t end_tick, const Sha256Digest& build,
std::uint64_t payload_bytes, const Sha256Digest& payload_sha256, const BatchDigests& batch);
[[nodiscard]] std::expected<std::unique_ptr<server::CellularEnvironment>, CheckpointError>
restore_environment_payload(std::span<const std::uint8_t> payload,
const CheckpointManifest& manifest);
// Population manual conversion may publish at the same tick with a nonempty trace.
[[nodiscard]] std::expected<CheckpointManifest, CheckpointError> population_successor_manifest(
const CheckpointManifest& predecessor, const Sha256Digest& predecessor_digest, Uuid commit,
@@ -238,4 +238,19 @@ resolve_population_commit(Postgres&, RegionKey, const Uuid& commit,
[[nodiscard]] std::expected<std::optional<PopulationEvidence>, LeaseStoreFailure>
load_population_evidence(Postgres&, RegionKey, const LeaseGrant&, const Uuid& commit,
std::chrono::milliseconds timeout);
// ADR-0174 / schema 56: the joint profile's fenced publishers and immutable evidence.
[[nodiscard]] std::expected<RegionHead, LeaseStoreFailure>
publish_environment_checkpoint(Postgres&, std::span<const std::uint8_t> manifest,
std::span<const std::uint8_t> trace,
std::chrono::milliseconds timeout);
[[nodiscard]] std::expected<RegionHead, LeaseStoreFailure>
publish_environment_profile_transition(Postgres&, std::span<const std::uint8_t> manifest,
std::chrono::milliseconds timeout);
[[nodiscard]] std::expected<ResolvedCommit, LeaseStoreFailure>
resolve_environment_commit(Postgres&, RegionKey, const Uuid& commit,
std::span<const std::uint8_t> manifest,
std::span<const std::uint8_t> trace, std::chrono::milliseconds timeout);
[[nodiscard]] std::expected<std::optional<PopulationEvidence>, LeaseStoreFailure>
load_environment_evidence(Postgres&, RegionKey, const LeaseGrant&, const Uuid& commit,
std::chrono::milliseconds timeout);
} // namespace evo::persistence