M12.7: reconcile pending migration evidence in census snapshots
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m26s
Foundation / checks (network) (push) Successful in 21m1s
Foundation / checks (client) (push) Successful in 22m9s
Foundation / checks (tsan) (push) Successful in 24m36s
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 33m38s
Foundation / checks (checks) (push) Canceled after 33m49s

This commit is contained in:
dingo
2026-10-18 21:14:53 -04:00
parent 709dfb9557
commit 27ec5729bf
23 changed files with 592 additions and 23 deletions
+48 -1
View File
@@ -1,5 +1,7 @@
#include "evo/persistence/cellular_census_snapshot.hpp"
#include "cellular_migration_observation_detail.hpp"
#include <algorithm>
#include <array>
#include <charconv>
#include <optional>
@@ -19,10 +21,14 @@ auto history_failure(std::uint64_t region, CellularHistoryFailure error) {
auto coverage_failure(CellularCoverageError kind, PgFailure cause = {}) {
return std::unexpected(Failure{Error::coverage, 0, {}, {}, {}, {kind, cause}});
}
auto migration_failure(RecoveryFailure cause, std::uint64_t region = 0) {
return std::unexpected(Failure{Error::migration, region, {}, {}, {}, {}, cause});
}
struct Captured {
std::vector<RegisteredCellularRegion> catalog;
std::vector<CommittedCheckpoint> cuts;
Uuid history_domain{};
std::vector<detail::CapturedCellularMigration> migrations;
};
std::expected<Uuid, Failure> history_domain(Postgres& db, std::chrono::milliseconds timeout) {
const auto rows = db.query("SELECT pg_catalog.encode(pg_catalog.uuid_send("
@@ -120,6 +126,10 @@ std::expected<Captured, Failure> capture(Postgres& db, std::uint64_t world,
return coverage_failure(CellularCoverageError::frame);
}
captured.catalog = std::move(*required);
auto pending = detail::capture_cellular_migrations(db, world, timeout);
if (!pending)
return migration_failure(pending.error());
captured.migrations = std::move(*pending);
}
captured.cuts.reserve(requests.size());
for (std::size_t i = 0; i < requests.size(); ++i) {
@@ -163,6 +173,42 @@ load_snapshot(Postgres& db, std::uint64_t world,
auto cuts = capture(db, world, requests, timeout, hooks, registered);
if (!cuts)
return std::unexpected(cuts.error());
std::vector<CellularMigrationObservation> migrations;
for (const auto& pending : cuts->migrations) {
const auto source_manifest = decode_manifest(pending.source);
const auto destination_manifest = decode_manifest(pending.destination);
if (!source_manifest || !destination_manifest)
return migration_failure({RecoveryError::manifest});
if (std::ranges::find(builds, source_manifest->build) == builds.end() ||
std::ranges::find(builds, destination_manifest->build) == builds.end())
return migration_failure({RecoveryError::unsupported});
const auto trace = server::decode_migration_trace(pending.trace);
if (!trace || trace->world != world ||
(!migrations.empty() &&
trace->request.request <= migrations.back().trace.request.request))
return migration_failure({RecoveryError::history});
const auto endpoint = [&](std::uint64_t region) {
return std::ranges::lower_bound(requests, region, {},
&CellularCensusRegionRequest::region);
};
const auto s = endpoint(trace->request.source.region);
const auto d = endpoint(trace->request.destination.region);
if (s == requests.end() || d == requests.end() ||
s->region != trace->request.source.region ||
d->region != trace->request.destination.region || s->lease.frame != trace->frame ||
d->lease.frame != trace->frame)
return migration_failure({RecoveryError::history});
const auto si = static_cast<std::size_t>(s - requests.begin());
const auto di = static_cast<std::size_t>(d - requests.begin());
if (cuts->cuts[si].manifest != pending.source ||
(pending.ghost && cuts->cuts[di].manifest != pending.destination))
return migration_failure({RecoveryError::history}, s->region);
auto verified =
detail::verify_captured_cellular_migration(pending, *s->objects, *d->objects);
if (!verified)
return migration_failure(verified.error(), s->region);
migrations.push_back(std::move(*verified));
}
std::vector<server::CellularCensus> observations;
observations.reserve(requests.size());
for (std::size_t i = 0; i < requests.size(); ++i) {
@@ -187,7 +233,8 @@ load_snapshot(Postgres& db, std::uint64_t world,
return std::unexpected(Failure{Error::census, 0, {}, {}, census.error()});
return RegisteredCellularCensusSnapshot{std::move(cuts->catalog),
{std::move(cuts->cuts), std::move(*census)},
cuts->history_domain};
cuts->history_domain,
std::move(migrations)};
}
} // namespace
@@ -0,0 +1,20 @@
#pragma once
#include "evo/persistence/cellular_migration_store.hpp"
#include <optional>
namespace evo::persistence::detail {
struct CapturedCellularMigration {
std::vector<std::uint8_t> trace, source, destination;
std::optional<VerifiedObject> ghost;
};
// Internal census adapter: caller owns the read-only metadata snapshot.
[[nodiscard]] std::expected<std::vector<CapturedCellularMigration>, RecoveryFailure>
capture_cellular_migrations(Postgres&, std::uint64_t world, std::chrono::milliseconds);
// Immutable historical evidence only; no live authority/activation or SQL access.
[[nodiscard]] std::expected<CellularMigrationObservation, RecoveryFailure>
verify_captured_cellular_migration(const CapturedCellularMigration&,
const FilesystemObjectStore& source,
const FilesystemObjectStore& destination);
} // namespace evo::persistence::detail
@@ -1,5 +1,7 @@
#include "evo/persistence/cellular_migration_store.hpp"
#include "cellular_migration_observation_detail.hpp"
#include "evo/persistence/sha256.hpp"
#include "evo/server/lifecycle/cellular_census_set.hpp"
#include <algorithm>
#include <charconv>
@@ -441,6 +443,74 @@ load_cellular_migration_stage(Postgres& db, const FilesystemObjectStore& objects
return fail(RecoveryError::history);
return result;
}
namespace detail {
std::expected<std::vector<CapturedCellularMigration>, RecoveryFailure>
capture_cellular_migrations(Postgres& db, std::uint64_t world, milliseconds timeout) {
const std::array<std::string, 1> args{std::to_string(world)};
const auto rows =
db.query("SELECT encode(trace,'hex'),encode(source_manifest,'hex'),"
"encode(destination_manifest,'hex'),encode(ghost_sha256,'hex'),"
"pg_catalog.trunc(ghost_bytes)::text,coherent::text "
"FROM evolution.load_world_cellular_migrations_v1($1::evolution.u64)",
args, timeout);
if (!rows)
return std::unexpected(RecoveryFailure{RecoveryError::store, failure(rows.error())});
if (rows->size() > server::max_cellular_census_regions)
return std::unexpected(
RecoveryFailure{RecoveryError::store, {LeaseStoreError::invalid, {PgError::bounds}}});
std::vector<CapturedCellularMigration> result;
for (const auto& row : *rows) {
if (row.size() != 6 || row[5].value_or("") != "true")
return std::unexpected(RecoveryFailure{RecoveryError::history});
auto cut = parse({row[0], row[1], row[2], std::string{"false"}});
if (!cut)
return std::unexpected(RecoveryFailure{RecoveryError::history});
std::optional<VerifiedObject> ghost;
if (row[3] || row[4]) {
auto stage =
parse_stage({row[0], row[1], row[2], std::string{"false"}, row[3], row[4]});
if (!stage)
return std::unexpected(RecoveryFailure{RecoveryError::history});
ghost = stage->ghost;
}
result.push_back(
{std::move(cut->trace), std::move(cut->source), std::move(cut->destination), ghost});
}
return result;
}
std::expected<CellularMigrationObservation, RecoveryFailure>
verify_captured_cellular_migration(const CapturedCellularMigration& record,
const FilesystemObjectStore& source_objects,
const FilesystemObjectStore& destination_objects) {
const auto fail = [](RecoveryError kind) { return std::unexpected(RecoveryFailure{kind}); };
auto trace = server::decode_migration_trace(record.trace);
const auto s = decode_manifest(record.source), d = decode_manifest(record.destination);
const auto sd = sha256(record.source), dd = sha256(record.destination);
if (!trace || !s || !d || !sd || !dd || !cuts(*s, *d, *sd, *dd, *trace))
return fail(RecoveryError::history);
const auto source = source_objects.get({s->payload_sha256, s->payload_bytes});
const auto capsule = source_objects.get({d->payload_sha256, d->payload_bytes});
if (!source || !capsule)
return fail(RecoveryError::tail);
const auto replay = derive(*s, *d, *source, *capsule, trace->request);
if (!replay || *replay != *trace)
return fail(RecoveryError::history);
if (record.ghost) {
if (record.ghost->sha256 == Sha256Digest{} || record.ghost->bytes == 0 ||
record.ghost->bytes > max_payload_bytes(d->profile))
return fail(RecoveryError::history);
const auto sc = destination_objects.get({s->payload_sha256, s->payload_bytes});
const auto dc = destination_objects.get({d->payload_sha256, d->payload_bytes});
const auto ghost = destination_objects.get(*record.ghost);
if (!sc || !dc || !ghost)
return fail(RecoveryError::tail);
const auto candidate = ghost_candidate(*s, *d, *sc, *dc, *trace);
if (!candidate || *candidate != *ghost)
return fail(RecoveryError::history);
}
return CellularMigrationObservation{std::move(*trace), record.ghost.has_value()};
}
} // namespace detail
namespace {
constexpr auto commit_columns =
"encode(trace,'hex'),encode(source_predecessor,'hex'),"