Files
aevolution/include/evo/server/postgres_handoff_ledger.hpp
dingoandClaude Opus 5.5 265163a9a6
Foundation / checks (deploy) (push) Successful in 3m20s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (client) (push) Failing after 10m4s
Foundation / checks (network) (push) Successful in 13m3s
Foundation / checks (tsan) (push) Successful in 7m53s
Foundation / checks (checks) (push) Successful in 32m18s
Foundation / checks (postgres) (push) Successful in 43m26s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Add M10.8d two-process handoff fault matrix and recovery fixes
ADR-0096. Two real evo-server processes on PostgreSQL (regions 7/161 and
7/162, adjacent areas) run crossings and crossings back, SIGKILL of the
source after prepare and of the destination after stage and after commit,
duplicate and stale ticket retries, a client that never arrives and a
destination that is down. After every scenario SQL checks one owner per
probe, the conserved inventory and frozen-iff-open-transfer.

The matrix found two recovery gaps, now fixed:
- a source restarted after a prepare left the probe frozen for good (its
  abort deadline was in memory): schema v14 overdue_probe_transfers and a
  session-layer sweep abort open outgoing transfers past the ticket
  lifetime plus 10 s by the database clock;
- a ticket replayed at a restarted destination after the probe moved on
  took control back: admission of a committed transfer now requires the
  record as that commit left it.

M10.8 is complete. Refreshes the dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 23:17:49 -04:00

68 lines
3.6 KiB
C++

#pragma once
#include "evo/network/handoff_ticket.hpp"
#include "evo/persistence/probe_store.hpp"
#include "evo/server/pg_slot.hpp"
#include "evo/server/probe_ledger.hpp"
#include <chrono>
#include <functional>
#include <optional>
#include <utility>
#include <vector>
// M10.8b destination side of a ticket login over PostgreSQL (ADR-0096, schema v12). Linux
// only; owned by the region host's thread, on its own connection slot. For a verified ticket:
// stage its transfer under the host's current lease (again after a restart), commit it (the
// authority switch), then take the account's durable control for the session. Every step is
// idempotent, so a retried ticket login after an undecided outcome converges. A transfer that
// is unknown, aborted, for another account or another region is refused.
namespace evo::server {
class PostgresHandoffLedger final : public network::HandoffLedger {
public:
using LeaseSource = std::function<std::optional<persistence::LeaseGrant>()>;
PostgresHandoffLedger(PgSlot& db, persistence::RegionKey key, LeaseSource lease,
std::chrono::milliseconds duration = std::chrono::milliseconds{20000},
std::chrono::milliseconds timeout = std::chrono::milliseconds{2000})
: db_{&db}, key_{key}, lease_{std::move(lease)}, duration_{duration}, timeout_{timeout} {}
[[nodiscard]] std::expected<network::HandoffAdmission, network::HandoffLedgerError>
admit(const network::TicketClaims& ticket, std::uint64_t session) override;
private:
PgSlot* db_;
persistence::RegionKey key_;
LeaseSource lease_;
std::chrono::milliseconds duration_, timeout_;
};
// M10.8c the region's durable probe records over PostgreSQL (ADR-0096, schema v12-14), on the
// host's lease and its own connection slot. Undecided or failed calls report `unavailable`
// (the session layer retries or refuses); a fenced lease reports `fenced`.
class PostgresProbeLedger final : public ProbeLedger {
public:
using LeaseSource = std::function<std::optional<persistence::LeaseGrant>()>;
static constexpr std::uint64_t inventory = 1000; // EXPERIMENT test inventory per probe.
PostgresProbeLedger(PgSlot& 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<ProbeHome, ProbeLedgerError> open(const network::AccountId& account,
std::int64_t x, std::int64_t y,
std::int64_t z) override;
void save(const network::AccountId& account, std::uint64_t generation, std::int64_t x,
std::int64_t y, std::int64_t z) override;
[[nodiscard]] std::expected<void, ProbeLedgerError>
prepare(const network::AccountId& account, std::uint64_t generation,
const network::TransferId& transfer, std::uint64_t destination, std::int64_t x,
std::int64_t y, std::int64_t z) override;
[[nodiscard]] std::expected<bool, ProbeLedgerError>
abort(const network::TransferId& transfer) override;
[[nodiscard]] std::expected<std::vector<IncomingProbe>, ProbeLedgerError> incoming() override;
[[nodiscard]] std::expected<std::vector<network::TransferId>, ProbeLedgerError>
overdue(std::chrono::seconds age) override;
private:
PgSlot* db_;
persistence::RegionKey key_;
LeaseSource lease_;
std::chrono::milliseconds timeout_;
};
} // namespace evo::server