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
+64 -4
View File
@@ -7,6 +7,8 @@
// scheduled for upcoming ticks are submitted to the host, which commits them with the batch
// of the tick they ride; the host's action acknowledgements and drops become outcomes.
// Session control and action records use their own connection under the host's lease.
// M10.5 (ADR-0093): once per simulated tick every session's snapshot is built from the
// region's own stores for its interest (default: the region's first habitat site, radius 7).
#include "evo/persistence/postgres.hpp"
#include "evo/persistence/region_lease.hpp"
#include <cstdint>
@@ -14,6 +16,8 @@
#include <string>
#ifdef EVO_SERVER_M10
#include "evo/client/environment_view.hpp"
#include "evo/processes/lineage_region.hpp"
#include "evo/server/pg_slot.hpp"
#include "evo/server/postgres_action_ledger.hpp"
#include "evo/server/postgres_control_ledger.hpp"
@@ -61,9 +65,9 @@ template <typename Host> class M10Bridge {
if (!window)
return fail(window.error() == server::SessionWindow::Error::expired
? "error m10-window-expired"
: window.error() == server::SessionWindow::Error::too_long
? "error m10-window-too-long"
: "error m10-window");
: window.error() == server::SessionWindow::Error::too_long
? "error m10-window-too-long"
: "error m10-window");
const auto colon = o.listen.rfind(':');
std::uint16_t port = 0;
if (colon == std::string::npos ||
@@ -129,6 +133,19 @@ template <typename Host> class M10Bridge {
const server::HostFacts facts{s.ready && s.phase == server::HostPhase::running, s.epoch,
s.simulated_tick};
sessions_->poll(facts, wall_seconds(), std::chrono::steady_clock::now());
if (facts.ready && host.state() != nullptr && s.simulated_tick > replicated_) {
replicated_ = s.simulated_tick;
const auto& c = community(*host.state());
if (!default_interest_)
if (const auto& sites = c.resources().fields().sites(); !sites.empty()) {
const auto v = sites.front().voxel;
default_interest_ = network::SessionInterest{v.x, v.y, v.z, 7};
sessions_->set_default_interest(*default_interest_);
}
sessions_->replicate(s.simulated_tick, [&](const network::SessionInterest& in) {
return source(c, in, s.simulated_tick);
});
}
if (facts.ready)
for (const auto& a : sessions_->carry(s.simulated_tick + m10_carry_ahead_ticks)) {
const persistence::ActionRecord record{a.account.bytes, a.action_id, a.tick,
@@ -164,6 +181,44 @@ template <typename Host> class M10Bridge {
}
private:
static const processes::EnvironmentalCommunity&
community(const processes::EnvironmentalCommunity& c) {
return c;
}
static const processes::EnvironmentalCommunity& community(const processes::LineageRegion& r) {
return r.community();
}
// A read-only copy of the region's stores within one interest: the habitat sites of its
// square in its slice. The region has no placed individuals: organisms stay empty.
network::ReplicationSource source(const processes::EnvironmentalCommunity& c,
const network::SessionInterest& in, std::uint64_t tick) {
network::ReplicationSource src;
src.mask = world::all_environment_fields;
const auto& fields = c.resources().fields();
std::vector<world::VoxelAddress> footprint;
for (const auto& site : fields.sites()) {
const auto v = site.voxel;
if (v.z == in.z && v.x >= in.x - in.radius && v.x <= in.x + in.radius &&
v.y >= in.y - in.radius && v.y <= in.y + in.radius &&
footprint.size() < world::max_environment_footprint)
footprint.push_back(v);
}
if (footprint.empty())
return src;
const auto view = world::query_environment(fields, c.resources().terrain(), tick, footprint,
world::all_environment_fields);
if (!view) {
if (!warned_)
std::printf("m10 view-unavailable %u\n", static_cast<unsigned>(view.error()));
warned_ = true;
return src;
}
src.identity = view->identity();
src.field_revision = view->field_revision();
if (const auto cells = client::present_environment(*view, in.z))
src.environment.assign(cells->cells().begin(), cells->cells().end());
return src;
}
static network::CarriedAction carried(const persistence::ActionRecord& r) {
network::CarriedAction a;
a.account.bytes = r.account;
@@ -193,6 +248,9 @@ template <typename Host> class M10Bridge {
std::unique_ptr<server::RegionSessions> sessions_; // Destroyed first: uses the ledgers.
std::optional<server::SessionWindow> window_;
bool window_closed_{};
std::uint64_t replicated_{};
std::optional<network::SessionInterest> default_interest_;
bool warned_{};
};
#else
inline constexpr bool m10_available = false;
@@ -205,7 +263,9 @@ template <typename Host> class M10Bridge {
[[nodiscard]] bool enabled() const noexcept {
return false;
}
[[nodiscard]] bool accepting(std::uint64_t) const noexcept { return false; }
[[nodiscard]] bool accepting(std::uint64_t) const noexcept {
return false;
}
void after_step() {}
void shutdown() {}
};
+51 -2
View File
@@ -6,12 +6,15 @@
// evo-session-probe run --connect HOST:PORT --server-name NAME --ca FILE --issuer-key FILE
// --world N --frame N --region N --account HEX32 --serial N [--lifetime S]
// [--intents N] [--actions N --action-base ID] [--query ID]... [--timeout-ms N]
// [--interest X,Y,Z,R] [--snapshots N]
// Signs a dev grant for the account and serial, logs in over QUIC, sends N intentions
// (one per tick, two ticks ahead) and N probe actions (three ticks ahead), queries the
// given action ids, and prints one line per answer:
// welcome SESSION EPOCH TICK | intention SEQ STATUS | simulated SEQ TICK
// receipt ID STATUS TICK | outcome ID RESULT TICK COMMIT | done
// resolved HOST ADDRESS (a host name was looked up; IPv4)
// snapshot TICK CELLS ORGANISMS MINX MINY MAXX MAXY Z (each newly applied snapshot;
// --snapshots N waits for N; --interest asks for another focus than the default)
// closed REASON TRANSPORT (TRANSPORT names why QUIC ended: untrusted means the server
// answered but failed the pinned CA/name check; idle means nothing answered)
// Statuses, results and reasons are the session-v1 wire values. Exits 0 once every
@@ -160,7 +163,24 @@ struct RunOptions {
action_base{1}, timeout_ms{20000};
std::optional<AccountId> account;
std::vector<std::uint64_t> queries;
std::optional<SessionInterest> interest;
std::uint64_t snapshots{};
};
std::optional<SessionInterest> interest_of(std::string_view v) {
std::array<std::int64_t, 4> parts{};
for (std::size_t i = 0; i < parts.size(); ++i) {
const auto comma = v.find(',');
const auto part = v.substr(0, comma);
const auto [end, ec] = std::from_chars(part.data(), part.data() + part.size(), parts.at(i));
if (ec != std::errc{} || end != part.data() + part.size() ||
(comma == std::string_view::npos) != (i + 1 == parts.size()))
return std::nullopt;
v.remove_prefix(comma == std::string_view::npos ? v.size() : comma + 1);
}
if (parts[3] < 0 || parts[3] > 65535)
return std::nullopt;
return SessionInterest{parts[0], parts[1], parts[2], static_cast<std::uint16_t>(parts[3])};
}
int run(const RunOptions& o) {
const auto scalar = read(o.issuer_key);
@@ -219,6 +239,7 @@ int run(const RunOptions& o) {
const auto deadline = Clock::now() + std::chrono::milliseconds{o.timeout_ms};
bool welcomed = false, queried = false;
std::uint64_t sent_intents = 0, sent_actions = 0, last_tick = 0, simulated = 0;
std::uint64_t seen_snapshot = 0, snapshots = 0;
std::set<std::uint64_t> pending_actions, pending_queries(o.queries.begin(), o.queries.end());
for (std::uint64_t i = 0; i < o.actions; ++i)
pending_actions.insert(o.action_base + i);
@@ -253,6 +274,8 @@ int run(const RunOptions& o) {
}
if (!queried) {
queried = true;
if (o.interest && !c.set_interest(*o.interest))
std::puts("error interest");
for (const auto query : o.queries)
(void)c.query_action(query);
}
@@ -264,6 +287,23 @@ int run(const RunOptions& o) {
std::printf("simulated %llu %llu\n", static_cast<unsigned long long>(s->sequence),
static_cast<unsigned long long>(s->tick));
}
if (const auto* v = c.view(); v && v->tick != seen_snapshot) {
seen_snapshot = v->tick;
++snapshots;
std::int64_t min_x = 0, min_y = 0, max_x = 0, max_y = 0;
for (std::size_t i = 0; i < v->environment.size(); ++i) {
const auto& voxel = v->environment[i].voxel;
min_x = i == 0 ? voxel.x : std::min(min_x, voxel.x);
min_y = i == 0 ? voxel.y : std::min(min_y, voxel.y);
max_x = i == 0 ? voxel.x : std::max(max_x, voxel.x);
max_y = i == 0 ? voxel.y : std::max(max_y, voxel.y);
}
std::printf("snapshot %llu %zu %zu %lld %lld %lld %lld %lld\n",
static_cast<unsigned long long>(v->tick), v->environment.size(),
v->organisms.size(), static_cast<long long>(min_x),
static_cast<long long>(min_y), static_cast<long long>(max_x),
static_cast<long long>(max_y), static_cast<long long>(v->slice_z));
}
for (const auto& r : c.take_action_receipts())
std::printf("receipt %llu %u %llu\n", static_cast<unsigned long long>(r.action_id),
static_cast<unsigned>(r.status), static_cast<unsigned long long>(r.tick));
@@ -279,7 +319,11 @@ int run(const RunOptions& o) {
}
std::fflush(stdout);
if (sent_actions == o.actions && pending_actions.empty() && pending_queries.empty() &&
sent_intents == o.intents && simulated >= std::min<std::uint64_t>(o.intents, 1)) {
sent_intents == o.intents && simulated >= std::min<std::uint64_t>(o.intents, 1) &&
snapshots >= o.snapshots) {
std::printf("snapshot-bytes %llu chunks %llu\n",
static_cast<unsigned long long>(c.snapshot_bytes()),
static_cast<unsigned long long>(c.snapshot_chunks()));
std::puts("done");
c.close();
return 0;
@@ -338,6 +382,10 @@ int main(int argc, char** argv) {
o.action_base = *n;
else if (n && flag == "--timeout-ms" && *n > 0)
o.timeout_ms = *n;
else if (n && flag == "--snapshots" && *n <= 100000)
o.snapshots = *n;
else if (flag == "--interest")
ok = (o.interest = interest_of(value)).has_value();
else
ok = false;
}
@@ -346,7 +394,8 @@ int main(int argc, char** argv) {
std::fputs("usage: evo-session-probe keys --out DIR | run --connect HOST:PORT "
"--server-name NAME --ca FILE --issuer-key FILE --world N --frame N "
"--region N --account HEX32 --serial N [--lifetime S] [--intents N] "
"[--actions N --action-base ID] [--query ID]... [--timeout-ms N]\n",
"[--actions N --action-base ID] [--query ID]... [--timeout-ms N] "
"[--interest X,Y,Z,R] [--snapshots N]\n",
stderr);
return 2;
}