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:
@@ -33,9 +33,14 @@ CheckpointManifest genesis(std::uint64_t payload_bytes = 100) {
|
||||
CHECK(g);
|
||||
return *g;
|
||||
}
|
||||
// Synthetic batch evidence of the right size for `ticks` (content is not checked here).
|
||||
BatchDigests batch_for(std::uint64_t ticks, std::uint32_t decisions = 0) {
|
||||
return {trace_bytes_for(ticks), filled<32>(0x7C), decisions,
|
||||
decisions == 0 ? Sha256Digest{} : filled<32>(0x7D)};
|
||||
}
|
||||
CheckpointManifest next(std::uint64_t end_tick = 16) {
|
||||
auto n = successor_manifest(genesis(), filled<32>(0xD0), filled<16>(0x02), lease(), end_tick,
|
||||
build, 200, filled<32>(0xA1));
|
||||
build, 200, filled<32>(0xA1), batch_for(end_tick, 1));
|
||||
CHECK(n);
|
||||
return *n;
|
||||
}
|
||||
@@ -52,7 +57,7 @@ void layout_and_round_trip() {
|
||||
CHECK(bytes && bytes->size() == checkpoint_manifest_bytes);
|
||||
// Golden offsets from schemas/region-commit.md.
|
||||
CHECK(std::string_view(reinterpret_cast<const char*>(bytes->data()), 8) == "AEVORCM1");
|
||||
CHECK(at(*bytes, 8, 4) == 1 && at(*bytes, 12, 4) == 1);
|
||||
CHECK(at(*bytes, 8, 4) == 2 && at(*bytes, 12, 4) == 1);
|
||||
CHECK(at(*bytes, 16, 8) == 7 && at(*bytes, 24, 8) == 3 && at(*bytes, 32, 8) == 9);
|
||||
CHECK((*bytes)[40] == 0x02 && at(*bytes, 56, 8) == 1 && (*bytes)[64] == 0x01);
|
||||
CHECK((*bytes)[80] == 0xD0 && at(*bytes, 112, 8) == 0 && at(*bytes, 120, 8) == 16);
|
||||
@@ -60,6 +65,9 @@ void layout_and_round_trip() {
|
||||
CHECK(at(*bytes, 160, 4) == 2 && at(*bytes, 164, 4) == 2 && at(*bytes, 192, 4) == 1);
|
||||
CHECK((*bytes)[196] == 0xB1 && at(*bytes, 228, 4) == 0 && at(*bytes, 232, 4) == 0);
|
||||
CHECK(at(*bytes, 236, 4) == 1 && at(*bytes, 240, 8) == 200 && (*bytes)[248] == 0xA1);
|
||||
CHECK(at(*bytes, 8, 4) == 2 && at(*bytes, 280, 8) == trace_bytes_for(16));
|
||||
CHECK((*bytes)[288] == 0x7C && at(*bytes, 320, 4) == 1 && at(*bytes, 324, 4) == 0);
|
||||
CHECK((*bytes)[328] == 0x7D);
|
||||
auto decoded = decode_manifest(*bytes);
|
||||
CHECK(decoded && *decoded == m && supported(*decoded));
|
||||
auto g = encode_manifest(genesis());
|
||||
@@ -68,7 +76,20 @@ void layout_and_round_trip() {
|
||||
|
||||
void malformed_and_unsupported() {
|
||||
auto bytes = *encode_manifest(next());
|
||||
CHECK(decode_manifest(std::span{bytes}.first(279)).error() == CheckpointError::format);
|
||||
CHECK(decode_manifest(std::span{bytes}.first(359)).error() == CheckpointError::format);
|
||||
// Version 1 (M7.4 commits) still decodes with no batch evidence; v2 is never
|
||||
// written as v1 and v1 bytes cannot carry batch fields.
|
||||
std::vector<std::uint8_t> v1(bytes.begin(), bytes.begin() + 280);
|
||||
v1[8] = 1;
|
||||
auto old = decode_manifest(v1);
|
||||
CHECK(old && old->manifest_version == 1 && old->batch == BatchDigests{});
|
||||
CHECK(!encode_manifest(*old));
|
||||
auto stretched = bytes;
|
||||
stretched[8] = 1;
|
||||
CHECK(decode_manifest(stretched).error() == CheckpointError::format);
|
||||
auto reserved = bytes;
|
||||
reserved[324] = 1;
|
||||
CHECK(decode_manifest(reserved).error() == CheckpointError::format);
|
||||
auto grown = bytes;
|
||||
grown.push_back(0);
|
||||
CHECK(decode_manifest(grown).error() == CheckpointError::format);
|
||||
@@ -76,7 +97,7 @@ void malformed_and_unsupported() {
|
||||
magic[0] ^= 1U;
|
||||
CHECK(decode_manifest(magic).error() == CheckpointError::format);
|
||||
auto version = bytes;
|
||||
version[8] = 2;
|
||||
version[8] = 3;
|
||||
CHECK(decode_manifest(version).error() == CheckpointError::unsupported);
|
||||
// Structurally invalid: zero world, 65-tick batch, oversized payload, zero digest.
|
||||
for (const auto& [offset, value] :
|
||||
@@ -113,24 +134,38 @@ void successor_chain() {
|
||||
const auto g = genesis();
|
||||
const auto d = filled<32>(0xD0);
|
||||
const auto payload = filled<32>(0xA1);
|
||||
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 0, build, 1, payload).error() ==
|
||||
CheckpointError::chain);
|
||||
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 65, build, 1, payload).error() ==
|
||||
CheckpointError::chain);
|
||||
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 0, build, 1, payload, batch_for(1))
|
||||
.error() == CheckpointError::chain);
|
||||
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 65, build, 1, payload, batch_for(1))
|
||||
.error() == CheckpointError::chain);
|
||||
auto foreign = lease();
|
||||
foreign.frame = 8;
|
||||
CHECK(successor_manifest(g, d, filled<16>(2), foreign, 1, build, 1, payload).error() ==
|
||||
CheckpointError::chain);
|
||||
CHECK(successor_manifest(g, d, g.commit, lease(), 1, build, 1, payload).error() ==
|
||||
CHECK(successor_manifest(g, d, filled<16>(2), foreign, 1, build, 1, payload, batch_for(1))
|
||||
.error() == CheckpointError::chain);
|
||||
CHECK(successor_manifest(g, d, g.commit, lease(), 1, build, 1, payload, batch_for(1)).error() ==
|
||||
CheckpointError::format); // Reused commit identity.
|
||||
auto old = g;
|
||||
old.versions.rules = 1;
|
||||
CHECK(successor_manifest(old, d, filled<16>(2), lease(), 1, build, 1, payload).error() ==
|
||||
CheckpointError::unsupported);
|
||||
CHECK(successor_manifest(old, d, filled<16>(2), lease(), 1, build, 1, payload, batch_for(1))
|
||||
.error() == CheckpointError::unsupported);
|
||||
auto last = next();
|
||||
last.sequence = ~std::uint64_t{0};
|
||||
CHECK(successor_manifest(last, d, filled<16>(3), lease(), 17, build, 1, payload).error() ==
|
||||
CheckpointError::chain);
|
||||
CHECK(successor_manifest(last, d, filled<16>(3), lease(), 17, build, 1, payload, batch_for(1))
|
||||
.error() == CheckpointError::chain);
|
||||
// Batch evidence must match the tick range: one trace step per tick.
|
||||
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 2, build, 1, payload, batch_for(1))
|
||||
.error() == CheckpointError::format);
|
||||
auto untraced = batch_for(1);
|
||||
untraced.trace_sha256 = {};
|
||||
CHECK(
|
||||
successor_manifest(g, d, filled<16>(2), lease(), 1, build, 1, payload, untraced).error() ==
|
||||
CheckpointError::format);
|
||||
auto unsigned_decisions = batch_for(1, 1);
|
||||
unsigned_decisions.decisions_sha256 = {};
|
||||
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 1, build, 1, payload, unsigned_decisions)
|
||||
.error() == CheckpointError::format);
|
||||
CHECK(successor_manifest(g, d, filled<16>(2), lease(), 1, build, 1, payload, batch_for(1, 9))
|
||||
.error() == CheckpointError::format);
|
||||
const auto n = next(64);
|
||||
CHECK(n.sequence == 1 && n.predecessor_commit == g.commit && n.predecessor_digest == d);
|
||||
CHECK(n.begin_tick == 0 && n.holder == lease().holder && n.epoch == 4 && n.frame == 9);
|
||||
@@ -151,7 +186,7 @@ void payload_validation_and_restored_trajectory() {
|
||||
auto lease_at_frame = lease();
|
||||
lease_at_frame.frame = evo::test::region_identity.frame;
|
||||
auto m = successor_manifest(*g, filled<32>(0xD0), filled<16>(2), lease_at_frame, 16, build,
|
||||
payload->size(), filled<32>(0xA1));
|
||||
payload->size(), filled<32>(0xA1), batch_for(16));
|
||||
CHECK(m);
|
||||
auto restored = restore_environmental_payload(*payload, *m, 8000000);
|
||||
CHECK(restored);
|
||||
@@ -170,7 +205,12 @@ void payload_validation_and_restored_trajectory() {
|
||||
auto r = restore_environmental_payload(bytes, manifest, 8000000);
|
||||
return !r && r.error() == error;
|
||||
};
|
||||
CHECK(refused([](auto&, auto& x) { x.end_tick = 15; }, CheckpointError::payload));
|
||||
CHECK(refused(
|
||||
[](auto&, auto& x) {
|
||||
x.end_tick = 15;
|
||||
x.batch = batch_for(15);
|
||||
},
|
||||
CheckpointError::payload));
|
||||
CHECK(refused([](auto&, auto& x) { x.key.world = 8; }, CheckpointError::payload));
|
||||
CHECK(refused([](auto&, auto& x) { x.frame = 10; }, CheckpointError::payload));
|
||||
CHECK(refused([](auto&, auto& x) { x.tick_microseconds = 25000; }, CheckpointError::payload));
|
||||
@@ -227,13 +267,14 @@ void lineage_profile() {
|
||||
auto lease_at_frame = lease();
|
||||
lease_at_frame.frame = evo::test::region_identity.frame;
|
||||
auto m = successor_manifest(*g, filled<32>(0xD0), filled<16>(2), lease_at_frame, 24, build,
|
||||
payload->size(), filled<32>(0xA1));
|
||||
payload->size(), filled<32>(0xA1), batch_for(24));
|
||||
CHECK(m && m->profile == CheckpointProfile::environmental_lineage_v1 &&
|
||||
m->history_profile == 1);
|
||||
auto later = restore_lineage_payload(*payload, *m, 8000000);
|
||||
CHECK(later && !(*later)->archive().organism(11)->alive);
|
||||
auto wrong_tick = *m;
|
||||
wrong_tick.end_tick = 23;
|
||||
wrong_tick.batch = batch_for(23);
|
||||
CHECK(restore_lineage_payload(*payload, wrong_tick, 8000000).error() ==
|
||||
CheckpointError::payload);
|
||||
auto nested = *payload;
|
||||
|
||||
Reference in New Issue
Block a user