Files
aevolution/tests/fixtures/fake_handoff_world.hpp
T
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

131 lines
5.6 KiB
C++

#pragma once
// M10.8c test fixture (ADR-0096): a fake world database with the same probe transfer state
// machine as schema v12 (prepared -> committed or aborted; stage and commit happen together
// at the ticket login), serving one region's ProbeLedger, HandoffLedger and ControlLedger.
#include "evo/network/handoff_ticket.hpp"
#include "evo/network/session_control.hpp"
#include "evo/server/probe_ledger.hpp"
#include <chrono>
#include <cstdint>
#include <expected>
#include <map>
#include <optional>
#include <vector>
namespace evo::test {
using network::AccountId;
using network::ControlLease;
using network::ControlLedger;
using network::ControlLedgerError;
using network::HandoffAdmission;
using network::HandoffLedger;
using network::HandoffLedgerError;
using network::TicketClaims;
using network::TransferId;
struct WorldDb {
struct Probe {
std::uint64_t owner{}, generation{};
std::int64_t x{}, y{};
std::optional<TransferId> transfer;
};
enum class State : std::uint8_t { prepared, committed, aborted };
struct Transfer {
AccountId account;
std::uint64_t source{}, destination{}, generation{};
std::int64_t x{}, y{};
State state{};
};
std::map<AccountId, Probe> probes;
std::map<TransferId, Transfer> transfers;
bool all_overdue{}; // overdue() reports every open transfer (a restarted source's view).
std::uint64_t overdue_reads{};
};
struct RegionDb final : server::ProbeLedger, HandoffLedger, ControlLedger {
RegionDb(WorldDb& w, std::uint64_t r) : world{&w}, region{r} {}
std::expected<server::ProbeHome, server::ProbeLedgerError>
open(const AccountId& account, std::int64_t x, std::int64_t y, std::int64_t) override {
auto [it, created] =
world->probes.try_emplace(account, WorldDb::Probe{region, 1, x, y, std::nullopt});
const auto& p = it->second;
return server::ProbeHome{p.owner, p.generation, p.x, p.y, p.transfer.has_value()};
}
void save(const AccountId& account, std::uint64_t generation, std::int64_t x, std::int64_t y,
std::int64_t) override {
auto& p = world->probes.at(account);
if (p.owner == region && p.generation == generation && !p.transfer) {
p.x = x;
p.y = y;
++saves;
}
}
std::expected<void, server::ProbeLedgerError>
prepare(const AccountId& account, std::uint64_t generation, const TransferId& transfer,
std::uint64_t destination, std::int64_t x, std::int64_t y, std::int64_t) override {
auto& p = world->probes.at(account);
if (p.owner != region || p.generation != generation || p.transfer)
return std::unexpected(server::ProbeLedgerError::unavailable);
p.transfer = transfer;
p.x = x;
p.y = y;
world->transfers[transfer] = {
account, region, destination, generation, x, y, WorldDb::State::prepared};
return {};
}
std::expected<bool, server::ProbeLedgerError> abort(const TransferId& transfer) override {
auto& t = world->transfers.at(transfer);
if (t.state == WorldDb::State::prepared) {
t.state = WorldDb::State::aborted;
world->probes.at(t.account).transfer.reset();
}
return t.state == WorldDb::State::aborted;
}
std::expected<std::vector<server::IncomingProbe>, server::ProbeLedgerError>
incoming() override {
std::vector<server::IncomingProbe> out;
for (const auto& [id, t] : world->transfers)
if (t.destination == region && t.state == WorldDb::State::prepared)
out.push_back({id, t.x, t.y});
return out;
}
std::expected<std::vector<TransferId>, server::ProbeLedgerError>
overdue(std::chrono::seconds) override {
++world->overdue_reads;
std::vector<TransferId> out;
for (const auto& [id, t] : world->transfers)
if (world->all_overdue && t.source == region && t.state == WorldDb::State::prepared)
out.push_back(id);
return out;
}
std::expected<HandoffAdmission, HandoffLedgerError> admit(const TicketClaims& ticket,
std::uint64_t) override {
const auto found = world->transfers.find(ticket.transfer);
if (found == world->transfers.end() || found->second.destination != region ||
found->second.account != ticket.account ||
found->second.state == WorldDb::State::aborted)
return std::unexpected(HandoffLedgerError::refused);
auto& t = found->second;
auto& p = world->probes.at(t.account);
if (t.state == WorldDb::State::prepared) { // Stage and commit: the switch.
t.state = WorldDb::State::committed;
p = {region, t.generation + 1, t.x, t.y, std::nullopt};
}
return HandoffAdmission{ControlLease{++control, {}, std::chrono::milliseconds{20000}},
p.generation, p.x, p.y};
}
std::expected<ControlLease, ControlLedgerError> claim(const AccountId&, std::uint64_t,
std::uint64_t) override {
return ControlLease{++control, {}, std::chrono::milliseconds{20000}};
}
std::expected<std::chrono::milliseconds, ControlLedgerError> renew(const AccountId&,
std::uint64_t) override {
return std::chrono::milliseconds{20000};
}
void release(const AccountId&, std::uint64_t) override {
++releases;
}
WorldDb* world;
std::uint64_t region;
std::uint64_t control{}, saves{}, releases{};
};
} // namespace evo::test