Add cellular genome revision profile migration
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m59s
Foundation / checks (checks) (push) Failing after 2m10s
Foundation / checks (postgres) (push) Failing after 10m34s
Foundation / checks (network) (push) Failing after 12m19s
Foundation / checks (tsan) (push) Failing after 2m14s
Foundation / checks (client) (push) Successful in 15m7s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-11 06:13:17 -04:00
parent 66ffdc1cad
commit a479ce2d95
25 changed files with 725 additions and 79 deletions
+36 -3
View File
@@ -3,6 +3,8 @@
#include "evo/biology/genome.hpp"
#include "evo/core/types.hpp"
#include <span>
namespace evo::biology {
// What the archive can establish about itself. There is deliberately no third
// value: terminal extinction is a policy judgement over a reconciled world
@@ -25,11 +27,12 @@ enum class HistoryError : std::uint8_t {
unknown_organism,
already_dead,
invalid_identity,
invalid_tick
invalid_tick,
invalid_revision
};
inline constexpr std::size_t max_archived_genomes = 4'096;
inline constexpr std::size_t max_archived_organisms = 65'536;
// Whole-archive codec v1 (schemas/lineage-archive-v1.md, ADR-0062).
// Whole-archive codecs v1/v2 (schemas/lineage-archive-v1.md and -v2.md).
enum class ArchiveCodecError : std::uint8_t {
format, // Magic, lengths or field forms.
version, // Unknown archive format or genome schema.
@@ -40,10 +43,21 @@ enum class ArchiveCodecError : std::uint8_t {
noncanonical, // Valid content in a non-canonical order or form.
};
inline constexpr std::uint32_t lineage_archive_format = 1;
inline constexpr std::uint32_t lineage_archive_revision_format = 2;
inline constexpr std::size_t archived_organism_bytes = 33;
inline constexpr std::size_t max_archive_bytes =
inline constexpr std::size_t archived_genome_revision_bytes = 40;
inline constexpr std::size_t max_archive_legacy_bytes =
32 + (max_archived_genomes * (2 + max_genome_bytes)) +
(max_archived_organisms * archived_organism_bytes) + 8;
inline constexpr std::size_t max_archive_bytes =
40 + (max_archived_genomes * (2 + max_genome_bytes)) +
(max_archived_organisms * archived_organism_bytes) +
(max_archived_genomes * archived_genome_revision_bytes) + 8;
struct OrganismGenomeRevision {
std::uint64_t organism{}, previous_genome{}, successor_genome{}, origin_event{};
Tick at{};
auto operator<=>(const OrganismGenomeRevision&) const = default;
};
// Retains genomes and the organisms that carried them. There is no removal
// operation: not a guarded one, not a private one. Retention is a property of
@@ -70,10 +84,18 @@ class LineageArchive {
std::uint64_t genome, Tick when);
// Terminal for the organism, and nothing to do with the genome it carried.
[[nodiscard]] std::expected<void, HistoryError> record_death(std::uint64_t organism, Tick when);
// Adds a successor genome and binds it as the next genome carried by a living
// organism. Birth records remain immutable; the revision chain is append-only.
[[nodiscard]] std::expected<void, HistoryError>
record_mutation(std::uint64_t organism, const Genome& successor, Tick when);
// Explicitly upgrades a revision-free archive during a cellular profile migration.
void upgrade_to_revision_format() noexcept;
[[nodiscard]] std::expected<Genome, HistoryError> find(std::uint64_t genome) const;
[[nodiscard]] std::expected<OrganismRecord, HistoryError>
organism(std::uint64_t identity) const;
[[nodiscard]] std::expected<std::uint64_t, HistoryError>
current_genome(std::uint64_t organism) const;
// Oldest first, ending at the founder. Still resolves after every carrier dies.
[[nodiscard]] std::expected<std::vector<std::uint64_t>, HistoryError>
ancestry(std::uint64_t genome) const;
@@ -90,11 +112,17 @@ class LineageArchive {
[[nodiscard]] std::size_t archived() const noexcept {
return genomes_.size();
}
[[nodiscard]] std::uint32_t format_version() const noexcept {
return format_version_;
}
[[nodiscard]] std::size_t recorded() const noexcept {
return organisms_.size();
}
// Ascending identities of organisms not yet recorded dead.
[[nodiscard]] std::vector<std::uint64_t> living_organisms() const;
[[nodiscard]] std::span<const OrganismGenomeRevision> revisions() const noexcept {
return revisions_;
}
// Largest recorded identities, zero when none: allocator high-water checks.
[[nodiscard]] std::uint64_t highest_genome() const noexcept;
[[nodiscard]] std::uint64_t highest_organism() const noexcept;
@@ -121,5 +149,10 @@ class LineageArchive {
// ADR-0030, so an aggregate holding one would have a throwing move.
std::vector<Genome> genomes_;
std::vector<ArchivedOrganism> organisms_;
std::vector<OrganismGenomeRevision> revisions_;
std::uint32_t format_version_{lineage_archive_format};
[[nodiscard]] std::expected<void, HistoryError>
append_revision(std::uint64_t organism, std::uint64_t previous, std::uint64_t successor,
std::uint64_t origin_event, Tick when);
};
} // namespace evo::biology
@@ -239,6 +239,11 @@ migrate_cellular_profile_to_v2(Postgres& db, const FilesystemObjectStore& object
Uuid commit, const Sha256Digest& build,
std::chrono::milliseconds timeout);
[[nodiscard]] std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
migrate_cellular_profile_to_v3(Postgres& db, const FilesystemObjectStore& objects,
const LeaseGrant& lease, const CommittedCheckpoint& predecessor,
Uuid commit, const Sha256Digest& build,
std::chrono::milliseconds timeout);
[[nodiscard]] std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
retry_cellular_profile_migration(Postgres& db, const CellularProfileMigrationPrepared& prepared,
std::chrono::milliseconds timeout);
@@ -31,6 +31,7 @@ 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 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 };
@@ -51,6 +52,7 @@ struct CellularVersionBundle {
};
inline constexpr CellularVersionBundle cellular_v1_versions{};
inline constexpr CellularVersionBundle cellular_v2_versions{2, 2, 1, 1, 1, 2, 1, 1, 1};
inline constexpr CellularVersionBundle cellular_v3_versions{2, 3, 1, 1, 1, 2, 1, 2, 1};
// Batch evidence bound by manifest v2 (ADR-0063); all zero at genesis.
struct BatchDigests {
@@ -140,8 +142,8 @@ successor_manifest(const CheckpointManifest& predecessor, const Sha256Digest& pr
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);
// The only supported cellular profile transition: a leased, no-tick v1-to-v2
// representation migration. SQL publication must independently verify the pair.
// Leased, no-tick cellular representation migration. SQL publication independently
// verifies the exact adjacent profile transition.
[[nodiscard]] std::expected<CheckpointManifest, CheckpointError>
cellular_profile_migration_manifest(const CheckpointManifest& predecessor,
const Sha256Digest& predecessor_digest, Uuid commit,
+1 -1
View File
@@ -29,7 +29,7 @@ enum class LineageRegionError : std::uint8_t {
};
inline constexpr std::uint32_t lineage_region_format = 1;
inline constexpr std::size_t max_lineage_region_bytes =
72 + EnvironmentalCommunity::max_snapshot_bytes + biology::max_archive_bytes;
72 + EnvironmentalCommunity::max_snapshot_bytes + biology::max_archive_legacy_bytes;
class LineageRegion {
public:
@@ -16,6 +16,7 @@
namespace evo::server {
inline constexpr std::uint32_t cellular_lives_legacy_format = 1;
inline constexpr std::uint32_t cellular_lives_format = 2;
inline constexpr std::uint32_t cellular_lives_revision_format = 3;
inline constexpr std::uint32_t cellular_lives_rules = 2;
inline constexpr std::size_t max_cellular_lives_bytes = std::size_t{16} * 1024 * 1024;
inline constexpr std::uint64_t cellular_mutation_surplus_seconds = 60;
@@ -135,6 +136,9 @@ class CellularLives {
// Detached no-tick representation upgrade. Only a fully restored v1 owner can migrate.
[[nodiscard]] std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
migrate_to_v2() const;
// Detached no-tick v2-to-v3 profile upgrade enabling genome revisions.
[[nodiscard]] std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
migrate_to_v3() const;
// Returns a detached post-birth candidate for an allocator-reserved request.
// The caller supplies the durable identity; the owner derives founder biology,
@@ -25,7 +25,7 @@ inline constexpr std::size_t max_primitive_lives = 256;
inline constexpr std::int32_t spawn_coordinate_limit_um = 1'000'000'000;
inline constexpr std::uint32_t primitive_lives_format = 1;
inline constexpr std::size_t max_primitive_lives_bytes =
200 + 184 * max_primitive_lives + biology::max_archive_bytes;
200 + 184 * max_primitive_lives + biology::max_archive_legacy_bytes;
enum class LifeCodecError : std::uint8_t { format, version, checksum, closure };
struct NurseryConfig {
std::uint64_t world{}, region{}, frame{}, source{};