Add M10.8c-2 client handoff switch and evo-server handoff configuration
Foundation / checks (deploy) (push) Successful in 3m20s
Foundation / checks (ecs) (push) Successful in 2m0s
Foundation / checks (client) (push) Failing after 12m9s
Foundation / checks (network) (push) Successful in 13m2s
Foundation / checks (tsan) (push) Successful in 8m7s
Foundation / checks (checks) (push) Successful in 32m1s
Foundation / checks (postgres) (push) Successful in 42m43s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

ADR-0096. The engineering client follows a HandoffOffer into the next region
with its ticket (no grant, no pause, the view kept) and a Redirect to the
probe's owner, picking grants by region claim in rising serial order.
evo-server gains --m10-area, --m10-handoff-key and --m10-neighbour (dev
only), wiring the PostgreSQL probe and handoff ledgers; the probe tool writes
multi-region bundles and reports handoffs and redirects.

Refreshes the dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-06 21:56:42 -04:00
co-authored by Claude Opus 5.5
parent a7a3d12283
commit dabeee8e8b
14 changed files with 635 additions and 129 deletions
+128
View File
@@ -6,6 +6,7 @@
#include "evo/network/dev_credentials.hpp"
#include "evo/network/session_grant.hpp"
#include "evo/server/region_sessions.hpp"
#include "fixtures/fake_handoff_world.hpp"
#include "remote_session.hpp"
#include <algorithm>
#include <chrono>
@@ -13,6 +14,7 @@
#include <filesystem>
#include <fstream>
#include <functional>
#include <memory>
#include <source_location>
#include <stdexcept>
#include <string>
@@ -327,6 +329,131 @@ void refusals(Region& r) {
CHECK(!RemoteSession::open(bad));
CHECK(!RemoteSession::open(r.material({})));
}
// M10.8c-2 (ADR-0096): the client follows a crossing into the next region with the offer's
// ticket (no grant, no pause, the view kept) and follows a redirect at login, picking grants
// by region from a two-region bundle in rising serial order.
void crossing_regions(const Files& f) {
using evo::test::RegionDb;
using evo::test::WorldDb;
constexpr std::int64_t m = 1'000'000;
const auto area = [](std::int64_t x0) {
return network::motion::Area{x0, 0, x0 + (10 * m) - 1, (10 * m) - 1, 0};
};
WorldDb world;
RegionDb db1{world, 1}, db2{world, 2};
auto key1 = std::make_shared<const HandoffSigningKey>(
*HandoffSigningKey::generate(DeploymentEnvironment::dev, 41));
auto key2 = std::make_shared<const HandoffSigningKey>(
*HandoffSigningKey::generate(DeploymentEnvironment::dev, 42));
auto imported = GrantSigningKey::import(DeploymentEnvironment::dev, 1, scalar());
CHECK(imported.has_value());
const auto& issuer = *imported;
const auto make = [&](std::uint64_t id, RegionDb& db,
std::shared_ptr<const HandoffSigningKey> own,
const HandoffSigningKey& neighbour_key, std::uint64_t neighbour,
std::uint16_t neighbour_port, std::uint16_t port) {
server::RegionSessionsConfig c;
c.transport.certificate_pem_file = f.certificate.string();
c.transport.key_pem_file = f.key.string();
c.transport.port = port;
c.control.environment = DeploymentEnvironment::dev;
c.control.world = world_id;
c.control.region = id;
c.control.epoch = 3;
c.control.max_account_attempts = 16;
c.issuer_keys.push_back({1, *issuer.public_key()});
c.ledger = &db;
c.handoff = &db;
c.probes = &db;
c.handoff_key = std::move(own);
c.handoff_keys.push_back(
{neighbour, static_cast<std::uint32_t>(neighbour + 40), *neighbour_key.public_key()});
c.neighbours.push_back(
{{neighbour, "localhost:" + std::to_string(neighbour_port), std::string{name}},
area(neighbour == 1 ? 0 : 10 * m)});
c.ghost_poll = std::chrono::milliseconds{20};
auto made = server::RegionSessions::create(std::move(c));
CHECK(made.has_value());
const auto x0 = id == 1 ? 0 : 10 * m;
CHECK((*made)->set_motion_area(area(x0), x0 + (5 * m), 5 * m));
(*made)->set_default_interest({(x0 / m) + 5, 5, 0, 7});
return std::move(*made);
};
// Region 2 listens on a port found by binding a throwaway region first.
std::uint16_t port2 = 0;
{
auto probe = make(2, db2, key2, *key1, 1, 1, 0);
port2 = probe->port();
}
auto r1 = make(1, db1, key1, *key2, 2, port2, 0);
auto r2 = make(2, db2, key2, *key1, 1, r1->port(), port2);
std::uint64_t tick = 100;
const auto grants = [&](const AccountId& who, std::uint64_t first) {
std::vector<WireGrant> out;
for (std::uint64_t i = 0; i < 4; ++i) {
GrantClaims c;
c.grant_id = 5000 + first + i;
c.account = who;
c.serial = first + i;
c.world = world_id;
c.region = (i % 2) + 1; // Interleaved: region 1, 2, 1, 2.
c.issued_at = start;
c.expires_at = start + 120;
out.push_back(*issuer.sign(c));
}
return out;
};
const auto material = [&](std::vector<WireGrant> g) {
return client::ConnectMaterial{
{"localhost", r1->port()}, std::string{name}, f.ca_pem, f.ca.string(), std::move(g)};
};
const auto pump = [&](const std::vector<Client*>& clients, const std::function<bool()>& done) {
const auto end = Clock::now() + std::chrono::seconds{20};
for (int i = 1; Clock::now() < end; ++i) {
if (i % 5 == 0)
++tick;
for (auto* r : {r1.get(), r2.get()}) {
r->poll({true, 3, tick}, start + 1, Clock::now());
r->replicate(tick, [](const SessionInterest&) {
ReplicationSource s;
s.identity = world_id;
return s;
});
static_cast<void>(r->take_events());
}
for (auto* c : clients)
c->host.step(Clock::now(), c->intention, c->ui);
if (done())
return true;
std::this_thread::sleep_for(std::chrono::milliseconds{2});
}
return done();
};
const auto dana = account(31);
Client a;
CHECK(a.host.connect(RemoteSession::open(material(grants(dana, 10)))));
auto& s = *a.host.session();
CHECK(pump({&a}, [&] { return s.status().phase == "connected" && s.status().marker; }));
CHECK(s.status().region == 1 && s.status().marker_x_mm == 5000);
// Walking east: the crossing is followed into region 2 with the ticket, no grant used.
a.intention.move_x = 1000;
const auto left = s.status().grants_left;
CHECK(pump({&a}, [&] {
const auto st = s.status();
return st.region == 2 && st.phase == "connected" && st.handoffs == 1 && st.marker;
}));
CHECK(s.status().grants_left == left && a.phase() == LaunchPhase::connected &&
world.probes.at(dana).owner == 2 && s.status().marker_x_mm >= 10'000);
a.intention.move_x = 0;
// A second client with a newer bundle logs in at region 1 and is redirected to region 2,
// where it takes over (the first is superseded).
Client b;
CHECK(b.host.connect(RemoteSession::open(material(grants(dana, 20)))));
auto& t = *b.host.session();
CHECK(
pump({&a, &b}, [&] { return t.status().region == 2 && t.status().phase == "connected"; }));
CHECK(a.phase() == LaunchPhase::failed && world.probes.at(dana).owner == 2);
}
} // namespace
int main() try {
@@ -337,6 +464,7 @@ int main() try {
remote_markers(r);
refusals(r);
}
crossing_regions(files);
std::filesystem::remove_all(files.dir);
std::puts("client remote session tests passed");
return 0;
+119
View File
@@ -0,0 +1,119 @@
#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;
};
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<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
+5 -96
View File
@@ -8,6 +8,7 @@
#include "evo/network/session_grant.hpp"
#include "evo/server/probe_ledger.hpp"
#include "evo/server/region_sessions.hpp"
#include "fixtures/fake_handoff_world.hpp"
#include <algorithm>
#include <chrono>
#include <cstdio>
@@ -628,102 +629,10 @@ void ticket_login(const Files& f) {
CHECK(a->state() == RegionSessionState::established && handoff.admitted.size() == 1);
}
// M10.8c (ADR-0096): two regions with adjacent areas in one process, over a fake world
// database with the same transfer state machine as schema v12.
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;
};
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<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{};
};
// M10.8c (ADR-0096): two regions with adjacent areas in one process, over the fake world
// database of tests/fixtures/fake_handoff_world.hpp.
using evo::test::RegionDb;
using evo::test::WorldDb;
constexpr std::int64_t m_um = 1'000'000; // One metre (one cell) in micrometres.
// Region `id` owns x in [x0, x0 + 10 m), y in [0, 10 m) of slice 0.
network::motion::Area area_of(std::int64_t x0) {