Add M10.5b snapshot wiring: sessions, evo-server, client and probe
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m54s
Foundation / checks (client) (push) Successful in 12m40s
Foundation / checks (network) (push) Successful in 11m27s
Foundation / checks (tsan) (push) Successful in 8m6s
Foundation / checks (checks) (push) Successful in 31m54s
Foundation / checks (postgres) (push) Successful in 40m43s
Foundation / server-image (push) Successful in 25s
Foundation / postgres-tools (push) Successful in 1m2s
Foundation / image (push) Successful in 2m32s

RegionSessions owns the replication server: interest and acks per session, a
host-set default interest, and per-tick snapshots sized to each connection's
datagram limit. evo-server builds each interest's view from the region's own
habitat sites (default: the first site, radius 7). RegionSessionClient assembles,
acknowledges and presents snapshots and can change its interest; the probe prints
them. Loopback and real-process evidence. ADR-0093.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-06 10:47:47 -04:00
co-authored by Claude Opus 5.5
parent e640b6d3a3
commit 33e91458e7
15 changed files with 428 additions and 23 deletions
+59 -7
View File
@@ -62,15 +62,18 @@ struct RegionSessions::Impl {
};
Impl(RegionSessionsConfig c, std::unique_ptr<network::quic::Endpoint> e,
network::GrantVerifier v, network::SessionControl s, network::IntentAdmission i)
network::GrantVerifier v, network::SessionControl s, network::IntentAdmission i,
network::ReplicationServer r)
: config{std::move(c)}, endpoint{std::move(e)}, verifier{std::move(v)},
control{std::move(s)}, intents{std::move(i)} {}
control{std::move(s)}, intents{std::move(i)}, replication{std::move(r)} {}
RegionSessionsConfig config;
std::unique_ptr<network::quic::Endpoint> endpoint;
network::GrantVerifier verifier;
network::SessionControl control;
network::IntentAdmission intents;
network::ReplicationServer replication;
std::optional<network::SessionInterest> default_interest;
HostFacts facts;
std::vector<Connection> connections;
std::vector<RegionSessionEvent> events;
@@ -110,8 +113,10 @@ struct RegionSessions::Impl {
event.account = c.account;
event.reason = reason;
events.push_back(std::move(event));
if (c.state == State::established)
if (c.state == State::established) {
intents.close(c.session);
replication.close(c.session);
}
if (c.session != 0) // May already be released (superseded, expired, epoch).
(void)control.close(c.session).has_value();
// A superseded session's durable control already moved to its successor.
@@ -183,6 +188,12 @@ struct RegionSessions::Impl {
void welcome(Connection& c, Clock::time_point now) {
if (!intents.open(c.session, c.account_id))
return close(c, SessionCloseReason::capacity, now);
if (!replication.open(c.session, c.welcome.epoch)) {
intents.close(c.session);
return close(c, SessionCloseReason::capacity, now);
}
if (default_interest)
(void)replication.set_interest(c.session, *default_interest).has_value();
c.state = State::established;
c.welcome.server_tick = facts.simulated_tick;
send(c, c.welcome);
@@ -244,8 +255,12 @@ struct RegionSessions::Impl {
if (c.state == State::closing)
return;
const auto decoded = network::decode_session(bytes);
const auto* m = decoded ? std::get_if<network::SessionIntention>(&*decoded) : nullptr;
if (c.state != State::established || !m)
if (c.state != State::established || !decoded)
return close(c, SessionCloseReason::protocol, now);
if (const auto* ack = std::get_if<network::SnapshotAck>(&*decoded))
return replication.acknowledge(c.session, *ack);
const auto* m = std::get_if<network::SessionIntention>(&*decoded);
if (!m)
return close(c, SessionCloseReason::protocol, now);
send_datagram(c, intents.intention(c.session, *m, admission()));
}
@@ -290,6 +305,10 @@ struct RegionSessions::Impl {
}
if (const auto* m = std::get_if<network::ActionQuery>(&*decoded))
return send(c, intents.query(c.session, *m, admission()));
if (const auto* m = std::get_if<network::SessionInterest>(&*decoded)) {
(void)replication.set_interest(c.session, *m).has_value(); // Clamped by the server.
return;
}
if (const auto* m = std::get_if<network::SessionClose>(&*decoded);
m && m->reason == SessionCloseReason::client_closed) {
close(c, SessionCloseReason::client_closed, now);
@@ -324,13 +343,17 @@ RegionSessions::create(RegionSessionsConfig config) {
auto intents = network::IntentAdmission::create(config.intents);
if (!intents)
return std::unexpected(RegionSessionsError::configuration);
config.replication.max_sessions = config.control.max_sessions;
auto replication = network::ReplicationServer::create(config.replication);
if (!replication)
return std::unexpected(RegionSessionsError::configuration);
intents->attach(config.actions);
auto endpoint = network::quic::Endpoint::serve(config.transport);
if (!endpoint)
return std::unexpected(RegionSessionsError::transport);
return std::unique_ptr<RegionSessions>{new RegionSessions{
std::make_unique<Impl>(std::move(config), std::move(*endpoint), std::move(*verifier),
std::move(*control), std::move(*intents))}};
std::move(*control), std::move(*intents), std::move(*replication))}};
}
void RegionSessions::poll(const HostFacts& facts, std::uint64_t now_seconds,
@@ -362,8 +385,10 @@ void RegionSessions::poll(const HostFacts& facts, std::uint64_t now_seconds,
m.connections, [&](const Impl::Connection& c) { return c.id == e.connection; });
if (it == m.connections.end())
continue;
if (it->state == Impl::State::established)
if (it->state == Impl::State::established) {
m.intents.close(it->session);
m.replication.close(it->session);
}
if (it->state == Impl::State::pending) {
(void)m.control.close(it->session).has_value();
if (m.config.ledger && it->generation != 0)
@@ -417,6 +442,33 @@ void RegionSessions::dropped(std::span<const network::CarriedAction> actions, bo
impl_->deliver(impl_->intents.dropped(actions, final));
}
void RegionSessions::set_default_interest(network::SessionInterest interest) {
auto& m = *impl_;
m.default_interest = interest;
for (const auto& c : m.connections)
if (c.state == Impl::State::established && !m.replication.interest(c.session))
(void)m.replication.set_interest(c.session, interest).has_value();
}
void RegionSessions::replicate(
std::uint64_t tick,
const std::function<network::ReplicationSource(const network::SessionInterest&)>& source,
const network::Perceives& perceives) {
auto& m = *impl_;
const auto payload = [&](std::uint64_t session) -> std::size_t {
const auto* c = m.by_session(session);
return c && c->state == Impl::State::established ? m.endpoint->datagram_limit(c->id) : 0;
};
for (const auto& [session, chunks] : m.replication.tick(tick, source, perceives, payload))
if (const auto* c = m.by_session(session); c && c->state == Impl::State::established)
for (const auto& chunk : chunks)
m.send_datagram(*c, chunk); // A refused chunk leaves the snapshot unacknowledged.
}
network::ReplicationStats RegionSessions::replication_stats() const {
return impl_->replication.stats();
}
void RegionSessions::shutdown(Clock::time_point now) {
for (auto& c : impl_->connections)
impl_->close(c, SessionCloseReason::shutdown, now);