Wire M10.8c-1 region handoff: protocol v4, durable probes, crossing, ghosts
Foundation / checks (deploy) (push) Successful in 3m29s
Foundation / checks (ecs) (push) Successful in 2m0s
Foundation / checks (client) (push) Successful in 12m51s
Foundation / checks (network) (push) Successful in 13m0s
Foundation / checks (tsan) (push) Successful in 7m50s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 32m4s
Foundation / checks (postgres) (push) Canceled after 19m13s

ADR-0096. Session protocol v4 (v3 is deployed and frozen) adds HandoffOffer,
SessionRedirect, close reasons handed_off and moved, and ghost marker records.
Sessions use the durable probe record: logins open it where it was saved
(redirected when it lives elsewhere), and session ends save it. A marker
crossing into a neighbour's area is frozen, prepared, its control released
and a signed ticket offered; uncommitted transfers are aborted after the
ticket's lifetime. The destination shows arriving probes as ghosts (schema
v13 incoming_probe_transfers) and opens the marker where it crossed.

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:24:42 -04:00
co-authored by Claude Opus 5.5
parent 97a3756e46
commit a7a3d12283
39 changed files with 1315 additions and 68 deletions
+33 -1
View File
@@ -2,10 +2,12 @@
#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:
@@ -21,7 +23,7 @@ class PostgresHandoffLedger final : public network::HandoffLedger {
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::ControlLease, network::HandoffLedgerError>
[[nodiscard]] std::expected<network::HandoffAdmission, network::HandoffLedgerError>
admit(const network::TicketClaims& ticket, std::uint64_t session) override;
private:
@@ -30,4 +32,34 @@ class PostgresHandoffLedger final : public network::HandoffLedger {
LeaseSource lease_;
std::chrono::milliseconds duration_, timeout_;
};
// M10.8c the region's durable probe records over PostgreSQL (ADR-0096, schema v12-13), 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;
private:
PgSlot* db_;
persistence::RegionKey key_;
LeaseSource lease_;
std::chrono::milliseconds timeout_;
};
} // namespace evo::server
+51
View File
@@ -0,0 +1,51 @@
#pragma once
#include "evo/network/handoff_ticket.hpp"
#include "evo/network/session_control.hpp"
#include <cstdint>
#include <expected>
#include <vector>
// M10.8c (ADR-0096): the region's durable probe records as the session layer uses them.
// Transport-neutral; the host implements it over PostgreSQL (PostgresProbeLedger), tests use
// fakes. EXPERIMENT: probes are non-biological engineering entities (ADR-0094).
namespace evo::server {
struct ProbeHome {
std::uint64_t owner{}, generation{};
std::int64_t x{}, y{};
bool frozen{}; // An open transfer: neither this region nor the owner may act yet.
};
struct IncomingProbe {
network::TransferId transfer{};
std::int64_t x{}, y{};
};
enum class ProbeLedgerError : std::uint8_t { fenced, unavailable };
class ProbeLedger {
public:
ProbeLedger() = default;
ProbeLedger(const ProbeLedger&) = delete;
ProbeLedger& operator=(const ProbeLedger&) = delete;
virtual ~ProbeLedger() = default;
// The account's probe, created here at the position when the world has none.
[[nodiscard]] virtual std::expected<ProbeHome, ProbeLedgerError>
open(const network::AccountId& account, std::int64_t x, std::int64_t y, std::int64_t z) = 0;
// Best effort: the owned, active probe's position (session end).
virtual void save(const network::AccountId& account, std::uint64_t generation, std::int64_t x,
std::int64_t y, std::int64_t z) = 0;
// Freezes the probe at its final position for `destination`.
[[nodiscard]] virtual 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) = 0;
// Abandons a transfer whose client never arrived: true when aborted (the probe is active
// here again), false when it had been committed.
[[nodiscard]] virtual std::expected<bool, ProbeLedgerError>
abort(const network::TransferId& transfer) = 0;
// Open transfers addressed to this region (shown as ghosts).
[[nodiscard]] virtual std::expected<std::vector<IncomingProbe>, ProbeLedgerError>
incoming() = 0;
protected:
ProbeLedger(ProbeLedger&&) = default;
ProbeLedger& operator=(ProbeLedger&&) = default;
};
} // namespace evo::server
+17 -1
View File
@@ -7,6 +7,7 @@
#include "evo/network/session_control.hpp"
#include "evo/network/session_grant.hpp"
#include "evo/network/session_protocol.hpp"
#include "evo/server/probe_ledger.hpp"
#include <chrono>
#include <cstddef>
#include <cstdint>
@@ -46,6 +47,11 @@ struct IssuerKey {
std::uint32_t key_id{};
network::GrantPublicKey public_key{};
};
// A region whose area adjoins this one: where its clients dial and the area it owns.
struct Neighbour {
network::RegionAddress address;
network::motion::Area area; // Micrometres, same slice as this region's.
};
// A neighbouring region's handoff public key (ADR-0096): tickets it signs are accepted here.
struct HandoffKey {
std::uint64_t source_region{};
@@ -73,6 +79,15 @@ struct RegionSessionsConfig {
// ticket also needs a HandoffLedger (control must move durably with the transfer).
std::vector<HandoffKey> handoff_keys;
network::HandoffLedger* handoff{};
// M10.8c: with probe records, a session's marker is the account's durable probe (it opens
// where it was saved, a login whose probe lives elsewhere is redirected). With this
// region's handoff key and neighbours as well, a marker crossing into a neighbour's area
// is frozen, prepared and handed over with a ticket.
ProbeLedger* probes{};
std::shared_ptr<const network::HandoffSigningKey> handoff_key;
std::vector<Neighbour> neighbours;
std::uint64_t ticket_lifetime{30}; // Seconds a handoff ticket is valid.
std::chrono::milliseconds ghost_poll{1000}; // Incoming transfers read this often.
};
// The region host's authority, read once per poll.
struct HostFacts {
@@ -119,7 +134,8 @@ class RegionSessions {
const network::Perceives& perceives = {});
[[nodiscard]] network::ReplicationStats replication_stats() const;
// Where probe markers live and spawn (ADR-0094); sessions already established receive a
// marker. False for an invalid area.
// marker. False for an invalid area. With neighbours (ADR-0096), markers move within the
// bounding box of this area and the neighbours' areas, and leaving this area hands off.
[[nodiscard]] bool set_motion_area(const network::motion::Area& area, std::int64_t spawn_x,
std::int64_t spawn_y);
[[nodiscard]] const network::motion::ProbeMarkers& markers() const noexcept;