M12.4: preserve exact biology across ownership candidates
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m18s
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 5m33s
Foundation / checks (postgres) (push) Canceled after 5m29s
Foundation / checks (tsan) (push) Canceled after 5m28s
Foundation / checks (client) (push) Canceled after 5m37s
Foundation / checks (network) (push) Canceled after 5m39s

This commit is contained in:
dingo
2026-10-17 18:17:59 -04:00
parent 0a8962b57e
commit decd4f8043
27 changed files with 1408 additions and 61 deletions
@@ -42,6 +42,9 @@ inline constexpr std::uint32_t cellular_lives_reproduction_rules = 7;
// contact; detritus becomes bubbles and emptied deposits disappear. The habitat envelope
// carries the new state, so they keep owner format 6.
inline constexpr std::uint32_t cellular_lives_foraging_rules = 8;
// ADR-0144: opt-in boundary accounting and retained nonresident history. Biology
// remains rules 8; every earlier envelope retains its original meaning.
inline constexpr std::uint32_t cellular_lives_migration_format = 7;
// The founder a region of these rules creates.
[[nodiscard]] constexpr biology::FounderVersion
cellular_founder_version(std::uint32_t rules) noexcept {
@@ -115,6 +118,12 @@ struct CellularOwnedCorpse {
std::uint64_t parent_life{}; // Format 5: kept after death.
auto operator<=>(const CellularOwnedCorpse&) const = default;
};
struct CellularBoundaryLedger {
accounting::Inventory incoming{}, outgoing{}; // Cumulative flows, never stock.
std::vector<std::uint64_t> nonresident_organisms; // Retained history, never activity.
bool operator==(const CellularBoundaryLedger&) const = default;
};
class CellularMigration;
struct CellularLifeIntent {
std::uint64_t life_id{};
biology::CellularStepIntent intent{};
@@ -240,6 +249,10 @@ class CellularLives {
[[nodiscard]] accounting::Inventory heat() const noexcept;
[[nodiscard]] accounting::Inventory opening_total() const noexcept;
[[nodiscard]] accounting::Inventory current_total() const noexcept;
[[nodiscard]] const CellularBoundaryLedger& boundary_ledger() const noexcept;
// Explicit detached format-6/rules-8 -> format-7 upgrade. No biology advances.
[[nodiscard]] std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
migration_upgrade_candidate() const;
// Latest successful in-memory step report; omitted from snapshots and empty after restore.
[[nodiscard]] std::span<const CellularLifeTickFeedback> last_tick_feedback() const noexcept;
[[nodiscard]] std::vector<std::uint8_t> snapshot() const;
@@ -280,6 +293,10 @@ class CellularLives {
std::span<const CellularMutationSelection> selections);
private:
friend class CellularMigration;
[[nodiscard]] std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
migration_replacement(std::vector<CellularOwnedLife>, const biology::LineageArchive&,
CellularBoundaryLedger) const;
struct State;
explicit CellularLives(std::unique_ptr<State> state);
std::unique_ptr<State> state_;
@@ -0,0 +1,41 @@
#pragma once
#include "evo/server/lifecycle/cellular_population.hpp"
namespace evo::server {
enum class CellularMigrationError : std::uint8_t {
version,
identity,
tick,
ineligible,
capacity,
placement,
archive,
overflow,
conservation
};
struct CellularMigrationExecution {
std::uint64_t genome{};
std::vector<std::uint64_t> members;
accounting::Inventory transferred;
std::unique_ptr<CellularLives> source, destination;
};
struct CellularPopulationMigrationExecution {
std::uint64_t genome{};
std::vector<std::uint64_t> members;
accounting::Inventory transferred;
std::unique_ptr<CellularPopulation> source, destination;
};
// ADR-0144: exact no-tick ownership candidates at an explicitly compatible cut.
// This chooses neither a route nor a movement. It preserves every coordinate and
// biological field, imports the complete genome ancestry and moves actual stock.
// Publication must commit the pair under both current fences before activation.
class CellularMigration {
public:
[[nodiscard]] static std::expected<CellularMigrationExecution, CellularMigrationError>
prepare(const CellularLives& source, const CellularLives& destination, std::uint64_t genome);
[[nodiscard]] static std::expected<CellularPopulationMigrationExecution, CellularMigrationError>
prepare(const CellularPopulation& source, const CellularPopulation& destination,
std::uint64_t genome);
};
} // namespace evo::server
@@ -49,6 +49,10 @@ class CellularPopulation {
[[nodiscard]] bool in_cohort(std::uint64_t life) const noexcept;
[[nodiscard]] CellularTierPolicy policy() const noexcept;
[[nodiscard]] std::uint64_t conversion_sequence() const noexcept;
[[nodiscard]] std::uint32_t format_version() const noexcept;
// Explicit no-tick envelope-1 -> envelope-2 upgrade, retaining all cohort tags.
[[nodiscard]] std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
migration_upgrade_candidate() const;
[[nodiscard]] std::vector<std::uint8_t> snapshot() const;
[[nodiscard]] static std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
restore(std::span<const std::uint8_t> bytes, std::uint64_t world, std::uint64_t region,
@@ -73,6 +77,7 @@ class CellularPopulation {
std::span<const CellularMutationSelection> selections = {});
private:
friend class CellularMigration;
friend std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
execute_population_batch(const CellularPopulation&, CellularPopulationBatch&, bool);
explicit CellularPopulation(std::unique_ptr<CellularLives> state, CellularTierPolicy policy);