Add cellular profile region serving
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (ecs) (push) Successful in 1m57s
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 (client) (push) Canceled after 2m58s
Foundation / checks (postgres) (push) Canceled after 52s
Foundation / checks (network) (push) Canceled after 2m23s

This commit is contained in:
dingo
2026-10-11 01:03:05 -04:00
parent ad6f0ff78a
commit 10b042309e
8 changed files with 423 additions and 3 deletions
+2 -1
View File
@@ -263,7 +263,8 @@ if(EVO_BUILD_POSTGRES)
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_link_libraries(evo-server PRIVATE evo_session_server evo_control_ledger_postgres
evo_cellular_session_adapter)
target_compile_definitions(evo-server PRIVATE EVO_SERVER_M10=1)
endif()
evo_owned_target(evo-server)
+199
View File
@@ -0,0 +1,199 @@
#pragma once
#include "evo/client/organism_view.hpp"
#include "evo/network/session_grant.hpp"
#include "evo/server/cellular_region_host.hpp"
#include "evo/server/pg_slot.hpp"
#include "evo/server/postgres_action_ledger.hpp"
#include "evo/server/postgres_control_ledger.hpp"
#include "evo/server/region_sessions.hpp"
#include "evo/server/session_window.hpp"
#include "m10_bridge.hpp"
#include <algorithm>
#include <array>
#include <charconv>
#include <chrono>
#include <cstdio>
#include <fstream>
#include <iterator>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <vector>
namespace evo::server_app {
// Profile-4 network boundary. Biology and persistence remain owned by the cellular host;
// this bridge handles admission, v7 action receipts and read-only replicated cell views.
class CellularBridge {
public:
static std::optional<CellularBridge>
open(const M10Options& options, server::CellularRegionHost& host,
persistence::RegionKey key, std::uint64_t frame, const persistence::PgOptions& pg) {
if (!options.complete())
return fail("error cellular-session-config");
CellularBridge bridge;
const auto window = server::SessionWindow::open(options.session_window, wall_seconds());
if (!window)
return fail("error cellular-session-window");
const auto colon = options.listen.rfind(':');
std::uint16_t port{};
if (colon == std::string::npos ||
std::from_chars(options.listen.data() + colon + 1,
options.listen.data() + options.listen.size(), port)
.ec != std::errc{})
return fail("error cellular-session-listen");
const auto issuer = read(options.issuer);
if (issuer.size() != network::grant_public_key_bytes)
return fail("error cellular-session-issuer");
server::RegionSessionsConfig config;
config.transport.listen_address = options.listen.substr(0, colon);
config.transport.port = port;
config.transport.certificate_pem_file = options.certificate;
config.transport.key_pem_file = options.key;
config.control.environment = options.environment == "dev"
? network::DeploymentEnvironment::dev
: options.environment == "stage"
? network::DeploymentEnvironment::stage
: network::DeploymentEnvironment::world0;
config.control.world = {key.world, frame};
config.control.region = key.region;
config.control.epoch = 1;
config.control.max_sessions = 512;
config.transport.limits.max_connections = 576;
network::GrantPublicKey public_key{};
std::copy(issuer.begin(), issuer.end(), public_key.begin());
config.issuer_keys.push_back({1, public_key});
bridge.window_ = *window;
bridge.slot_ = std::make_unique<server::PgSlot>(pg, std::chrono::seconds{2});
const auto lease = [&host] { return host.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();
config.accept_cellular_actions = true;
config.create_primitive_life = [&host](const network::AccountId& account,
std::uint64_t generation,
std::uint64_t request) {
return host.create_primitive_life(account.bytes, generation, request);
};
config.query_primitive_life = [&host](const network::AccountId& account,
std::uint64_t generation,
std::uint64_t request) {
return host.query_primitive_life(account.bytes, generation, request);
};
auto sessions = server::RegionSessions::create(std::move(config));
if (!sessions)
return fail(sessions.error() == server::RegionSessionsError::transport
? "error cellular-session-listen"
: "error cellular-session-config");
bridge.sessions_ = std::move(*sessions);
bridge.sessions_->set_default_interest({0, 0, 0, 7});
std::printf("cellular listening %u\n", static_cast<unsigned>(bridge.sessions_->port()));
return std::optional<CellularBridge>{std::move(bridge)};
}
[[nodiscard]] bool accepting(std::uint64_t now_seconds) {
const bool open = window_ && window_->accepting(now_seconds);
if (!open && !shutdown_) {
sessions_->shutdown(std::chrono::steady_clock::now());
shutdown_ = true;
}
return open;
}
[[nodiscard]] server::RegionSessions& sessions() noexcept {
return *sessions_;
}
[[nodiscard]] std::vector<network::CarriedAction> carry(std::uint64_t tick) {
return sessions_->carry(tick);
}
void committed(std::span<const network::CarriedAction> actions, std::uint64_t sequence) {
sessions_->committed(actions, sequence);
}
void dropped(std::span<const network::CarriedAction> actions, bool final) {
sessions_->dropped(actions, final);
}
void poll(const server::HostStatus& status, std::uint64_t now_seconds) {
sessions_->poll({status.ready, status.epoch, status.simulated_tick}, now_seconds,
std::chrono::steady_clock::now());
for (const auto& event : sessions_->take_events())
std::printf("cellular %s session=%llu account=%s reason=%u\n",
event.kind == server::RegionSessionEvent::Kind::opened ? "opened"
: event.kind == server::RegionSessionEvent::Kind::closed ? "closed"
: "refused",
static_cast<unsigned long long>(event.session), event.account.c_str(),
static_cast<unsigned>(event.reason));
}
void replicate(const server::CellularLives& state) {
const auto tick = state.tick();
if (replicated_tick_ == tick)
return;
const auto source = [&](const network::SessionInterest& interest) {
network::ReplicationSource result;
result.identity = {state.world(), state.frame()};
result.organism_revision = tick;
for (const auto& life : state.lives()) {
const auto voxel_x = life.position.x_um / 1'000'000;
const auto voxel_y = life.position.y_um / 1'000'000;
if (voxel_x >
static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max()) ||
voxel_y > static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max()))
continue;
const world::VoxelAddress voxel{static_cast<std::int64_t>(voxel_x),
static_cast<std::int64_t>(voxel_y), 0};
if (voxel.x < interest.x - interest.radius ||
voxel.x > interest.x + interest.radius ||
voxel.y < interest.y - interest.radius ||
voxel.y > interest.y + interest.radius)
continue;
const auto genome = state.archive().find(life.identity.genome);
if (!genome)
continue;
const biology::EnvironmentState environment{
state.ambient_temperature_millikelvin(), life.reserve};
auto cell = client::present_organism(
life.identity.organism, voxel,
{life.position.x_um % 1'000'000}, {life.position.y_um % 1'000'000}, *genome,
life.growth, environment, client::OrganismState::alive);
if (cell)
result.organisms.push_back(*cell);
}
std::ranges::sort(result.organisms, {}, &client::OrganismCell::id);
return result;
};
sessions_->replicate(tick, source);
replicated_tick_ = tick;
}
void shutdown() {
sessions_->shutdown(std::chrono::steady_clock::now());
}
private:
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::string read(const std::string& path) {
std::ifstream file{path, std::ios::binary};
return {std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}};
}
static std::optional<CellularBridge> fail(const char* message) {
std::puts(message);
return std::nullopt;
}
std::unique_ptr<server::PgSlot> slot_;
std::unique_ptr<server::PostgresControlLedger> control_;
std::unique_ptr<server::PostgresActionLedger> actions_;
std::unique_ptr<server::RegionSessions> sessions_;
std::optional<server::SessionWindow> window_;
std::optional<std::uint64_t> replicated_tick_;
bool shutdown_{};
};
} // namespace evo::server_app
+198 -2
View File
@@ -54,6 +54,7 @@
// provisioning remain disabled.
#include "evo/biology/founder.hpp"
#include "evo/processes/development_opening.hpp"
#include "evo/server/cellular_session_batch.hpp"
#include "evo/server/lifecycle/primitive_lives.hpp"
#include "evo/server/ops_http.hpp"
#include "evo/server/primitive_region_host.hpp"
@@ -61,6 +62,7 @@
#include "m10_bridge.hpp"
#include "session_bridge.hpp"
#ifdef EVO_SERVER_M10
#include "cellular_bridge.hpp"
#include "evo/server/pg_slot.hpp"
#include "evo/server/postgres_control_ledger.hpp"
#include "evo/server/region_sessions.hpp"
@@ -170,7 +172,8 @@ std::optional<Options> parse(int argc, char** argv) {
const std::string_view value = argv[++i];
const auto n = number(value);
if (flag == "--profile" &&
(value == "lineage" || value == "environmental" || value == "primitive"))
(value == "lineage" || value == "environmental" || value == "primitive" ||
value == "cellular"))
o.profile = value;
else if (flag == "--world" && n)
o.host.key.world = *n;
@@ -316,6 +319,13 @@ std::optional<Options> parse(int argc, char** argv) {
(o.synthetic || !o.crash_point.empty() || o.session.any() || o.m10.any() ||
o.host.flush_interval != 1000ms || o.drain != 10000ms))
return std::nullopt;
if (o.profile == "cellular" &&
(!server_app::m10_available || !o.m10.complete() || o.primitive_session.any() ||
o.synthetic || !o.crash_point.empty() || o.session.any() ||
!o.m10.area.empty() || !o.m10.handoff_key.empty() || !o.m10.neighbours.empty() ||
o.m10.max_grant_lifetime != 0 || !o.m10.load_governor ||
o.host.flush_interval != 1000ms || o.drain != 10000ms))
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;
@@ -870,13 +880,195 @@ int serve_primitive(Options& o) {
std::this_thread::sleep_for(5ms);
}
}
#ifdef EVO_SERVER_M10
int serve_cellular(Options& o) {
auto objects = persistence::FilesystemObjectStore::open(
o.objects, o.host.key, server::max_cellular_lives_bytes, nullptr,
o.objects_reserve_mib * 1024 * 1024);
if (!objects) {
std::puts("error objects");
return 2;
}
const auto pg = o.pg;
auto made = server::CellularRegionHost::create(
{o.host.key, o.host.frame, o.host.lease, o.host.build, o.host.retained_builds},
[pg] { return persistence::Postgres::connect(pg, 2s); }, std::move(*objects));
if (!made) {
std::puts("error config");
return 2;
}
auto& host = **made;
auto bridge = server_app::CellularBridge::open(o.m10, host, o.host.key, o.host.frame, o.pg);
if (!bridge)
return 2;
std::unique_ptr<server::OpsServer> ops;
if (!o.ops_listen.empty()) {
auto listening = server::OpsServer::listen(o.ops_listen);
if (!listening) {
std::puts("error ops-listen");
return 2;
}
ops = std::move(*listening);
std::printf("ops listening %u\n", static_cast<unsigned>(ops->port()));
}
bool ready = false;
std::optional<server::HostPhase> phase;
std::optional<std::chrono::steady_clock::time_point> next_tick;
std::vector<network::CarriedAction> awaiting_outcomes;
const auto set_ready = [&](bool now) {
if (ready != now) {
ready = now;
std::printf("ready %d\n", ready ? 1 : 0);
}
if (!o.ready_file.empty()) {
std::error_code ignored;
if (ready)
std::ofstream(o.ready_file) << "ready\n";
else
std::filesystem::remove(o.ready_file, ignored);
}
};
const auto deliver_finalized = [&] {
for (const auto& finalized : host.take_finalized_actions()) {
const auto pending = std::ranges::find_if(awaiting_outcomes, [&](const auto& action) {
return action.account.bytes == finalized.action.account &&
action.action_id == finalized.action.action_id;
});
if (pending == awaiting_outcomes.end())
continue;
const std::array committed{*pending};
bridge->committed(committed, finalized.commit_sequence);
awaiting_outcomes.erase(pending);
}
};
const auto finish = [&](int code) {
set_ready(false);
const auto& status = host.status();
std::printf("phase %s epoch=%llu committed=%llu simulated=%llu\n",
server::phase_name(status.phase),
static_cast<unsigned long long>(status.epoch),
static_cast<unsigned long long>(status.committed_tick),
static_cast<unsigned long long>(status.simulated_tick));
std::printf("stats commits=%llu store_failures=%llu\n",
static_cast<unsigned long long>(status.commits),
static_cast<unsigned long long>(status.store_failures));
std::printf("exit %d\n", code);
std::fflush(stdout);
return code;
};
for (;;) {
if (stop_requested) {
bridge->shutdown();
host.drain();
return finish(0);
}
const auto& status = host.step();
const auto wall = static_cast<std::uint64_t>(
std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
static_cast<void>(bridge->accepting(wall));
bridge->poll(status, wall);
deliver_finalized();
set_ready(status.ready);
if (!phase || *phase != status.phase) {
phase = status.phase;
std::printf("phase %s epoch=%llu committed=%llu simulated=%llu\n",
server::phase_name(status.phase),
static_cast<unsigned long long>(status.epoch),
static_cast<unsigned long long>(status.committed_tick),
static_cast<unsigned long long>(status.simulated_tick));
}
if (ops) {
const auto handler = [&](std::string_view path) -> server::OpsResponse {
const auto& current = host.status();
if (path == "/livez")
return {200, "live\n"};
if (path == "/readyz")
return current.ready ? server::OpsResponse{200, "ready\n"}
: server::OpsResponse{
503, std::string("not ready: ") +
server::phase_name(current.phase) + "\n"};
if (path == "/metrics")
return {200, server::render_metrics(current, {})};
return {404, "not found\n"};
};
ops->serve(handler);
}
if (status.phase == server::HostPhase::quarantined)
return finish(4);
const auto* state = host.state();
bool player_present = false;
if (status.ready && state) {
for (const auto& life : state->lives()) {
network::AccountId account;
account.bytes = life.account;
if (bridge->sessions().holder(account)) {
player_present = true;
break;
}
}
}
const bool birth_waiting = !host.queued_births().empty();
if (status.ready && state && (player_present || birth_waiting)) {
const auto now = std::chrono::steady_clock::now();
if (!next_tick)
next_tick = now + std::chrono::milliseconds{50};
if (now >= *next_tick && state->tick() != UINT64_MAX) {
const auto tick = state->tick() + 1;
std::vector<server::CellularLifeIntent> baseline;
baseline.reserve(state->lives().size());
for (const auto& life : state->lives())
baseline.push_back({life.identity.life, {}});
std::ranges::sort(baseline, {}, &server::CellularLifeIntent::life_id);
auto actions = bridge->carry(tick);
auto builder = server::CellularSessionBatchBuilder::create(
*state, host.committed()->head);
if (!builder) {
bridge->dropped(actions, true);
} else {
const auto births = host.queued_births().first(
std::min(host.queued_births().size(), biology::max_cellular_tick_lives));
const auto appended = builder->append(tick, baseline, actions, births);
if (!appended) {
bridge->dropped(actions, true);
} else {
awaiting_outcomes.insert(awaiting_outcomes.end(), actions.begin(),
actions.end());
auto published = host.publish(builder->batch(), builder->actions());
if (!published && host.status().phase != server::HostPhase::resolving) {
bridge->dropped(actions, true);
std::erase_if(awaiting_outcomes, [&](const auto& action) {
return std::ranges::find(actions, action) != actions.end();
});
}
deliver_finalized();
}
}
*next_tick = std::chrono::steady_clock::now() + std::chrono::microseconds{
static_cast<std::chrono::microseconds::rep>(
biology::cellular_motion_tick_microseconds)};
}
} else {
next_tick.reset(); // A disconnected life does not accumulate offline ticks.
}
if (const auto* committed_state = host.state(); committed_state)
bridge->replicate(*committed_state);
std::fflush(stdout);
std::this_thread::sleep_for(2ms);
}
}
#endif
} // namespace
int main(int argc, char** argv) {
auto options = parse(argc, argv);
if (!options) {
std::fputs(
"usage: evo-server --profile lineage|environmental|primitive --world N --region N "
"usage: evo-server --profile lineage|environmental|primitive|"
"cellular --world N --region N "
"--frame N --pg-host H --pg-port P --pg-database D --pg-user U "
"--objects DIR --build HEX64 [--retained HEX64]... [--pg-hostaddr A "
"--pg-passfile F --pg-ca F] [--flush-ms N] [--drain-ms N] "
@@ -904,6 +1096,10 @@ int main(int argc, char** argv) {
std::signal(SIGPIPE, SIG_IGN);
if (options->profile == "primitive")
return serve_primitive(*options);
#ifdef EVO_SERVER_M10
if (options->profile == "cellular")
return serve_cellular(*options);
#endif
return options->profile == "lineage" ? serve<processes::LineageRegion>(*options)
: serve<processes::EnvironmentalCommunity>(*options);
}
+7
View File
@@ -346,6 +346,13 @@ scoped change before starting the next segment.
interest, in addition to committing cellular actions. QUIC coverage confirms
a v7 client can receive a cell entity and move its focus. The process-level
cellular tick loop and resource patch view are still required before 11.3e.
- 11.3d-7n: `evo-server --profile cellular` now has a profile-4 serve path,
durable v5/v7 sessions, 50 ms host ticks, checkpointed carried actions and
live-cell replication. It pauses when no living account is connected and does
not accumulate catch-up ticks while offline. The path has not been compiled
with the Linux/PostgreSQL CMake preset or run against a region. Exact patch
perception and the engineering-client controls/view are still required for
the exploratory 11.3e playtest.
## Exit boundary
+12
View File
@@ -6487,3 +6487,15 @@ session, client session and QUIC test, and `git diff --check` passes. QUIC
runtime tests and CI remain pending. The configured Windows CMake QUIC target
produced no output for 25 seconds and was interrupted; it is not counted as a
build or test result.
## 2026-10-11 — M11.3d-7n cellular server process
The app now has an opt-in `--profile cellular` serve path with the M10 session
window, durable control/action ledgers, cellular ticks and cell snapshots. It
only advances while a living account has an established session or a first
birth is queued. The new bridge header passes GCC 13.2 strict-warning syntax
checking; the `CellularLives` accessor and tests pass strict-warning syntax
checking; `git diff --check` passes. The POSIX-only `evo-server/main.cpp` cannot
be compiled in this Windows environment (`poll.h` is unavailable). The
configured Windows CMake QUIC target previously stalled without output and was
interrupted. Linux/PostgreSQL CI and a real region run remain pending.
@@ -85,6 +85,7 @@ class CellularLives {
[[nodiscard]] std::uint64_t region() const noexcept;
[[nodiscard]] std::uint64_t frame() const noexcept;
[[nodiscard]] std::uint64_t tick() const noexcept;
[[nodiscard]] std::uint32_t ambient_temperature_millikelvin() const noexcept;
[[nodiscard]] biology::CellularArea area() const noexcept;
[[nodiscard]] std::span<const CellularOwnedLife> lives() const noexcept;
[[nodiscard]] std::span<const CellularOwnedCorpse> corpses() const noexcept;
+3
View File
@@ -379,6 +379,9 @@ std::uint64_t CellularLives::world() const noexcept { return state_->world; }
std::uint64_t CellularLives::region() const noexcept { return state_->region; }
std::uint64_t CellularLives::frame() const noexcept { return state_->frame; }
std::uint64_t CellularLives::tick() const noexcept { return state_->config.tick; }
std::uint32_t CellularLives::ambient_temperature_millikelvin() const noexcept {
return state_->config.ambient_temperature_millikelvin;
}
biology::CellularArea CellularLives::area() const noexcept { return state_->config.area; }
std::span<const CellularOwnedLife> CellularLives::lives() const noexcept { return state_->lives; }
std::span<const CellularOwnedCorpse> CellularLives::corpses() const noexcept {
+1
View File
@@ -53,6 +53,7 @@ std::unique_ptr<CellularLives> empty_cellular_owner(Inventory funding,
CHECK(habitat);
auto owner = CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150});
CHECK(owner);
CHECK((*owner)->ambient_temperature_millikelvin() == 293'150);
return std::move(*owner);
}