M12.6: derive replayed census history from immutable commits
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (network) (push) Successful in 20m50s
Foundation / checks (client) (push) Successful in 22m7s
Foundation / checks (tsan) (push) Successful in 24m42s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 35m33s
Foundation / checks (checks) (push) Canceled after 35m43s

This commit is contained in:
dingo
2026-10-18 14:36:14 -04:00
parent da39fc8095
commit a180c41ae7
23 changed files with 732 additions and 18 deletions
@@ -0,0 +1,43 @@
#pragma once
#include "evo/persistence/population_checkpoint_store.hpp"
#include "evo/server/lifecycle/cellular_census.hpp"
#include <cstddef>
#include <cstdint>
#include <expected>
#include <optional>
#include <span>
#include <vector>
namespace evo::persistence {
inline constexpr std::size_t max_cellular_history_page = 8;
struct CellularCensusHistoryEntry {
CommittedCheckpoint committed;
server::CellularCensus census;
};
struct CellularCensusHistoryPage {
RegionKey key{};
RegionHead watermark{}; // Exact immutable regional upper cut, not world coverage.
std::vector<CellularCensusHistoryEntry> entries;
std::optional<std::uint64_t> next_sequence;
};
enum class CellularHistoryError : std::uint8_t { invalid_request, cut_mismatch, recovery };
struct CellularHistoryFailure {
CellularHistoryError kind{};
RecoveryFailure recovery{}; // Meaningful only for recovery.
};
// Read-only forward history from the existing atomic biological commit journal.
// Inclusive first_sequence, at most eight consecutive commits, pinned upper cut.
// Full historical replay precedes every census. Any missing/unsupported/false
// evidence fails the ENTIRE page; there is no zero/skip/older-head fallback.
// Requires an idle connection: caller-owned transactions (including read-only
// transactions) are refused so pending writer changes cannot appear durable.
// Current grant is used by existing fenced evidence readers; output confers no
// live authority, recovery-branch identity or world completeness. Per-I/O timeout.
[[nodiscard]] std::expected<CellularCensusHistoryPage, CellularHistoryFailure>
load_cellular_census_history(Postgres&, const FilesystemObjectStore&, RegionKey, const LeaseGrant&,
const RegionHead& watermark, std::uint64_t first_sequence,
std::size_t limit, std::span<const Sha256Digest> retained_builds,
std::chrono::milliseconds timeout);
} // namespace evo::persistence
@@ -239,6 +239,12 @@ resolve_cellular_prepared(Postgres& db, const CellularPreparedCommit& prepared,
recover_cellular_checkpoint(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
const LeaseGrant& lease, std::span<const Sha256Digest> retained_builds,
std::chrono::milliseconds timeout);
// Read-only historical recovery with the SAME full replay/evidence validation.
// Never select this state as a live head, resume an old owner or infer authority.
[[nodiscard]] std::expected<RecoveredCellularCheckpoint, RecoveryFailure>
recover_cellular_commit(Postgres&, const FilesystemObjectStore&, RegionKey, std::uint64_t sequence,
const LeaseGrant&, std::span<const Sha256Digest> retained_builds,
std::chrono::milliseconds timeout);
// Leased, no-tick representation migration. The v1 payload is restored and
// converted in memory before one immutable v1-to-v2 migration commit is written.
[[nodiscard]] std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
@@ -45,6 +45,13 @@ resolve_population_prepared(Postgres&, const PopulationPreparedCommit&,
recover_population_checkpoint(Postgres&, const FilesystemObjectStore&, RegionKey, const LeaseGrant&,
std::span<const Sha256Digest> retained_builds,
std::chrono::milliseconds timeout);
// Explicit read-only historical recovery. It does not replace the current head
// or grant ownership; all ordinary evidence/complete replay checks still apply.
[[nodiscard]] std::expected<RecoveredPopulationCheckpoint, RecoveryFailure>
recover_population_commit(Postgres&, const FilesystemObjectStore&, RegionKey,
std::uint64_t sequence, const LeaseGrant&,
std::span<const Sha256Digest> retained_builds,
std::chrono::milliseconds timeout);
// Used by raw cellular recovery after a population -> individual profile transition.
[[nodiscard]] std::expected<void, RecoveryFailure>
verify_population_profile_transition(Postgres&, const FilesystemObjectStore&, const LeaseGrant&,
+3
View File
@@ -37,6 +37,9 @@ class Postgres {
Postgres& operator=(const Postgres&) = delete;
[[nodiscard]] static std::expected<std::unique_ptr<Postgres>, PgFailure>
connect(const PgOptions& options, std::chrono::milliseconds timeout);
// True only for a connected, idle session outside an explicit transaction.
// Read-only status inspection; no query, lock or transaction is started.
[[nodiscard]] bool transaction_idle() const noexcept;
[[nodiscard]] std::expected<PgRows, PgFailure> query(const std::string& sql,
std::span<const std::string> parameters,
std::chrono::milliseconds timeout);