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