Add M10.4c evo-server QUIC listener and headless session client
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m46s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
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 3m44s
Foundation / checks (client) (push) Canceled after 3m49s
Foundation / checks (network) (push) Canceled after 1m59s

evo-server gains an opt-in M10 listener (--m10-*, QUIC builds only): RegionSessions
with the PostgreSQL control and action ledgers on their own connection under the
host's lease, carried actions submitted to the host and its acknowledgements and
drops turned into outcomes. evo-session-probe is a dev-only headless client. Real
process tests cover intentions, durable action outcomes, SIGKILL before and after
an action's commit, duplicate retries and the probe. The simulated watermark now
reaches every session every tick, so clients always know the server tick.
ADR-0092.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-04 09:20:55 -04:00
co-authored by Claude Opus 5.5
parent 69f3ad7cf8
commit 0bf9901c7f
27 changed files with 1053 additions and 42 deletions
+17
View File
@@ -151,6 +151,11 @@ if(EVO_BUILD_QUIC)
add_library(evo_session_client STATIC src/client/session/region_session.cpp)
target_link_libraries(evo_session_client PUBLIC evo_network_quic evo_network_protocol)
evo_owned_target(evo_session_client)
# M10.4c headless session client (development and test only; ADR-0092).
add_executable(evo-session-probe apps/evo-session-probe/main.cpp)
target_link_libraries(evo-session-probe PRIVATE evo_session_client evo_network_tls)
evo_owned_target(evo-session-probe)
evo_msquic_runtime(evo-session-probe)
if(BUILD_TESTING)
# Owned impairment relay (tests and measurements only).
add_library(evo_network_impair STATIC tools/network/impair/udp_relay.cpp)
@@ -218,6 +223,11 @@ if(EVO_BUILD_POSTGRES)
target_link_libraries(evo-server PRIVATE evo_network_session)
target_compile_definitions(evo-server PRIVATE EVO_SERVER_SESSIONS=1)
endif()
if(EVO_BUILD_QUIC)
# M10.4c QUIC sessions inside the region process (ADR-0091/0092); opt-in by flags.
target_link_libraries(evo-server PRIVATE evo_session_server evo_control_ledger_postgres)
target_compile_definitions(evo-server PRIVATE EVO_SERVER_M10=1)
endif()
evo_owned_target(evo-server)
if(EVO_BUILD_NETWORK)
# M10.3c durable account control and M10.4b durable action records for region sessions
@@ -247,6 +257,13 @@ if(EVO_BUILD_POSTGRES)
target_link_libraries(evo-postgres-tests PRIVATE evo_network_session evo_control_ledger_postgres)
target_compile_definitions(evo-postgres-tests PRIVATE EVO_POSTGRES_SESSIONS=1)
endif()
if(EVO_BUILD_QUIC)
# M10.4c: evo-server with the QUIC listener, real clients and the probe (ADR-0092).
target_sources(evo-postgres-tests PRIVATE tests/region_m10_session_tests.cpp)
target_link_libraries(evo-postgres-tests PRIVATE evo_session_client)
target_compile_definitions(evo-postgres-tests PRIVATE EVO_POSTGRES_M10=1)
add_dependencies(evo-postgres-tests evo-session-probe)
endif()
add_dependencies(evo-postgres-tests evo-server evo-world-clone) # Spawned by process tests.
evo_owned_target(evo-postgres-tests)
# Intentionally not an ordinary CTest: tools/ci/postgres-check.sh owns its private DB.
+1 -1
View File
@@ -24,7 +24,7 @@
{"name": "client", "configurePreset": "client", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-client-ui-model-tests", "evo-client-panel-tests", "evo-client-bindings-tests"]},
{"name": "client-probe", "configurePreset": "client-probe", "targets": ["evo-client-probe"]},
{"name": "network", "configurePreset": "network", "targets": ["evo-client-state-tests", "evo-network-tests", "evo-dev-session"]},
{"name": "quic", "configurePreset": "quic", "targets": ["evo-quic-smoke-tests", "evo-quic-transport-tests", "evo-quic-session-tests", "evo-quic-hol-measure", "evo-network-tests"]},
{"name": "quic", "configurePreset": "quic", "targets": ["evo-quic-smoke-tests", "evo-quic-transport-tests", "evo-quic-session-tests", "evo-quic-hol-measure", "evo-session-probe", "evo-network-tests"]},
{"name": "client-network", "configurePreset": "client-network", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-client-ui-model-tests", "evo-client-panel-tests", "evo-client-bindings-tests", "evo-network-tests", "evo-dev-session"]},
{"name": "client-package", "configurePreset": "client-package", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-client-ui-model-tests", "evo-client-panel-tests", "evo-client-bindings-tests", "evo-network-tests", "evo-dev-session"]}
],
+191
View File
@@ -0,0 +1,191 @@
#pragma once
// M10.4c QUIC session listener for evo-server (ADR-0091, ADR-0092). Compiled only with
// EVO_SERVER_M10 (EVO_BUILD_QUIC with the PostgreSQL build); otherwise the flags are refused
// at parse time. Opt-in, development and test only: nothing deploys it yet.
//
// Each loop iteration after the host's step: the sessions see the host's authority; actions
// 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.
#include "evo/persistence/postgres.hpp"
#include "evo/persistence/region_lease.hpp"
#include <cstdint>
#include <optional>
#include <string>
#ifdef EVO_SERVER_M10
#include "evo/server/pg_slot.hpp"
#include "evo/server/postgres_action_ledger.hpp"
#include "evo/server/postgres_control_ledger.hpp"
#include "evo/server/region_host.hpp"
#include "evo/server/region_sessions.hpp"
#include <algorithm>
#include <charconv>
#include <chrono>
#include <cstdio>
#include <fstream>
#include <iterator>
#include <map>
#include <memory>
#include <vector>
#endif
namespace evo::server_app {
struct M10Options {
std::string listen, certificate, key, issuer, environment;
[[nodiscard]] bool any() const noexcept {
return !listen.empty() || !certificate.empty() || !key.empty() || !issuer.empty() ||
!environment.empty();
}
[[nodiscard]] bool complete() const noexcept {
return !listen.empty() && !certificate.empty() && !key.empty() && !issuer.empty() &&
!environment.empty();
}
};
// Actions are handed to the host as soon as they are scheduled (at most 8 ticks ahead).
inline constexpr std::uint64_t m10_carry_ahead_ticks = 8;
#ifdef EVO_SERVER_M10
inline constexpr bool m10_available = true;
template <typename Host> class M10Bridge {
public:
// Empty bridge without M10 options; nullopt on a startup failure (the caller exits).
static std::optional<M10Bridge> open(const M10Options& o, Host& host,
persistence::RegionKey key, std::uint64_t frame,
const persistence::PgOptions& pg) {
M10Bridge bridge;
if (!o.any())
return bridge;
const auto colon = o.listen.rfind(':');
std::uint16_t port = 0;
if (colon == std::string::npos ||
std::from_chars(o.listen.data() + colon + 1, o.listen.data() + o.listen.size(), port)
.ec != std::errc{})
return fail("error m10-listen");
const auto issuer = read(o.issuer);
if (issuer.size() != network::grant_public_key_bytes)
return fail("error m10-issuer");
server::RegionSessionsConfig config;
config.transport.listen_address = o.listen.substr(0, colon);
config.transport.port = port;
config.transport.certificate_pem_file = o.certificate;
config.transport.key_pem_file = o.key;
config.control.environment = o.environment == "dev" ? network::DeploymentEnvironment::dev
: o.environment == "stage"
? network::DeploymentEnvironment::stage
: network::DeploymentEnvironment::world0;
config.control.world = {key.world, frame};
config.control.region = key.region;
config.control.epoch = 1; // Follows the host's epoch from the first poll.
server::IssuerKey issuer_key;
issuer_key.key_id = 1;
std::copy(issuer.begin(), issuer.end(), issuer_key.public_key.begin());
config.issuer_keys.push_back(issuer_key);
bridge.host_ = &host;
bridge.slot_ = std::make_unique<server::PgSlot>(pg, std::chrono::seconds{2});
const auto lease = [h = &host] { return h->authority(); };
bridge.control_ =
std::make_unique<server::PostgresControlLedger>(*bridge.slot_, key, lease);
bridge.actions_ = std::make_unique<server::PostgresActionLedger>(*bridge.slot_, key, lease);
config.ledger = bridge.control_.get();
config.actions = bridge.actions_.get();
auto sessions = server::RegionSessions::create(std::move(config));
if (!sessions)
return fail(sessions.error() == server::RegionSessionsError::keys ? "error m10-issuer"
: sessions.error() == server::RegionSessionsError::transport
? "error m10-listen"
: "error m10-config");
bridge.sessions_ = std::move(*sessions);
std::printf("m10 listening %u\n", static_cast<unsigned>(bridge.sessions_->port()));
return bridge;
}
[[nodiscard]] bool enabled() const noexcept {
return sessions_ != nullptr;
}
void after_step() {
if (!sessions_)
return;
auto& host = *host_;
const auto& s = host.status();
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)
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,
static_cast<std::uint16_t>(a.kind)};
if (!host.submit_action(record)) // Never reached the host: final.
sessions_->dropped(std::span{&a, 1}, true);
}
std::map<std::uint64_t, std::vector<network::CarriedAction>> committed;
for (const auto& ack : host.take_action_acks())
committed[ack.commit_sequence].push_back(carried(ack.record));
for (const auto& [sequence, actions] : committed) {
sessions_->committed(actions, sequence);
std::printf("m10 committed actions=%zu commit=%llu\n", actions.size(),
static_cast<unsigned long long>(sequence));
}
for (const auto& d : host.take_dropped_actions()) {
const auto a = carried(d.record);
sessions_->dropped(std::span{&a, 1}, d.final);
std::printf("m10 dropped action=%llu final=%d\n",
static_cast<unsigned long long>(d.record.action_id), d.final ? 1 : 0);
}
for (const auto& e : sessions_->take_events())
std::printf("m10 %s session=%llu account=%s reason=%u\n",
e.kind == server::RegionSessionEvent::Kind::opened ? "opened"
: e.kind == server::RegionSessionEvent::Kind::closed ? "closed"
: "refused",
static_cast<unsigned long long>(e.session), e.account.c_str(),
static_cast<unsigned>(e.reason));
}
void shutdown() {
if (sessions_)
sessions_->shutdown(std::chrono::steady_clock::now());
}
private:
static network::CarriedAction carried(const persistence::ActionRecord& r) {
network::CarriedAction a;
a.account.bytes = r.account;
a.action_id = r.action_id;
a.tick = r.tick;
a.kind = network::ActionKind::probe;
return a;
}
static std::uint64_t wall_seconds() {
return static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
}
static std::optional<M10Bridge> fail(const char* message) {
std::puts(message);
return std::nullopt;
}
static std::string read(const std::string& path) {
std::ifstream file{path, std::ios::binary};
return {std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}};
}
Host* host_{};
// Heap-held so the sessions' pointers stay valid when the bridge moves.
std::unique_ptr<server::PgSlot> slot_;
std::unique_ptr<server::PostgresControlLedger> control_;
std::unique_ptr<server::PostgresActionLedger> actions_;
std::unique_ptr<server::RegionSessions> sessions_; // Destroyed first: uses the ledgers.
};
#else
inline constexpr bool m10_available = false;
template <typename Host> class M10Bridge {
public:
static std::optional<M10Bridge> open(const M10Options&, Host&, persistence::RegionKey,
std::uint64_t, const persistence::PgOptions&) {
return M10Bridge{};
}
[[nodiscard]] bool enabled() const noexcept {
return false;
}
void after_step() {}
void shutdown() {}
};
#endif
} // namespace evo::server_app
+25 -1
View File
@@ -51,6 +51,7 @@
#include "evo/processes/development_opening.hpp"
#include "evo/server/ops_http.hpp"
#include "evo/server/region_host.hpp"
#include "m10_bridge.hpp"
#include "session_bridge.hpp"
#include <algorithm>
@@ -91,6 +92,7 @@ struct Options {
std::uint64_t accelerate{1};
std::uint64_t objects_reserve_mib{1024};
server_app::SessionOptions session;
server_app::M10Options m10;
};
// Kills this process without any cleanup: the real SIGKILL, at a chosen boundary.
@@ -214,6 +216,17 @@ std::optional<Options> parse(int argc, char** argv) {
else if (flag == "--session-environment" &&
(value == "dev" || value == "stage" || value == "world0"))
o.session.environment = value;
else if (flag == "--m10-listen")
o.m10.listen = value;
else if (flag == "--m10-cert")
o.m10.certificate = value;
else if (flag == "--m10-key")
o.m10.key = value;
else if (flag == "--m10-issuer")
o.m10.issuer = value;
else if (flag == "--m10-environment" &&
(value == "dev" || value == "stage" || value == "world0"))
o.m10.environment = value;
else if (flag == "--crash-at") {
const auto colon = value.find(':');
const auto ordinal =
@@ -241,6 +254,9 @@ std::optional<Options> parse(int argc, char** argv) {
if (o.session.any() &&
(!server_app::sessions_available || !o.session.complete() || !o.synthetic))
return std::nullopt;
// M10 sessions (ADR-0091/0092) need every setting and the QUIC build.
if (o.m10.any() && (!server_app::m10_available || !o.m10.complete()))
return std::nullopt;
if (std::ranges::find(o.host.retained_builds, o.host.build) == o.host.retained_builds.end())
o.host.retained_builds.push_back(o.host.build);
return o;
@@ -365,6 +381,10 @@ template <typename State> int serve(Options& o) {
auto sessions = server_app::SessionBridge::open(o.session, o.host.key, o.host.frame);
if (!sessions)
return 2;
auto m10 = server_app::M10Bridge<server::RegionHost<State>>::open(o.m10, host, o.host.key,
o.host.frame, o.pg);
if (!m10)
return 2;
std::fflush(stdout);
const std::uint64_t lookahead = sessions->enabled() ? server_app::session_lookahead_ticks : 64;
server::OpsCounters counters;
@@ -431,6 +451,7 @@ template <typename State> int serve(Options& o) {
};
for (;;) {
if (stop_requested && !drain_deadline) {
m10->shutdown();
host.drain();
drain_deadline = std::chrono::steady_clock::now() + o.drain;
}
@@ -528,6 +549,7 @@ template <typename State> int serve(Options& o) {
if (ops)
ops->serve(handler);
sessions->step(host.state(), host.status());
m10->after_step();
std::fflush(stdout);
if (o.crash_point == "after-ack" && !acknowledged.empty() && ++ack_steps == o.crash_ordinal)
crash_now();
@@ -563,7 +585,9 @@ int main(int argc, char** argv) {
"[--ops-listen ADDRESS:PORT] [--synthetic-inputs development-v1 "
"[--synthetic-until TICK] [--accelerate N] [--session-listen ADDRESS:PORT "
"--session-cert F --session-key F --session-grant-key F "
"--session-grant-ledger F --session-environment dev]]\n",
"--session-grant-ledger F --session-environment dev]] [--m10-listen "
"ADDRESS:PORT --m10-cert F --m10-key F --m10-issuer F "
"--m10-environment dev|stage|world0]\n",
stderr);
return 2;
}
+283
View File
@@ -0,0 +1,283 @@
// M10.4c headless session client (ADR-0091, ADR-0092). Development and test only.
//
// evo-session-probe keys --out DIR
// Writes a fresh dev issuer key pair: DIR/issuer.key (32-byte P-256 scalar, owner-only)
// and DIR/issuer.pub (65-byte public key for evo-server --m10-issuer).
// 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]
// 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 | closed REASON | done
// Statuses, results and reasons are the session-v1 wire values. Exits 0 once every
// action is final and every query answered, 1 on timeout, 3 when the server closes.
// The issuer key is a development credential: the probe refuses any environment but dev.
#include "evo/client/region_session.hpp"
#include "evo/network/session_grant.hpp"
#include <algorithm>
#include <array>
#include <charconv>
#include <chrono>
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <iterator>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <thread>
#include <vector>
namespace {
using namespace evo;
using namespace evo::network;
using Clock = std::chrono::steady_clock;
std::optional<std::uint64_t> number(std::string_view v) {
std::uint64_t n = 0;
const auto [end, ec] = std::from_chars(v.data(), v.data() + v.size(), n);
if (ec != std::errc{} || end != v.data() + v.size())
return std::nullopt;
return n;
}
std::string read(const std::filesystem::path& path) {
std::ifstream file{path, std::ios::binary};
return {std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}};
}
bool write(const std::filesystem::path& path, std::span<const std::uint8_t> bytes) {
std::ofstream file{path, std::ios::binary | std::ios::trunc};
file.write(reinterpret_cast<const char*>(bytes.data()),
static_cast<std::streamsize>(bytes.size()));
return file.good();
}
std::optional<AccountId> account_of(std::string_view hex) {
if (hex.size() != 32)
return std::nullopt;
AccountId id;
for (std::size_t i = 0; i < 16; ++i) {
unsigned value = 0;
const auto [end, ec] =
std::from_chars(hex.data() + (2 * i), hex.data() + (2 * i) + 2, value, 16);
if (ec != std::errc{} || end != hex.data() + (2 * i) + 2)
return std::nullopt;
id.bytes.at(i) = static_cast<std::uint8_t>(value);
}
return id.valid() ? std::optional{id} : std::nullopt;
}
int keys(const std::filesystem::path& out) {
std::filesystem::create_directories(out);
for (int attempt = 0; attempt < 8; ++attempt) {
std::array<std::uint8_t, grant_private_key_bytes> scalar{};
if (!random_bytes(scalar))
return 1;
auto key = GrantSigningKey::import(DeploymentEnvironment::dev, 1, scalar);
if (!key)
continue; // Out of the curve's range: draw again.
const auto pub = key->public_key();
if (!pub || !write(out / "issuer.key", scalar) || !write(out / "issuer.pub", *pub))
return 1;
std::filesystem::permissions(out / "issuer.key",
std::filesystem::perms::owner_read |
std::filesystem::perms::owner_write,
std::filesystem::perm_options::replace);
std::puts("keys written");
return 0;
}
return 1;
}
struct RunOptions {
std::string host, server_name, ca, issuer_key;
std::uint16_t port{};
std::uint64_t world{}, frame{}, region{}, serial{}, lifetime{60}, intents{}, actions{},
action_base{1}, timeout_ms{20000};
std::optional<AccountId> account;
std::vector<std::uint64_t> queries;
};
int run(const RunOptions& o) {
const auto scalar = read(o.issuer_key);
const auto key = GrantSigningKey::import(
DeploymentEnvironment::dev, 1,
std::span{reinterpret_cast<const std::uint8_t*>(scalar.data()), scalar.size()});
if (!key) {
std::puts("error issuer-key");
return 2;
}
GrantClaims claims;
std::array<std::uint8_t, 8> id{};
if (!random_bytes(id)) {
std::puts("error random");
return 2;
}
for (std::size_t i = 0; i < id.size(); ++i)
claims.grant_id |= static_cast<std::uint64_t>(id.at(i)) << (8U * i);
claims.grant_id = std::max<std::uint64_t>(claims.grant_id, 1);
if (!o.account)
return 2; // Required at parse time.
claims.account = *o.account;
claims.serial = o.serial;
claims.world = {o.world, o.frame};
claims.region = o.region;
claims.issued_at =
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
claims.expires_at = claims.issued_at + o.lifetime;
const auto grant = key->sign(claims);
if (!grant) {
std::puts("error grant");
return 2;
}
client::RegionSessionClientConfig config;
config.transport.server_address = o.host;
config.transport.port = o.port;
config.transport.server_name = o.server_name;
config.transport.authority_pem = read(o.ca);
config.transport.authority_pem_file = o.ca;
config.grant = *grant;
auto made = client::RegionSessionClient::connect(std::move(config), Clock::now());
if (!made) {
std::puts("error connect");
return 2;
}
auto& c = **made;
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::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);
while (Clock::now() < deadline) {
c.poll(Clock::now());
if (c.state() == client::RegionSessionState::closed) {
std::printf("closed %u\n", static_cast<unsigned>(c.close_reason().value_or(
SessionCloseReason::connection_lost)));
return 3;
}
if (c.state() != client::RegionSessionState::established) {
std::this_thread::sleep_for(std::chrono::milliseconds{2});
continue;
}
if (!welcomed) {
welcomed = true;
const auto& w = *c.welcome();
std::printf("welcome %llu %llu %llu\n", static_cast<unsigned long long>(w.session),
static_cast<unsigned long long>(w.epoch),
static_cast<unsigned long long>(w.server_tick));
}
const auto tick = c.server_tick();
if (tick != last_tick) {
last_tick = tick;
if (sent_intents < o.intents && c.send_intention(tick + 2, 100, 0))
++sent_intents;
if (sent_actions < o.actions &&
c.send_action(o.action_base + sent_actions, ActionKind::probe, tick + 3))
++sent_actions;
}
if (!queried) {
queried = true;
for (const auto query : o.queries)
(void)c.query_action(query);
}
for (const auto& r : c.take_intention_receipts())
std::printf("intention %llu %u\n", static_cast<unsigned long long>(r.sequence),
static_cast<unsigned>(r.status));
if (const auto s = c.simulated(); s && s->sequence != simulated) {
simulated = s->sequence;
std::printf("simulated %llu %llu\n", static_cast<unsigned long long>(s->sequence),
static_cast<unsigned long long>(s->tick));
}
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));
for (const auto& out : c.take_action_outcomes()) {
std::printf(
"outcome %llu %u %llu %llu\n", static_cast<unsigned long long>(out.action_id),
static_cast<unsigned>(out.result), static_cast<unsigned long long>(out.tick),
static_cast<unsigned long long>(out.commit_sequence));
pending_queries.erase(out.action_id);
if (out.result == ActionResult::committed_no_effect ||
out.result == ActionResult::not_committed)
pending_actions.erase(out.action_id);
}
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)) {
std::puts("done");
c.close();
return 0;
}
std::this_thread::sleep_for(std::chrono::milliseconds{2});
}
std::puts("timeout");
return 1;
}
} // namespace
int main(int argc, char** argv) {
const std::vector<std::string_view> args(argv + 1, argv + argc);
if (args.size() == 3 && args[0] == "keys" && args[1] == "--out")
return keys(std::filesystem::path{std::string{args[2]}});
RunOptions o;
bool ok = !args.empty() && args[0] == "run" && args.size() % 2 == 1;
for (std::size_t i = 1; ok && i + 1 < args.size(); i += 2) {
const auto flag = args[i];
const auto value = args[i + 1];
const auto n = number(value);
if (flag == "--connect") {
const auto colon = value.rfind(':');
const auto port =
colon == std::string_view::npos ? std::nullopt : number(value.substr(colon + 1));
ok = port && *port > 0 && *port <= 65535;
if (ok) {
o.host = std::string{value.substr(0, colon)};
o.port = static_cast<std::uint16_t>(*port);
}
} else if (flag == "--server-name")
o.server_name = value;
else if (flag == "--ca")
o.ca = value;
else if (flag == "--issuer-key")
o.issuer_key = value;
else if (flag == "--account")
ok = (o.account = account_of(value)).has_value();
else if (flag == "--query" && n)
o.queries.push_back(*n);
else if (n && flag == "--world")
o.world = *n;
else if (n && flag == "--frame")
o.frame = *n;
else if (n && flag == "--region")
o.region = *n;
else if (n && flag == "--serial")
o.serial = *n;
else if (n && flag == "--lifetime" && *n > 0 && *n <= 3600)
o.lifetime = *n;
else if (n && flag == "--intents" && *n <= 1000)
o.intents = *n;
else if (n && flag == "--actions" && *n <= 1000)
o.actions = *n;
else if (n && flag == "--action-base" && *n > 0)
o.action_base = *n;
else if (n && flag == "--timeout-ms" && *n > 0)
o.timeout_ms = *n;
else
ok = false;
}
if (!ok || o.host.empty() || o.server_name.empty() || o.ca.empty() || o.issuer_key.empty() ||
!o.account || o.world == 0 || o.frame == 0 || o.region == 0 || o.serial == 0) {
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",
stderr);
return 2;
}
return run(o);
}
+3 -2
View File
@@ -523,8 +523,9 @@ hardware (10.9). 10.2 split: 10.2a selection, pins and build of msquic/OpenSSL d
session control done; 10.3b QUIC session login (schemas/network/session-v1.md) done;
10.3c durable per-world account control (schema v10) done. 10.4 split (ADR-0092):
10.4a intention/action protocol and admission done; 10.4b durable action records
(schema v11, same transaction as the checkpoint) done; 10.4c evo-server wiring with a
headless client follows. 10.5-10.9 planned.
(schema v11, same transaction as the checkpoint) done; 10.4c evo-server QUIC listener and
headless client with process kill tests done. The engineering GUI client still uses the
M9 dev path. 10.5-10.9 planned.
**Entry:** M9 client/session evidence and M7/M8 dev/stage durability. Read
NETWORK_ARCHITECTURE, PERSISTENCE_ARCHITECTURE and ADR-0017. The M9 transport is
+5 -1
View File
@@ -32,7 +32,11 @@ actions have no biological effect yet. M10.4b makes
action outcomes durable: schema v11 records each batch's actions in the same statement as
its checkpoint, the host attaches actions to the ticks they ride, and outcomes are read
from the durable record after crashes before or after a commit, unknown publications and
cross-region moves. Next: M10.4c evo-server wiring with a headless client.
cross-region moves. M10.4c adds the opt-in
evo-server QUIC listener (session control and action records under the host's lease) and
the headless `evo-session-probe`, with real-process tests including SIGKILL before and after
an action's commit. M10.4 is complete; the GUI client still uses the M9 dev path. Next:
M10.5 bounded snapshots and spatial interest.
## Previous gate - 2026-10-02
@@ -23,8 +23,9 @@ authoritative state yet. Committed batch traces record host inputs only, not req
state claim (position, energy): the message has no such fields and any extra bytes make
it invalid. Answers: an `IntentionReceipt` (admitted = scheduled for its tick, or a
refusal) and a cumulative `SimulatedThrough` watermark (every admitted intention up to a
sequence whose tick has been simulated in the epoch), repeated every 20 ticks so a lost
datagram is covered. Intentions are superseding: there is no per-intention durable record.
sequence whose tick has been simulated in the epoch), sent to every session on every
simulated tick (sequence 0 before its first), so a lost datagram is covered and clients
always know the server tick (until 10.5 snapshots carry it). Intentions are superseding: there is no per-intention durable record.
- *Actions* (stream): a client-chosen action id, unique per account and stable across
retries and reconnects, a kind and a tick. Answers: an `ActionReceipt` (scheduled, or a
refusal) and a final `ActionOutcome`: `committed_no_effect` with its commit sequence once
@@ -89,3 +90,30 @@ Schema v11 (`migrations/0011_region_actions.sql`, [region-actions-v1](../../sche
- Limits: action rows are retained (no pruning policy yet); clones (ADR-0067) do not copy
them; the two-argument publication of a commit that has an action block would still
return its receipt (the adapter never does this).
## M10.4c evo-server listener and headless client (2026-10-04)
- **evo-server** (`--m10-listen ADDRESS:PORT --m10-cert F --m10-key F --m10-issuer F
--m10-environment dev|stage|world0`, builds with EVO_BUILD_QUIC and PostgreSQL only;
opt-in, development and test, nothing deploys it): `RegionSessions` with
`PostgresControlLedger` and `PostgresActionLedger` on their own connection slot (reconnects
after store failures) under the host's current lease (`RegionHost::authority()`). After
each host step the sessions see the host's authority; actions scheduled up to 8 ticks
ahead go to the host (`submit_action`; a refusal is final `not_committed`); the host's
action acknowledgements and drops become outcomes. Draining closes sessions with
`shutdown`. The issuer public key is a 65-byte file (key id 1).
- **evo-session-probe** (dev only): generates a dev issuer key pair, signs a grant for a
given account and serial, logs in, sends intentions and probe actions, queries ids and
prints one machine-readable line per answer.
- **After a restart, `unknown` means "not on record"**: a new process cannot tell an id it
never saw from one admitted by a dead process. Both were never committed (the old epoch
is fenced and its commits are final), so retrying the same id is safe and commits once.
- **Found with real processes: clients need the server tick every tick.** A client that sent
only actions learned the server tick from receipts and from watermarks repeated every 20
ticks, so after waiting about a second for an outcome its next action named a past tick
(`outside_window`). `SimulatedThrough` is now sent to every established session on every
simulated tick (sequence 0 before its first intention): 24 bytes per tick on the datagram
channel, and the client's clock for the server tick until 10.5 snapshots carry it.
- Process evidence: actions survive SIGKILL after their commit (the outcome is answered from
the record by the next process, and a retry is a duplicate with the same outcome); an
action whose tick had not run at SIGKILL has no record, answers `unknown`, and commits
exactly once when retried.
+33
View File
@@ -4276,3 +4276,36 @@ session and network tests; Windows MSVC 19.44 preset `quic` build and CTest 4/4
rebuilt, timestamps checked).
Not done: evo-server wiring, headless client and process kill tests with real sessions
(10.4c); ASan of the PostgreSQL suite; a real two-region move with a pending action.
## 2026-10-04 — M10.4c evo-server QUIC listener and headless client (ADR-0092)
Implemented the opt-in `--m10-*` listener in evo-server (`apps/evo-server/m10_bridge.hpp`:
RegionSessions with PostgreSQL control and action ledgers on their own `PgSlot`, under
`RegionHost::authority()`), `evo-session-probe` (dev issuer keys, signed dev grants, login,
intentions, actions, queries) and `tests/region_m10_session_tests.cpp` (evo-postgres-tests
with EVO_BUILD_QUIC; region 7/151).
Process evidence (real evo-server, synthetic ticks, fast lease, in-process QUIC clients):
intention receipt and watermark; action receipt then a committed outcome matching its
durable record; SIGKILL after the record of a second action exists, restart, a newer grant:
the query answers the record, and a retry of the first action is a duplicate with the same
outcome; SIGKILL while a third action's tick had not run: no record, the next process
answers `unknown`, the retry is admitted and commits once; the probe logs in, gets
admitted intentions and two committed actions and exits 0; SIGTERM drains with exit 0.
Found and fixed with real processes: clients that sent only actions learned the server tick
too rarely (watermarks repeated every 20 ticks and only after intentions), so a later
action named a past tick (`outside_window`); the watermark now goes to every session every
simulated tick. The first intention after Welcome can be refused while the QUIC datagram
extension is not yet negotiated: tests retry (the probe retries each tick) and the client
API documents it. Also a shadowed variable in the probe (MSVC C4456, GCC -Wshadow) and
unchecked optional accesses (tidy).
Executed: Linux GCC 14 `tools/ci/postgres-check.sh` with EVO_BUILD_QUIC (20 integration and
rehearsal suites including the M10 process test, migration and audit probes); clang-tidy 19
on evo-server, the probe, the ledgers, the host and the M10/action/control tests (Clang
build with PostgreSQL, network and QUIC) and on the session sources and tests; format
check; GCC preset `quic` CTest 4/4, session tests 10/10 repeated; Clang 19 ASan/UBSan
session and network tests; Windows MSVC 19.44 preset `quic` build (including the probe) and
CTest 4/4 (binaries rebuilt, timestamps checked).
Not done: the engineering GUI client on M10 sessions; packaging (the server image does not
enable QUIC); a two-process cross-region move; ASan of the PostgreSQL suite.
+7
View File
@@ -251,6 +251,13 @@ final `stats`. Only `ack` and `outcome` lines are durable facts.
`--ready-file` mirrors readiness for probes. SIGTERM drains (commits pending ticks
and releases the lease) within `--drain-ms`.
With EVO_BUILD_QUIC, `--m10-listen ADDRESS:PORT --m10-cert F --m10-key F --m10-issuer F
--m10-environment dev|stage|world0` opens the M10 session listener (ADR-0091/0092;
development and test only, port 0 picks an ephemeral port printed as `m10 listening`).
Session control and action records use a separate runtime connection under the host's
lease. Events: `m10 opened|closed|refused`, `m10 committed`, `m10 dropped`.
`evo-session-probe` is the matching headless client (dev issuer keys and grants only).
Exit codes:
- 0: drained;
- 3: the drain deadline passed, and the next owner reconciles;
+3 -1
View File
@@ -40,7 +40,9 @@ class RegionSessionClient {
// Sends Close{client_closed} and closes the connection.
void close();
// Realtime intention for `tick` (server_tick + 1 ..= + 8); returns its sequence, or
// nothing unless established and sent. Datagrams may be lost: no receipt is not a refusal.
// nothing unless established and sent (also while the QUIC datagram extension is not yet
// negotiated, just after Welcome: retry). Datagrams may be lost: no receipt is not a
// refusal.
[[nodiscard]] std::optional<std::uint64_t>
send_intention(std::uint64_t tick, std::int16_t move_x, std::int16_t move_y);
// A discrete action with a caller-chosen id, unique for the account (stable across
+7 -3
View File
@@ -26,8 +26,10 @@ struct IntentLimits {
std::uint32_t max_actions_per_window{4}; // Every attempt counts.
std::size_t max_unresolved{256}; // Intentions plus actions per session.
std::size_t max_sessions{32};
std::size_t max_finals{2048}; // Recent final outcomes kept for duplicates and queries.
std::uint64_t watermark_every{20}; // Ticks between repeats of an unchanged watermark.
std::size_t max_finals{2048}; // Recent final outcomes kept for duplicates and queries.
// Ticks between watermarks to each session (1: every simulated tick). The watermark is
// also every client's clock for the server tick until snapshots carry it (10.5).
std::uint64_t watermark_every{1};
};
// The host's authority as admission must see it.
struct AdmissionFacts {
@@ -86,7 +88,9 @@ class IntentAdmission {
// is ready, and an action no longer in memory is looked up.
[[nodiscard]] ActionOutcome query(std::uint64_t session, const ActionQuery& m,
const AdmissionFacts& facts);
// Watermarks to send after the host simulated through facts.server_tick.
// Watermarks to send after the host simulated through facts.server_tick: to every
// session (sequence 0 before its first simulated intention) at least every
// `watermark_every` ticks, and whenever its sequence advances.
[[nodiscard]] std::vector<std::pair<std::uint64_t, SimulatedThrough>>
simulated(const AdmissionFacts& facts);
// Scheduled actions whose tick is <= `tick`: they ride that tick's batch from now on.
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include "evo/persistence/postgres.hpp"
#include <chrono>
#include <memory>
#include <utility>
// One lazily (re)connected PostgreSQL connection for single-owner callers such as the
// session ledgers (ADR-0091/0092). A caller that sees a store failure marks the slot broken;
// the next get() reconnects. Never retries a statement by itself.
namespace evo::server {
class PgSlot {
public:
PgSlot(persistence::PgOptions options, std::chrono::milliseconds connect_timeout)
: options_{std::move(options)}, timeout_{connect_timeout} {}
// Nullptr when no connection can be made now.
[[nodiscard]] persistence::Postgres* get() {
if (!db_)
if (auto made = persistence::Postgres::connect(options_, timeout_))
db_ = std::move(*made);
return db_.get();
}
void broken() noexcept {
db_.reset();
}
private:
persistence::PgOptions options_;
std::chrono::milliseconds timeout_;
std::unique_ptr<persistence::Postgres> db_;
};
} // namespace evo::server
@@ -1,27 +1,28 @@
#pragma once
#include "evo/network/intent_admission.hpp"
#include "evo/persistence/region_lease_store.hpp"
#include "evo/server/pg_slot.hpp"
#include <chrono>
#include <functional>
#include <optional>
#include <utility>
// M10.4b durable action records over the region's PostgreSQL lease (ADR-0092, schema v11).
// Linux only. Owned by the region host's thread, on the host's own connection. `lease`
// Linux only. Owned by the region host's thread, on its own connection slot. `lease`
// returns the host's current region lease, or nothing while it holds none; every lookup
// then reports `unavailable`, as does any store failure.
namespace evo::server {
class PostgresActionLedger final : public network::ActionLedger {
public:
using LeaseSource = std::function<std::optional<persistence::LeaseGrant>()>;
PostgresActionLedger(persistence::Postgres& db, persistence::RegionKey key, LeaseSource lease,
PostgresActionLedger(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<std::optional<network::ActionOutcome>, network::ActionLedgerError>
find(const network::AccountId& account, std::uint64_t action_id) override;
private:
persistence::Postgres* db_;
PgSlot* db_;
persistence::RegionKey key_;
LeaseSource lease_;
std::chrono::milliseconds timeout_;
@@ -1,13 +1,14 @@
#pragma once
#include "evo/network/session_control.hpp"
#include "evo/persistence/account_control_store.hpp"
#include "evo/server/pg_slot.hpp"
#include <chrono>
#include <functional>
#include <optional>
#include <utility>
// M10.3c durable account control over the region's PostgreSQL lease (ADR-0091, schema v10).
// Linux only. Owned by the region host's thread, on the host's own connection. `lease`
// Linux only. Owned by the region host's thread, on its own connection slot. `lease`
// returns the host's current region lease, or nothing while it holds none (every call then
// reports `fenced`). Store failures that may have executed or are undecided report
// `unavailable`; the session layer then keeps or closes sessions by its own deadlines.
@@ -15,7 +16,7 @@ namespace evo::server {
class PostgresControlLedger final : public network::ControlLedger {
public:
using LeaseSource = std::function<std::optional<persistence::LeaseGrant>()>;
PostgresControlLedger(persistence::Postgres& db, persistence::RegionKey key, LeaseSource lease,
PostgresControlLedger(PgSlot& db, persistence::RegionKey key, LeaseSource lease,
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} {}
@@ -26,7 +27,7 @@ class PostgresControlLedger final : public network::ControlLedger {
void release(const network::AccountId& account, std::uint64_t generation) override;
private:
persistence::Postgres* db_;
PgSlot* db_;
persistence::RegionKey key_;
LeaseSource lease_;
std::chrono::milliseconds duration_, timeout_;
+3
View File
@@ -128,6 +128,9 @@ template <typename State> class RegionHost {
[[nodiscard]] const HostStatus& status() const noexcept {
return status_;
}
// The current lease while this host may originate (for fenced calls made on its behalf,
// such as session control and action records); nothing otherwise.
[[nodiscard]] std::optional<persistence::LeaseGrant> authority() const;
// Read-only, for operational reporting (free space against the reserve).
[[nodiscard]] const persistence::FilesystemObjectStore& objects() const noexcept {
return *objects_;
+2 -1
View File
@@ -66,7 +66,8 @@ Close reasons (wire 1..13): 1 client_closed, 2 superseded, 3 expired, 4 stale_ep
- Reconnecting needs a new connection and a newer grant (ADR-0089).
- Intentions (ADR-0092): one per tick, ticks and sequences increasing, tick within
server_tick + 1 ..= + 8. A receipt only says admitted or refused; `SimulatedThrough`
says which admitted intentions' ticks have run (cumulative, resent every 20 ticks).
says which admitted intentions' ticks have run (cumulative, sent every simulated tick, sequence 0 before the first; it is also the
client's clock for the server tick).
Any datagram other than an Intention, or before Welcome, closes with `protocol`.
- Actions (ADR-0092): ids unique per account and never admitted twice. A receipt only
says scheduled or refused; `ActionOutcome` is sent once the action is final, again
+2 -3
View File
@@ -210,9 +210,8 @@ IntentAdmission::simulated(const AdmissionFacts& facts) {
s.pending.pop_front();
}
const bool changed = s.watermark != s.sent_watermark;
const bool repeat =
s.watermark != 0 && (facts.server_tick < s.sent_at_tick ||
facts.server_tick - s.sent_at_tick >= limits_.watermark_every);
const bool repeat = facts.server_tick < s.sent_at_tick ||
facts.server_tick - s.sent_at_tick >= limits_.watermark_every;
if (changed || repeat) {
s.sent_watermark = s.watermark;
s.sent_at_tick = facts.server_tick;
+7
View File
@@ -531,6 +531,13 @@ template <typename State> void RegionHost<State>::drain() {
status_.ready = false;
}
template <typename State>
std::optional<persistence::LeaseGrant> RegionHost<State>::authority() const {
if (!status_.ready || !authority_.may_originate(LeaseClock::now()))
return std::nullopt;
return authority_.grant();
}
template <typename State> std::vector<FinalAck> RegionHost<State>::take_acks() {
return std::exchange(acks_, {});
}
+11 -3
View File
@@ -6,10 +6,18 @@ PostgresActionLedger::find(const network::AccountId& account, std::uint64_t acti
const auto lease = lease_();
if (!lease)
return std::unexpected(network::ActionLedgerError::unavailable);
const auto found =
persistence::find_region_action(*db_, key_, *lease, account.bytes, action_id, timeout_);
if (!found.has_value())
auto* db = db_->get();
if (!db)
return std::unexpected(network::ActionLedgerError::unavailable);
const auto found =
persistence::find_region_action(*db, key_, *lease, account.bytes, action_id, timeout_);
if (!found.has_value()) {
const auto kind = found.error().kind;
if (kind == persistence::LeaseStoreError::store ||
kind == persistence::LeaseStoreError::unknown)
db_->broken(); // Reconnect next time.
return std::unexpected(network::ActionLedgerError::unavailable);
}
const auto& record = found.value();
if (!record.has_value())
return std::optional<network::ActionOutcome>{};
+29 -8
View File
@@ -20,6 +20,11 @@ ControlLedgerError ledger_error(ControlStoreError e) {
persistence::Uuid uuid(const network::AccountId& account) {
return account.bytes;
}
// A store failure leaves the connection in an unknown state: reconnect next time.
void note(PgSlot& slot, ControlStoreError e) {
if (e == ControlStoreError::store || e == ControlStoreError::unknown)
slot.broken();
}
} // namespace
std::expected<network::ControlLease, ControlLedgerError>
@@ -28,10 +33,15 @@ PostgresControlLedger::claim(const network::AccountId& account, std::uint64_t se
const auto lease = lease_();
if (!lease)
return std::unexpected(ControlLedgerError::fenced);
const auto claimed = persistence::claim_account_control(*db_, key_, *lease, uuid(account),
auto* db = db_->get();
if (!db)
return std::unexpected(ControlLedgerError::unavailable);
const auto claimed = persistence::claim_account_control(*db, key_, *lease, uuid(account),
serial, session, duration_, timeout_);
if (!claimed)
if (!claimed) {
note(*db_, claimed.error().kind);
return std::unexpected(ledger_error(claimed.error().kind));
}
return network::ControlLease{claimed->generation, claimed->wait, claimed->granted};
}
@@ -40,18 +50,29 @@ PostgresControlLedger::renew(const network::AccountId& account, std::uint64_t ge
const auto lease = lease_();
if (!lease)
return std::unexpected(ControlLedgerError::fenced);
const auto renewed = persistence::renew_account_control(*db_, key_, *lease, uuid(account),
auto* db = db_->get();
if (!db)
return std::unexpected(ControlLedgerError::unavailable);
const auto renewed = persistence::renew_account_control(*db, key_, *lease, uuid(account),
generation, duration_, timeout_);
if (!renewed)
if (!renewed) {
note(*db_, renewed.error().kind);
return std::unexpected(ledger_error(renewed.error().kind));
}
return *renewed;
}
void PostgresControlLedger::release(const network::AccountId& account, std::uint64_t generation) {
// Best effort: an unreleased control simply expires; a fenced one already moved on.
if (const auto lease = lease_())
(void)persistence::release_account_control(*db_, key_, *lease, uuid(account), generation,
timeout_)
.has_value();
const auto lease = lease_();
if (!lease)
return;
auto* db = db_->get();
if (!db)
return;
if (const auto released = persistence::release_account_control(*db, key_, *lease, uuid(account),
generation, timeout_);
!released)
note(*db_, released.error().kind);
}
} // namespace evo::server
+9 -1
View File
@@ -208,7 +208,15 @@ void serials_takeover_and_fencing() {
#ifdef EVO_POSTGRES_SESSIONS
// The session layer's ledger over these functions.
std::optional<LeaseGrant> current = restarted;
evo::server::PostgresControlLedger ledger{*db, a, [&] { return current; }};
evo::server::PgSlot slot{PgOptions{env("PGHOST"),
{},
env("PGPORT"),
env("PGDATABASE"),
env("EVO_PG_RUNTIME_USER"),
{},
{}},
5s};
evo::server::PostgresControlLedger ledger{slot, a, [&] { return current; }};
evo::network::AccountId dave;
dave.bytes = id(0x35);
auto claimed = ledger.claim(dave, 1, 9);
+24 -5
View File
@@ -491,8 +491,19 @@ void durable_actions() {
CHECK(b.query(1, {99}, f).result == ActionResult::unknown);
}
// The watermark sent to one session, if any.
std::optional<SimulatedThrough>
mark_of(const std::vector<std::pair<std::uint64_t, SimulatedThrough>>& marks,
std::uint64_t session) {
for (const auto& [s, m] : marks)
if (s == session)
return m;
return std::nullopt;
}
void intent_admission() {
IntentLimits limits;
limits.watermark_every = 20; // Exercise the repeat interval.
limits.max_unresolved = 6;
limits.max_finals = 4;
CHECK(refused(IntentAdmission::create(IntentLimits{0}), IntentConfigError::invalid));
@@ -526,15 +537,23 @@ void intent_admission() {
// Simulated watermark: only intentions whose tick ran, cumulatively.
f.server_tick = 109;
auto marks = a.simulated(f);
CHECK(marks.size() == 1 && marks[0].first == 1 &&
marks[0].second == SimulatedThrough{5, 2, 109});
CHECK(a.simulated(f).empty()); // Unchanged: not repeated yet.
CHECK(mark_of(marks, 1) == SimulatedThrough{5, 2, 109});
CHECK(mark_of(marks, 2) == SimulatedThrough{5, 0, 109}); // Bob: the tick, no intention.
CHECK(a.simulated(f).empty()); // Unchanged: not repeated yet.
f.server_tick = 110;
marks = a.simulated(f);
CHECK(marks.size() == 1 && marks[0].second.sequence == 3);
CHECK(marks.size() == 1 && mark_of(marks, 1) == SimulatedThrough{5, 3, 110}); // Bob: not
// repeated.
f.server_tick = 130;
marks = a.simulated(f); // Repeated after 20 ticks so a lost datagram is covered.
CHECK(marks.size() == 1 && marks[0].second == SimulatedThrough{5, 3, 130});
CHECK(mark_of(marks, 1) == SimulatedThrough{5, 3, 130} &&
mark_of(marks, 2) == SimulatedThrough{5, 0, 130});
// By default every session hears every simulated tick.
auto every = *IntentAdmission::create(IntentLimits{});
CHECK(every.open(7, alice));
for (std::uint64_t tick = 1; tick <= 3; ++tick)
CHECK(mark_of(every.simulated({true, 5, tick}), 7) == SimulatedThrough{5, 0, tick});
CHECK(every.simulated({true, 5, 3}).empty());
// Actions: receipt, carried with its tick's batch, final after the commit.
const auto action = [&](std::uint64_t session, std::uint64_t id, std::uint64_t tick,
+6
View File
@@ -12,6 +12,9 @@ void run_region_server_process_tests();
#ifdef EVO_POSTGRES_SESSIONS
void run_region_session_tests();
#endif
#ifdef EVO_POSTGRES_M10
void run_region_m10_session_tests();
#endif
void run_region_recovery_tests();
void run_region_ops_tests();
void run_region_clone_tests();
@@ -130,6 +133,9 @@ int main() {
#ifdef EVO_POSTGRES_SESSIONS
run_region_session_tests();
std::puts("region dev session integration passed");
#endif
#ifdef EVO_POSTGRES_M10
run_region_m10_session_tests();
#endif
run_region_recovery_tests();
std::puts("region recovery integration passed");
+6 -3
View File
@@ -378,11 +378,14 @@ void intentions_and_actions(const Files& f) {
auto a = h.connect(h.issuer.grant(alice, 1));
CHECK(h.settled(*a) && must(a->welcome()).server_tick == 100 && a->server_tick() == 100);
// Intention: a receipt, then the simulated watermark once its tick runs.
CHECK(a->send_intention(101, 10, -10) == 1u);
// Datagrams may be refused until the QUIC datagram extension is negotiated: retry.
std::optional<std::uint64_t> first;
CHECK(h.until([&] { return (first = a->send_intention(101, 10, -10)).has_value(); }));
CHECK(first == 1u);
std::vector<IntentionReceipt> receipts;
CHECK(h.until([&] { return !(receipts = a->take_intention_receipts()).empty(); }));
CHECK(receipts[0] == IntentionReceipt{1, AdmitStatus::admitted, 100});
CHECK(!a->simulated());
CHECK(a->simulated().value_or(SimulatedThrough{}).sequence == 0); // Ticks only, so far.
CHECK(a->send_intention(150, 0, 0) == 2u);
CHECK(h.until([&] { return !(receipts = a->take_intention_receipts()).empty(); }));
CHECK(receipts[0].status == AdmitStatus::outside_window);
@@ -434,7 +437,7 @@ void intentions_and_actions(const Files& f) {
CHECK(h.until([&] { return !(outcomes = c->take_action_outcomes()).empty(); }));
CHECK(outcomes[0].result == ActionResult::not_committed);
// Intentions of an old epoch are refused.
CHECK(c->send_intention(h.tick + 1, 0, 0));
CHECK(h.until([&] { return c->send_intention(h.tick + 1, 0, 0).has_value(); }));
CHECK(h.until([&] { return !(receipts = c->take_intention_receipts()).empty(); }));
CHECK(receipts[0].status == AdmitStatus::admitted); // c is in epoch 6.
+2 -1
View File
@@ -228,7 +228,8 @@ void store_rules() {
#ifdef EVO_POSTGRES_SESSIONS
// The session layer's ledger over the same lookup.
std::optional<LeaseGrant> current = *later;
PostgresActionLedger ledger{*db, r.key, [&] { return current; }};
PgSlot slot{options(env("EVO_PG_RUNTIME_USER")), 5s};
PostgresActionLedger ledger{slot, r.key, [&] { return current; }};
evo::network::AccountId who;
who.bytes = alice;
CHECK(holds(ledger.find(who, 3),
+308
View File
@@ -0,0 +1,308 @@
// Real process tests for M10.4c (ADR-0091, ADR-0092): evo-server with PostgreSQL, synthetic
// ticks and the QUIC session listener; in-process RegionSessionClients and the headless
// probe. Intentions get receipts and the simulated watermark; actions get durable outcomes
// that survive SIGKILL after their commit, and resolve as "no record" (then commit once on
// retry) after SIGKILL before it. Region 7/151. Run by tools/ci/postgres-check.sh
// when the build has EVO_BUILD_QUIC.
#include "evo/client/region_session.hpp"
#include "evo/network/dev_credentials.hpp"
#include "evo/network/session_grant.hpp"
#include "fixtures/server_process.hpp"
#include <fcntl.h>
#include <functional>
#include <optional>
#include <source_location>
#include <thread>
#include <unistd.h>
void run_region_m10_session_tests();
namespace {
using namespace evo::test::process;
using namespace evo;
using namespace evo::network;
using client::RegionSessionClient;
using client::RegionSessionState;
using evo::test::region_identity;
void check(bool value, std::source_location at = std::source_location::current()) {
if (!value)
throw std::runtime_error("region m10 session test line " + std::to_string(at.line()));
}
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
template <typename T>
const T& must(const std::optional<T>& o,
std::source_location at = std::source_location::current()) {
if (!o)
throw std::runtime_error("region m10 session missing value line " +
std::to_string(at.line()));
return *o;
}
constexpr const char* name = "dev-region.evolution.test";
void write_file(const fs::path& path, std::span<const std::uint8_t> bytes) {
const int fd = ::open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600);
expect(fd >= 0 &&
::write(fd, bytes.data(), bytes.size()) == static_cast<ssize_t>(bytes.size()) &&
::close(fd) == 0,
"write file");
}
void write_text(const fs::path& path, const std::string& text) {
write_file(path, {reinterpret_cast<const std::uint8_t*>(text.data()), text.size()});
}
AccountId account(std::uint8_t tag) {
AccountId a;
a.bytes.fill(tag);
return a;
}
std::string hex(const AccountId& a) {
constexpr char digits[] = "0123456789abcdef";
std::string out;
for (const auto b : a.bytes) {
out.push_back(digits[b >> 4U]);
out.push_back(digits[b & 0xFU]);
}
return out;
}
// One region's credentials, issuer key and server process arguments.
struct Setup {
ServerRegion region;
std::string ca_pem;
std::optional<GrantSigningKey> issuer;
explicit Setup(std::uint64_t r, std::uint8_t genesis) : region{provision(r, genesis)} {
const auto made = generate_dev_credentials(DeploymentEnvironment::dev, name, 1,
std::chrono::system_clock::now());
expect(made.has_value(), "credentials");
ca_pem = made->authority_pem;
write_text(region.root / "ca.pem", made->authority_pem);
write_text(region.root / "server.pem", made->server_certificate_pem);
write_text(region.root / "server.key", made->server_key_pem);
for (int attempt = 0; attempt < 8 && !issuer; ++attempt) {
std::array<std::uint8_t, grant_private_key_bytes> scalar{};
expect(random_bytes(scalar).has_value(), "random");
if (auto key = GrantSigningKey::import(DeploymentEnvironment::dev, 1, scalar)) {
write_file(region.root / "issuer.key", scalar);
write_file(region.root / "issuer.pub", *key->public_key());
issuer.emplace(std::move(*key));
}
}
expect(issuer.has_value(), "issuer key");
}
[[nodiscard]] std::vector<std::string> args() const {
return server_args(region,
{"--synthetic-inputs", "development-v1", "--m10-listen", "127.0.0.1:0",
"--m10-cert", (region.root / "server.pem").string(), "--m10-key",
(region.root / "server.key").string(), "--m10-issuer",
(region.root / "issuer.pub").string(), "--m10-environment", "dev"});
}
[[nodiscard]] WireGrant grant(const AccountId& who, std::uint64_t serial) const {
GrantClaims c;
c.grant_id = 9000 + serial;
c.account = who;
c.serial = serial;
c.world = {region.key.world, region_identity.frame};
c.region = region.key.region;
c.issued_at =
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
c.expires_at = c.issued_at + 120;
const auto g = must(issuer).sign(c);
expect(g.has_value(), "grant");
return *g;
}
};
// A running evo-server and its QUIC port, its output drained while waiting.
struct Server {
std::unique_ptr<Child> child;
std::uint16_t port{};
explicit Server(const Setup& s) : child{std::make_unique<Child>(s.args())} {
CHECK(child->wait_line("m10 listening ", 30s));
for (const auto& l : child->lines())
if (starts(l, "m10 listening "))
port = static_cast<std::uint16_t>(std::stoul(l.substr(14)));
CHECK(port != 0 && child->wait_line("ready 1", 30s));
}
void pump() {
child->pump(1ms);
}
void kill() {
child->signal(SIGKILL);
CHECK(child->wait_exit(30s) == 128 + SIGKILL);
}
};
std::unique_ptr<RegionSessionClient> connect(const Setup& s, Server& server,
const WireGrant& grant) {
client::RegionSessionClientConfig c;
c.transport.port = server.port;
c.transport.server_name = name;
c.transport.authority_pem = s.ca_pem;
c.transport.authority_pem_file = (s.region.root / "ca.pem").string();
c.grant = grant;
auto made = RegionSessionClient::connect(std::move(c), std::chrono::steady_clock::now());
CHECK(made.has_value());
return std::move(*made);
}
// Polls client and server until `done`, at most `limit`.
bool until(Server& server, RegionSessionClient& c, const std::function<bool()>& done,
std::chrono::milliseconds limit = 20s) {
const auto end = Clock::now() + limit;
while (Clock::now() < end) {
c.poll(Clock::now());
server.pump();
if (done())
return true;
}
return done();
}
bool established(Server& server, RegionSessionClient& c) {
return until(server, c,
[&] {
return c.state() == RegionSessionState::established ||
c.state() == RegionSessionState::closed;
}) &&
c.state() == RegionSessionState::established;
}
std::optional<ActionOutcome> outcome_of(Server& server, RegionSessionClient& c, std::uint64_t id,
bool final_only) {
std::optional<ActionOutcome> found;
until(server, c, [&] {
for (const auto& o : c.take_action_outcomes())
if (o.action_id == id &&
(!final_only || o.result == ActionResult::committed_no_effect ||
o.result == ActionResult::not_committed))
found = o;
return found.has_value();
});
return found;
}
std::optional<ActionReceipt> receipt_of(Server& server, RegionSessionClient& c, std::uint64_t id) {
std::optional<ActionReceipt> found;
until(server, c, [&] {
for (const auto& r : c.take_action_receipts())
if (r.action_id == id)
found = r;
return found.has_value();
});
return found;
}
// "tick:commit" of the durable record of (account, id) in world 7, or empty.
std::string record(const AccountId& who, std::uint64_t id) {
const std::array<std::string, 2> p{hex(who), std::to_string(id)};
auto rows =
owner()->query("SELECT tick || ':' || commit_sequence FROM evolution.region_actions "
"WHERE world_id = 7 AND account_id = $1::uuid AND "
"action_id = $2::evolution.u64",
p, 5s);
CHECK(rows.has_value());
return rows->empty() ? std::string{} : (*rows)[0][0].value_or("");
}
void end_to_end() {
Setup s{151, 0xC5};
const auto alice = account(0x51), bob = account(0x52);
auto server = std::make_unique<Server>(s);
auto a = connect(s, *server, s.grant(alice, 1));
CHECK(established(*server, *a));
// Intentions: receipts, then the watermark.
// Datagrams may be refused until the QUIC datagram extension is negotiated: retry.
std::optional<std::uint64_t> sequence;
CHECK(until(*server, *a, [&] {
return a->server_tick() > 0 &&
(sequence = a->send_intention(a->server_tick() + 2, 100, 0)).has_value();
}));
CHECK(sequence == 1u);
std::vector<IntentionReceipt> receipts;
CHECK(until(*server, *a, [&] { return !(receipts = a->take_intention_receipts()).empty(); }));
CHECK(receipts[0].sequence == 1 && receipts[0].status == AdmitStatus::admitted);
CHECK(until(*server, *a, [&] { return a->simulated() && a->simulated()->sequence >= 1; }));
// Action: receipt, then a final outcome naming the durable commit.
CHECK(a->send_action(1, ActionKind::probe, a->server_tick() + 3));
const auto r1 = receipt_of(*server, *a, 1);
CHECK(r1 && must(r1).status == AdmitStatus::admitted);
const auto o1 = outcome_of(*server, *a, 1, true);
CHECK(o1 && must(o1).result == ActionResult::committed_no_effect &&
must(o1).tick == must(r1).tick && must(o1).commit_sequence > 0);
CHECK(record(alice, 1) ==
std::to_string(must(o1).tick) + ":" + std::to_string(must(o1).commit_sequence));
// SIGKILL after the commit (the record exists), whether or not the outcome was sent.
CHECK(a->send_action(2, ActionKind::probe, a->server_tick() + 3));
const auto r2 = receipt_of(*server, *a, 2);
CHECK(r2 && must(r2).status == AdmitStatus::admitted);
const bool recorded = until(*server, *a, [&] { return !record(alice, 2).empty(); });
if (!recorded)
for (const auto& line : server->child->lines())
if (starts(line, "m10") || starts(line, "phase") || starts(line, "dropped"))
std::printf("server: %s\n", line.c_str());
CHECK(recorded);
server->kill();
server = std::make_unique<Server>(s); // Waits out the old lease.
auto b = connect(s, *server, s.grant(alice, 2));
CHECK(established(*server, *b));
CHECK(b->query_action(2));
const auto o2 = outcome_of(*server, *b, 2, false);
CHECK(o2 && must(o2).result == ActionResult::committed_no_effect &&
record(alice, 2) ==
std::to_string(must(o2).tick) + ":" + std::to_string(must(o2).commit_sequence));
// A retry of a committed action on the new process: duplicate, same outcome.
CHECK(b->send_action(1, ActionKind::probe, b->server_tick() + 3));
const auto d1 = receipt_of(*server, *b, 1);
CHECK(d1 && must(d1).status == AdmitStatus::duplicate && must(d1).tick == must(o1).tick);
CHECK(outcome_of(*server, *b, 1, true) == o1);
// SIGKILL before the commit: the action's tick has not run when the process dies.
CHECK(b->send_action(3, ActionKind::probe, b->server_tick() + 8));
const auto r3 = receipt_of(*server, *b, 3);
CHECK(r3 && must(r3).status == AdmitStatus::admitted);
server->kill();
CHECK(record(alice, 3).empty());
server = std::make_unique<Server>(s);
auto c = connect(s, *server, s.grant(alice, 3));
CHECK(established(*server, *c));
CHECK(c->query_action(3));
const auto unknown = outcome_of(*server, *c, 3, false);
CHECK(unknown && unknown->result == ActionResult::unknown); // No record: never committed.
CHECK(c->send_action(3, ActionKind::probe, c->server_tick() + 3)); // Safe to retry.
CHECK(must(receipt_of(*server, *c, 3)).status == AdmitStatus::admitted);
const auto o3 = outcome_of(*server, *c, 3, true);
CHECK(o3 && must(o3).result == ActionResult::committed_no_effect && !record(alice, 3).empty());
// The headless probe: login, intentions, actions and a query, then a clean exit.
const auto probe = fs::path(env("EVO_SERVER_BIN")).parent_path() / "evo-session-probe";
Child p{{probe.string(), "run",
"--connect", "127.0.0.1:" + std::to_string(server->port),
"--server-name", name,
"--ca", (s.region.root / "ca.pem").string(),
"--issuer-key", (s.region.root / "issuer.key").string(),
"--world", "7",
"--frame", std::to_string(region_identity.frame),
"--region", "151",
"--account", hex(bob),
"--serial", "1",
"--intents", "3",
"--actions", "2",
"--action-base", "10",
"--query", "10"}};
int code = -1;
for (const auto end = Clock::now() + 30s; Clock::now() < end && code < 0;) {
server->pump();
p.pump(5ms);
if (p.printed("done") || p.printed("timeout") || p.printed("closed"))
code = p.wait_exit(10s);
}
CHECK(code == 0 && p.printed("welcome ") && p.printed("intention 1 0") &&
p.printed("outcome 10 1 ") && p.printed("outcome 11 1 "));
CHECK(!record(bob, 10).empty() && !record(bob, 11).empty());
server->child->signal(SIGTERM);
CHECK(server->child->wait_exit(30s) == 0);
CHECK(server->child->printed("m10 opened ") && server->child->printed("m10 committed "));
}
} // namespace
void run_region_m10_session_tests() {
end_to_end();
std::puts("region m10 session integration passed");
}