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:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "evo/persistence/postgres.hpp"
|
||||
#include "evo/persistence/region_batch.hpp"
|
||||
#include "evo/persistence/region_lease.hpp"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
@@ -18,7 +19,9 @@ enum class LeaseStoreError : std::uint8_t {
|
||||
not_provisioned, // No genesis; runtime can never create one.
|
||||
exhausted, // Epoch or commit sequence would wrap: fail closed.
|
||||
unsupported, // Profile/version/build not admitted, or rules/quantum changed.
|
||||
commit_conflict, // Commit ID already used by another manifest (resolve at M7.5).
|
||||
commit_conflict, // Commit ID already holds other bytes: never retry it.
|
||||
outcome_final, // A decision repeats an already committed permanent outcome.
|
||||
immutable, // Attempted rewrite of committed history (owner paths only).
|
||||
invalid, // Rejected arguments; nothing changed.
|
||||
store, // Other SQL/configuration failure; nothing committed.
|
||||
unknown, // May have executed; reconnect and reconcile before reuse.
|
||||
@@ -47,11 +50,45 @@ release_region_lease(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
load_region_head(Postgres& db, RegionKey key, std::chrono::milliseconds timeout);
|
||||
[[nodiscard]] std::expected<CommittedCheckpoint, LeaseStoreFailure>
|
||||
load_region_checkpoint(Postgres& db, RegionKey key, std::chrono::milliseconds timeout);
|
||||
// Canonical manifest v1 bytes; the database parses identity, lease and chain from
|
||||
// them, locks the lease then the head and requires the exact committed predecessor.
|
||||
// The payload must already be verified in the object store. head_mismatch after
|
||||
// unknown: load the head and compare its commit ID (full resolution is M7.5).
|
||||
// Canonical manifest v2 bytes plus the decision block they digest (ADR-0063). The
|
||||
// database parses identity, lease and chain, locks the lease then the head, requires
|
||||
// the exact committed predecessor and records decisions and outbox rows in the same
|
||||
// statement. An exact retry of a committed ID returns its original receipt; changed
|
||||
// bytes are commit_conflict. The payload and trace must already be verified objects.
|
||||
[[nodiscard]] std::expected<RegionHead, LeaseStoreFailure>
|
||||
publish_region_checkpoint(Postgres& db, std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions,
|
||||
std::chrono::milliseconds timeout);
|
||||
|
||||
enum class Resolution : std::uint8_t {
|
||||
committed, // Exact bytes are durable; receipt holds the head. Grants no authority.
|
||||
absent, // Not committed now; proves nothing about a request still in flight.
|
||||
conflict, // The ID holds other bytes or belongs to another region: fail closed.
|
||||
};
|
||||
struct ResolvedCommit {
|
||||
Resolution status{};
|
||||
RegionHead receipt{}; // Only for committed.
|
||||
};
|
||||
[[nodiscard]] std::expected<ResolvedCommit, LeaseStoreFailure>
|
||||
resolve_region_commit(Postgres& db, RegionKey key, const Uuid& commit,
|
||||
std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions, std::chrono::milliseconds timeout);
|
||||
|
||||
struct CommittedDecision {
|
||||
std::uint64_t commit_sequence{};
|
||||
BatchDecision decision{};
|
||||
friend bool operator==(const CommittedDecision&, const CommittedDecision&) = default;
|
||||
};
|
||||
// Every committed permanent outcome of the region, ordered by (tick, actor).
|
||||
[[nodiscard]] std::expected<std::vector<CommittedDecision>, LeaseStoreFailure>
|
||||
load_region_decisions(Postgres& db, RegionKey key, std::chrono::milliseconds timeout);
|
||||
// Undelivered outbox rows (1..64), ordered by (commit, tick, actor). Delivery is
|
||||
// at-least-once; consumers deduplicate by (region, outcome, actor, tick).
|
||||
[[nodiscard]] std::expected<std::vector<CommittedDecision>, LeaseStoreFailure>
|
||||
pending_region_outbox(Postgres& db, RegionKey key, std::uint32_t limit,
|
||||
std::chrono::milliseconds timeout);
|
||||
// True on first acknowledgement, false when already delivered.
|
||||
[[nodiscard]] std::expected<bool, LeaseStoreFailure>
|
||||
acknowledge_region_outbox(Postgres& db, RegionKey key, const BatchDecision& decision,
|
||||
std::chrono::milliseconds timeout);
|
||||
} // namespace evo::persistence
|
||||
|
||||
Reference in New Issue
Block a user