Complete M7.9a region clones and retained-history audit

Clone a verified committed head into an isolated world and database
(ADR-0067): world re-identification with a proven byte round trip, a
schema v7 clone genesis naming the source commit and digest with digested
inherited outcomes, a read-only source session, an owner-only atomic
target transaction and the evo-world-clone tool. audit_region_history
re-verifies every retained link. Real-process tests cover trajectory
equality after the cut, source isolation, killed clones and retention.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-09-29 06:47:45 -04:00
co-authored by Claude Opus 5.5
parent 7aec68db8e
commit 703f67834f
28 changed files with 2206 additions and 266 deletions
+11 -1
View File
@@ -52,7 +52,9 @@ struct CheckpointManifest {
std::uint64_t frame{};
Uuid commit{};
std::uint64_t sequence{};
Uuid predecessor_commit{}; // Zero only at genesis.
// Zero at provisioned genesis. At a clone genesis (sequence 0, ADR-0067) they
// name the source commit and the SHA-256 of its manifest bytes.
Uuid predecessor_commit{};
Sha256Digest predecessor_digest{}; // SHA-256 of the predecessor manifest bytes.
std::uint64_t begin_tick{}, end_tick{};
Uuid holder{}; // Zero only at genesis (provisioning, not a lease).
@@ -103,6 +105,14 @@ genesis_manifest(RegionKey key, std::uint64_t frame, Uuid commit, std::uint64_t
const Sha256Digest& build, std::uint64_t payload_bytes,
const Sha256Digest& payload_sha256,
CheckpointProfile profile = CheckpointProfile::environmental_v1);
// Clone genesis (ADR-0067): sequence 0 of `target` in another world, at the source's
// end tick, whose predecessor fields name the source commit and manifest digest.
// Profile, versions, quantum, frame and build are inherited; `inherited` digests the
// source's permanent outcomes (no trace). The payload must be re-identified bytes.
[[nodiscard]] std::expected<CheckpointManifest, CheckpointError>
clone_manifest(const CheckpointManifest& source, const Sha256Digest& source_digest,
RegionKey target, Uuid commit, std::uint64_t payload_bytes,
const Sha256Digest& payload_sha256, const BatchDigests& inherited);
// Next link from the committed predecessor and its manifest digest under a lease.
// Profile, versions and quantum are inherited: a region never changes them.
[[nodiscard]] std::expected<CheckpointManifest, CheckpointError>
+104
View File
@@ -0,0 +1,104 @@
#pragma once
#include "evo/persistence/checkpoint_store.hpp"
#include <chrono>
#include <cstdint>
#include <expected>
#include <functional>
#include <span>
// M7.9 region clones and history audit (ADR-0067). Linux only.
//
// A clone is a consistent cut: the verified committed head of a source region,
// re-identified into another world and provisioned there as a clone genesis whose
// manifest names the source commit and digest. The source session is made
// read-only before anything is read; nothing is ever written to the source. Order:
// full source recovery (payload, tail, outcomes) -> re-identify and prove the byte
// round trip -> verified target upload -> one owner transaction in the target
// database. A failure before that transaction leaves at most target orphans; the
// target is never partially provisioned. Rules, formats, quantum and build are
// inherited unchanged: a clone never converts versions.
namespace evo::persistence {
enum class CloneError : std::uint8_t {
identity, // Target is in the source world or has a zero ID; nothing read.
session, // The source session could not be made read-only; nothing read.
source, // Source head failed full recovery verification (see recovery).
candidate, // Re-identified payload, outcomes or manifest failed validation.
upload, // Target object write failed; nothing provisioned.
verify, // Target object read-back differs; nothing provisioned.
rejected, // Target database refused (see store); uploads are orphans.
unknown, // Target outcome unknown: load the target head before retrying.
receipt, // Target head disagrees with the clone manifest: fail closed.
};
struct CloneFailure {
CloneError kind{};
RecoveryFailure recovery{}; // Meaningful for source.
LeaseStoreFailure store{}; // Meaningful for session/rejected/unknown.
ObjectError object{}; // Meaningful for upload/verify.
};
struct CloneOrigin {
RegionKey source{};
std::uint64_t sequence{}, tick{};
Uuid commit{};
Sha256Digest digest{}; // SHA-256 of the source manifest bytes.
friend bool operator==(const CloneOrigin&, const CloneOrigin&) = default;
};
struct ClonedRegion {
CommittedCheckpoint genesis;
CloneOrigin origin;
std::size_t inherited_outcomes{};
};
// Test/fault-injection seam, called after the verified target upload and
// immediately before the target transaction. Production callers pass nothing.
struct CloneHooks {
std::function<void()> before_transaction;
};
// `source` is any connection that may read the region (it is switched to read-only
// transactions for the rest of its life); `target_owner` must be a different
// connection with the target database's owner role. The target store is opened for
// target_key. Both profiles are supported; the profile is read from the source head.
[[nodiscard]] std::expected<ClonedRegion, CloneFailure>
clone_region(Postgres& source, const FilesystemObjectStore& source_objects, RegionKey source_key,
Postgres& target_owner, const FilesystemObjectStore& target_objects,
RegionKey target_key, Uuid commit, std::span<const Sha256Digest> retained_builds,
std::size_t restore_budget, std::chrono::milliseconds timeout,
const CloneHooks& hooks = {});
enum class AuditError : std::uint8_t {
store, // Database unavailable/failed (see store).
not_provisioned, // No such region.
bounds, // More commits than the caller allowed; nothing concluded.
manifest, // A link's bytes disagree with its digest or position.
chain, // Links do not form one contiguous chain from genesis.
unsupported, // Profile/versions/build outside the retained allowlist.
missing_payload, // A referenced payload object is gone.
corrupt_payload, // A payload object has the wrong length or digest.
payload, // Verified bytes fail full state validation.
tail, // A link's trace is missing, corrupt or does not reproduce it.
history, // Durable outcomes disagree with a link or the head state.
};
struct AuditFailure {
AuditError kind{};
std::uint64_t sequence{}; // The first link that failed.
LeaseStoreFailure store{};
};
struct HistoryAudit {
std::uint64_t commits{}, end_tick{}, outcomes{};
CheckpointProfile profile{};
// A clone genesis names its origin commit and manifest digest; the source
// world/region is recorded only in the target database (region_origins).
bool clone{};
Uuid origin_commit{};
Sha256Digest origin_digest{};
};
// Retention evidence: verifies every committed link from genesis to the head, as
// recovery verifies the head alone. Each manifest matches its digest and chain
// position, each payload is present and restores, each trace replays its
// predecessor's payload to exactly its own, and each link's durable outcomes are
// exactly those derived; the head state agrees with all of them. At most
// `max_commits` links are examined. Read-only; no lease is needed.
[[nodiscard]] std::expected<HistoryAudit, AuditFailure>
audit_region_history(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
std::span<const Sha256Digest> retained_builds, std::size_t restore_budget,
std::uint64_t max_commits, std::chrono::milliseconds timeout);
} // namespace evo::persistence
@@ -68,6 +68,13 @@ class EnvironmentalCommunity {
[[nodiscard]] std::uint64_t tick_microseconds() const noexcept {
return config_.tick_microseconds;
}
[[nodiscard]] std::uint64_t world() const noexcept {
return config_.world;
}
// Clone support (ADR-0067): records the region under another nonzero world ID,
// keeping its frame. Rules, content and trajectory do not depend on the world ID
// (ADR-0044), so rebinding back yields byte-identical snapshots. False for 0.
[[nodiscard]] bool rebind_world(std::uint64_t world) noexcept;
private:
struct State {
+5
View File
@@ -66,6 +66,11 @@ class LineageRegion {
[[nodiscard]] const LineageBinding& binding() const noexcept {
return binding_;
}
// Clone support (ADR-0067): only the nested community records a world; the
// archive and binding are identity-free. False for world 0 or a poisoned region.
[[nodiscard]] bool rebind_world(std::uint64_t world) noexcept {
return !poisoned_ && community_->rebind_world(world);
}
private:
LineageRegion(std::unique_ptr<EnvironmentalCommunity> community,
+5
View File
@@ -95,6 +95,11 @@ class EnvironmentalTransfers {
private:
friend class evo::processes::EnvironmentalCommunity;
// Clone support (ADR-0067): the field store and, through it, terrain snapshots
// carry this identity; no other resource state depends on it.
void rebind(WorldIdentity identity) noexcept {
fields_->identity_ = identity;
}
[[nodiscard]] bool process_checkpoint(std::uint64_t tick,
const std::array<std::uint64_t, 10>& environment,
const std::array<std::uint64_t, 10>& producer,