Add M10.4b durable action records (schema v11)
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m47s
Foundation / checks (network) (push) Successful in 9m30s
Foundation / checks (client) (push) Successful in 12m19s
Foundation / checks (tsan) (push) Successful in 7m43s
Foundation / checks (checks) (push) Successful in 31m29s
Foundation / checks (postgres) (push) Successful in 36m39s
Foundation / postgres-tools (push) Successful in 19s
Foundation / image (push) Successful in 2m15s
Foundation / server-image (push) Successful in 20m37s

Each batch's actions are recorded in the same statement as its checkpoint: one
region_actions row per (world, account, action id) and the block in an append-only
table, compared on exact retries and resolution. The region host attaches actions to
the ticks they ride and reports acknowledgements and drops, keeping unknown-outcome
batches unresolved. Outcomes come from the durable record via ActionLedger, so
crashes before or after a commit, unknown publications and cross-region moves all
resolve to one answer; a repeated id keeps its first record instead of stalling a
region. ADR-0092.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-03 22:53:38 -04:00
co-authored by Claude Opus 5.5
parent e2f6208433
commit 69f3ad7cf8
32 changed files with 1289 additions and 75 deletions
@@ -0,0 +1,29 @@
#pragma once
#include "evo/network/intent_admission.hpp"
#include "evo/persistence/region_lease_store.hpp"
#include <chrono>
#include <functional>
#include <optional>
#include <utility>
// M10.4b durable action records over the region's PostgreSQL lease (ADR-0092, schema v11).
// Linux only. Owned by the region host's thread, on the host's own connection. `lease`
// returns the host's current region lease, or nothing while it holds none; every lookup
// then reports `unavailable`, as does any store failure.
namespace evo::server {
class PostgresActionLedger final : public network::ActionLedger {
public:
using LeaseSource = std::function<std::optional<persistence::LeaseGrant>()>;
PostgresActionLedger(persistence::Postgres& db, persistence::RegionKey key, LeaseSource lease,
std::chrono::milliseconds timeout = std::chrono::milliseconds{2000})
: db_{&db}, key_{key}, lease_{std::move(lease)}, timeout_{timeout} {}
[[nodiscard]] std::expected<std::optional<network::ActionOutcome>, network::ActionLedgerError>
find(const network::AccountId& account, std::uint64_t action_id) override;
private:
persistence::Postgres* db_;
persistence::RegionKey key_;
LeaseSource lease_;
std::chrono::milliseconds timeout_;
};
} // namespace evo::server
+25
View File
@@ -50,6 +50,20 @@ struct Dropped {
TickInput input{};
Unacknowledged reason{};
};
// M10.4b (ADR-0092): an action is durable with the batch that simulated its tick.
struct ActionAck {
persistence::ActionRecord record{}; // `tick` is the tick it rode.
std::uint64_t commit_sequence{};
friend bool operator==(const ActionAck&, const ActionAck&) = default;
};
// `final`: certainly never committed. Otherwise its batch's publication outcome was unknown
// when authority was lost; the durable record decides (find_region_action) once a later
// authority has recovered.
struct DroppedAction {
persistence::ActionRecord record{};
bool final{};
Unacknowledged reason{};
};
// Commit boundaries for fault injection (M7.7 kill tests).
enum class CrashPoint : std::uint8_t {
@@ -68,6 +82,7 @@ struct HostConfig {
std::chrono::milliseconds flush_interval{1000}; // Commit a non-empty batch this often.
std::size_t max_queued_inputs{64};
std::size_t max_queued_bytes{65536};
std::size_t max_queued_actions{256}; // Queued plus riding the open batch.
std::uint32_t max_catch_up_ticks{8}; // Per step; debt is never skipped.
persistence::Sha256Digest build{};
std::vector<persistence::Sha256Digest> retained_builds;
@@ -95,6 +110,10 @@ template <typename State> class RegionHost {
// Provisional admission only; nothing is final until a FinalAck.
[[nodiscard]] std::expected<void, AdmissionError> submit(const TickInput& input);
// An action rides the first simulated tick >= record.tick and is committed with that
// batch, in the same statement (schema v11). Final only through an ActionAck.
[[nodiscard]] std::expected<void, AdmissionError>
submit_action(const persistence::ActionRecord& record);
// Advances the state machine once: lease upkeep, recovery, resolution, commits
// and up to max_catch_up_ticks ticks. Blocks at most for bounded I/O.
const HostStatus& step(SchedulerTime now);
@@ -104,6 +123,8 @@ template <typename State> class RegionHost {
[[nodiscard]] std::vector<FinalAck> take_acks();
[[nodiscard]] std::vector<FinalOutcome> take_outcomes();
[[nodiscard]] std::vector<Dropped> take_dropped();
[[nodiscard]] std::vector<ActionAck> take_action_acks();
[[nodiscard]] std::vector<DroppedAction> take_dropped_actions();
[[nodiscard]] const HostStatus& status() const noexcept {
return status_;
}
@@ -148,6 +169,10 @@ template <typename State> class RegionHost {
std::vector<FinalAck> acks_;
std::vector<FinalOutcome> outcomes_;
std::vector<Dropped> dropped_;
std::deque<persistence::ActionRecord> action_queue_;
std::vector<persistence::ActionRecord> batch_actions_; // Riding the open batch.
std::vector<ActionAck> action_acks_;
std::vector<DroppedAction> dropped_actions_;
SchedulerTime origin_{}, batch_started_{};
// Store failures back off: a failed commit is retried after retry_delay_, which
// doubles to a cap and resets on the next confirmed commit.
+9 -3
View File
@@ -10,6 +10,7 @@
#include <expected>
#include <memory>
#include <optional>
#include <span>
#include <string>
#include <vector>
@@ -45,6 +46,8 @@ struct RegionSessionsConfig {
network::ControlLedger* ledger{};
std::chrono::milliseconds renew_interval{5000}, safety_margin{2000};
network::IntentLimits intents{}; // max_sessions follows control.max_sessions.
// Durable action records (10.4b), owned by the host; null keeps outcomes in memory only.
network::ActionLedger* actions{};
};
// The region host's authority, read once per poll.
struct HostFacts {
@@ -74,9 +77,12 @@ class RegionSessions {
// Actions scheduled for ticks <= `tick`, to be recorded durably with the batch that
// simulates that tick (10.4b). Each action is returned once.
[[nodiscard]] std::vector<network::CarriedAction> carry(std::uint64_t tick);
// A commit covering ticks up to `end_tick` is durable: carried actions become final and
// their outcomes are sent to each account's current session.
void committed(std::uint64_t end_tick, std::uint64_t commit_sequence);
// These carried actions are durable in `commit_sequence` (each with the tick it rode):
// their outcomes go to each account's current session.
void committed(std::span<const network::CarriedAction> actions, std::uint64_t commit_sequence);
// The host dropped these carried actions: final ones are reported not_committed; the
// others await their durable record (their batch outcome was unknown).
void dropped(std::span<const network::CarriedAction> actions, bool final);
// Closes every connection with `shutdown` (flushed by later polls).
void shutdown(std::chrono::steady_clock::time_point now);
[[nodiscard]] std::vector<RegionSessionEvent> take_events();