Complete M7.5 durable batch outcomes and commit resolution
ADR-0063: manifest v2 (360 bytes) binds a per-tick validation trace object and a canonical decision block by SHA-256. Publication replays the trace from the committed predecessor's verified payload and requires every report and the candidate bytes, derives deaths deterministically, uploads payload and trace with verified read-back, then sends manifest and decisions to one fenced statement. RegionBatch seals at a terminal transition or 64 ticks and refuses ticks until durable confirmation. Schema v5 records the checkpoint, its decisions and outbox rows atomically; a unique index keeps one terminal outcome per actor (EVL08), triggers make commits/decisions immutable (EVL09), an exact retry of a committed ID returns the original receipt, changed bytes conflict, and read-only resolve_region_commit answers committed/absent/ conflict. Outbox pending/acknowledge give idempotent at-least-once delivery. Recovery reconciles durable deaths with restored lifecycle (and archive deaths for the lineage profile). Validated: Windows CTest 58/58; Linux GCC Debug/Release, clang-tidy and ASan/UBSan CTest 58/58 each; PostgreSQL suites Release, analysis, ASan (lost response, committed-after-timeout, terminated orphan retry, changed bytes, repeated/partial/reordered decisions, gap, outbox redelivery, history quarantine); five mutations each caught. No Docker/Gitea CI, process kill, broker or deployment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
namespace evo::persistence {
|
||||
namespace {
|
||||
constexpr std::uint64_t manifest_magic = 0x314D43524F564541ULL; // "AEVORCM1"
|
||||
constexpr std::uint32_t manifest_version = 1;
|
||||
constexpr std::uint64_t maximum = ~std::uint64_t{0};
|
||||
|
||||
template <std::size_t N> bool zero(const std::array<std::uint8_t, N>& bytes) {
|
||||
@@ -58,12 +57,23 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
m.tick_microseconds == 0 || zero(m.build) || m.payload_bytes == 0 ||
|
||||
m.payload_bytes > limit || zero(m.payload_sha256))
|
||||
return false;
|
||||
const auto& b = m.batch;
|
||||
if (m.manifest_version != 1 && m.manifest_version != 2)
|
||||
return false;
|
||||
const bool no_batch = b == BatchDigests{};
|
||||
if (m.sequence == 0)
|
||||
return zero(m.predecessor_commit) && zero(m.predecessor_digest) && m.begin_tick == 0 &&
|
||||
m.end_tick == 0 && zero(m.holder) && m.epoch == 0;
|
||||
return !zero(m.predecessor_commit) && m.predecessor_commit != m.commit &&
|
||||
!zero(m.predecessor_digest) && !zero(m.holder) && m.epoch != 0 &&
|
||||
m.end_tick > m.begin_tick && m.end_tick - m.begin_tick <= max_checkpoint_ticks;
|
||||
m.end_tick == 0 && zero(m.holder) && m.epoch == 0 && no_batch;
|
||||
const bool link = !zero(m.predecessor_commit) && m.predecessor_commit != m.commit &&
|
||||
!zero(m.predecessor_digest) && !zero(m.holder) && m.epoch != 0 &&
|
||||
m.end_tick > m.begin_tick &&
|
||||
m.end_tick - m.begin_tick <= max_checkpoint_ticks;
|
||||
if (m.manifest_version == 1)
|
||||
return link && no_batch;
|
||||
// v2: the trace has exactly one step per tick; decisions are bounded.
|
||||
return link && b.trace_bytes == trace_bytes_for(m.end_tick - m.begin_tick) &&
|
||||
!zero(b.trace_sha256) && b.decision_count <= max_batch_decisions &&
|
||||
(b.decision_count == 0) == zero(b.decisions_sha256);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -78,13 +88,13 @@ bool supported(const CheckpointManifest& m) noexcept {
|
||||
|
||||
std::expected<std::vector<std::uint8_t>, CheckpointError>
|
||||
encode_manifest(const CheckpointManifest& m) {
|
||||
if (!structural(m))
|
||||
if (!structural(m) || m.manifest_version != 2)
|
||||
return std::unexpected{CheckpointError::format};
|
||||
std::vector<std::uint8_t> out;
|
||||
out.reserve(checkpoint_manifest_bytes);
|
||||
Writer w{out};
|
||||
w.u(manifest_magic, 8);
|
||||
w.u(manifest_version, 4);
|
||||
w.u(m.manifest_version, 4);
|
||||
w.u(static_cast<std::uint8_t>(m.profile), 4);
|
||||
w.u(m.key.world, 8);
|
||||
w.u(m.key.region, 8);
|
||||
@@ -108,19 +118,28 @@ encode_manifest(const CheckpointManifest& m) {
|
||||
w.u(static_cast<std::uint8_t>(m.durability), 4);
|
||||
w.u(m.payload_bytes, 8);
|
||||
w.bytes(m.payload_sha256);
|
||||
w.u(m.batch.trace_bytes, 8);
|
||||
w.bytes(m.batch.trace_sha256);
|
||||
w.u(m.batch.decision_count, 4);
|
||||
w.u(0, 4);
|
||||
w.bytes(m.batch.decisions_sha256);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::expected<CheckpointManifest, CheckpointError>
|
||||
decode_manifest(std::span<const std::uint8_t> bytes) {
|
||||
if (bytes.size() != checkpoint_manifest_bytes)
|
||||
if (bytes.size() < 12)
|
||||
return std::unexpected{CheckpointError::format};
|
||||
Reader r{bytes};
|
||||
if (r.u(8) != manifest_magic)
|
||||
return std::unexpected{CheckpointError::format};
|
||||
if (r.u(4) != manifest_version)
|
||||
return std::unexpected{CheckpointError::unsupported};
|
||||
CheckpointManifest m;
|
||||
m.manifest_version = static_cast<std::uint32_t>(r.u(4));
|
||||
if (m.manifest_version != 1 && m.manifest_version != 2)
|
||||
return std::unexpected{CheckpointError::unsupported};
|
||||
if (bytes.size() !=
|
||||
(m.manifest_version == 1 ? checkpoint_manifest_v1_bytes : checkpoint_manifest_bytes))
|
||||
return std::unexpected{CheckpointError::format};
|
||||
const auto profile = r.u(4);
|
||||
m.profile =
|
||||
profile <= 0xFFU ? static_cast<CheckpointProfile>(profile) : CheckpointProfile::unknown;
|
||||
@@ -148,6 +167,14 @@ decode_manifest(std::span<const std::uint8_t> bytes) {
|
||||
durability <= 0xFFU ? static_cast<DurabilityPolicy>(durability) : DurabilityPolicy::unknown;
|
||||
m.payload_bytes = r.u(8);
|
||||
m.payload_sha256 = r.bytes<32>();
|
||||
if (m.manifest_version == 2) {
|
||||
m.batch.trace_bytes = r.u(8);
|
||||
m.batch.trace_sha256 = r.bytes<32>();
|
||||
m.batch.decision_count = static_cast<std::uint32_t>(r.u(4));
|
||||
if (r.u(4) != 0)
|
||||
return std::unexpected{CheckpointError::format}; // Reserved.
|
||||
m.batch.decisions_sha256 = r.bytes<32>();
|
||||
}
|
||||
if (!structural(m))
|
||||
return std::unexpected{CheckpointError::format};
|
||||
return m;
|
||||
@@ -176,7 +203,8 @@ genesis_manifest(RegionKey key, std::uint64_t frame, Uuid commit, std::uint64_t
|
||||
std::expected<CheckpointManifest, CheckpointError>
|
||||
successor_manifest(const CheckpointManifest& p, const Sha256Digest& predecessor_digest, Uuid commit,
|
||||
const LeaseGrant& lease, std::uint64_t end_tick, const Sha256Digest& build,
|
||||
std::uint64_t payload_bytes, const Sha256Digest& payload_sha256) {
|
||||
std::uint64_t payload_bytes, const Sha256Digest& payload_sha256,
|
||||
const BatchDigests& batch) {
|
||||
// This build writes only its own versions; a change requires a migration (M7.9).
|
||||
if (!supported(p))
|
||||
return std::unexpected{CheckpointError::unsupported};
|
||||
@@ -184,6 +212,8 @@ successor_manifest(const CheckpointManifest& p, const Sha256Digest& predecessor_
|
||||
end_tick <= p.end_tick || end_tick - p.end_tick > max_checkpoint_ticks)
|
||||
return std::unexpected{CheckpointError::chain};
|
||||
CheckpointManifest m = p;
|
||||
m.manifest_version = 2;
|
||||
m.batch = batch;
|
||||
m.commit = commit;
|
||||
m.sequence = p.sequence + 1;
|
||||
m.predecessor_commit = p.commit;
|
||||
|
||||
Reference in New Issue
Block a user