Implement M9.7 dev region sessions with durable no-effect intentions
Run a non-blocking TLS 1.3 session server inside evo-server's loop: environment views come from the region's own field/terrain stores with an explicitly empty organism presentation; admitted intentions ride the next synthetic input (content unchanged) and return a durable no-effect outcome from the host's final acknowledgement, or not_committed when dropped. Sessions are bound to their connection, epochs close stale sessions, and connections have bounded output, input rate and deadlines. SessionClient and evo-client --connect consume one single-use grant per Hello (refusals before admission keep it), reset to a fresh baseline on every session, keep stale views visible and report in-flight intentions as unknown after loss. evo-dev-session generates dev credentials, grant bundles and runs a restart probe. The dev deployment gains a drill-time, loopback-only listener with an optional Secret, enforced by the policy check, and tools/ops/session-drill.sh. Protocol v1 gains IntentOutcome and the capacity close reason before any deployment. ADR-0083 records the maintainer-confirmed decisions; M8-dev/stage remains not passed and no cluster change was made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+53
-14
@@ -2,6 +2,7 @@
|
||||
#include "evo/client/organism_inspector.hpp"
|
||||
#include "evo/render/environment.hpp"
|
||||
#include "evo/render/organism.hpp"
|
||||
#include "remote_session.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
@@ -23,10 +24,12 @@ constexpr std::int64_t fixture_z = -16000;
|
||||
// incident energy (never opened: missing). Unrequested fields draw hollow outlines.
|
||||
constexpr std::uint32_t fixture_mask = (1U << 0) | (1U << 1) | (1U << 2) | (1U << 7) | (1U << 8);
|
||||
constexpr unsigned frames_per_authority_tick = 60;
|
||||
// Frame composition: environment bound + organisms + inspector + 3 host UI rectangles.
|
||||
// Frame composition: environment bound + organisms + inspector + 5 host UI rectangles
|
||||
// (capture bar, intention dot, and in remote mode the connection and intent chips).
|
||||
constexpr std::size_t host_ui_rectangles = 5;
|
||||
constexpr std::size_t organism_budget = evo::render::max_rectangles -
|
||||
evo::render::max_environment_rectangles -
|
||||
evo::client::inspector_rectangles - 3;
|
||||
evo::client::inspector_rectangles - host_ui_rectangles;
|
||||
// Local in-memory stand-in for authoritative region views until M9.7. It is never
|
||||
// persisted or published; the client presentation only copies its read-only views.
|
||||
struct FixtureAuthority {
|
||||
@@ -175,12 +178,21 @@ int main(int argc, char** argv) try {
|
||||
unsigned frames = 0, refresh_every = 1;
|
||||
bool inspect = false;
|
||||
evo::render::EnvironmentDisplay display;
|
||||
evo::client_app::RemoteOptions remote_options;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
const std::string_view arg{argv[i]};
|
||||
if (arg == "--hidden")
|
||||
config.hidden = true;
|
||||
else if (arg == "--inspect")
|
||||
inspect = true;
|
||||
else if (arg == "--connect" && i + 1 < argc)
|
||||
remote_options.connect = argv[++i];
|
||||
else if (arg == "--server-name" && i + 1 < argc)
|
||||
remote_options.server_name = argv[++i];
|
||||
else if (arg == "--ca" && i + 1 < argc)
|
||||
remote_options.authority = argv[++i];
|
||||
else if (arg == "--grants" && i + 1 < argc)
|
||||
remote_options.grants = argv[++i];
|
||||
else if (arg == "--renderer" && i + 1 < argc)
|
||||
config.renderer = argv[++i];
|
||||
else if (arg == "--frames" && i + 1 < argc) {
|
||||
@@ -197,15 +209,36 @@ int main(int argc, char** argv) try {
|
||||
} else {
|
||||
std::fputs("usage: evo-client [--renderer NAME] [--hidden] [--frames 1..100000]\n"
|
||||
" [--layer water|nitrogen|...|heat|moisture]\n"
|
||||
" [--refresh-every 1..1000] [--inspect]\n",
|
||||
" [--refresh-every 1..1000] [--inspect]\n"
|
||||
" [--connect HOST:PORT --server-name NAME --ca FILE "
|
||||
"--grants FILE]\n",
|
||||
stderr);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
auto authority = make_authority();
|
||||
if (!authority) {
|
||||
std::fputs("client environment fixture error\n", stderr);
|
||||
return 1;
|
||||
// Remote mode (M9.7): views and intentions go through a dev session; the local
|
||||
// fixture authority is not created at all.
|
||||
std::optional<evo::client_app::RemoteSession> remote;
|
||||
if (remote_options.any()) {
|
||||
if (!evo::client_app::remote_available || !remote_options.complete()) {
|
||||
std::fputs("remote mode needs --connect, --server-name, --ca and --grants "
|
||||
"(and a build with EVO_BUILD_NETWORK)\n",
|
||||
stderr);
|
||||
return 2;
|
||||
}
|
||||
remote = evo::client_app::RemoteSession::open(remote_options);
|
||||
if (!remote) {
|
||||
std::fputs("client session configuration error\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
std::optional<FixtureAuthority> authority;
|
||||
if (!remote) {
|
||||
authority = make_authority();
|
||||
if (!authority) {
|
||||
std::fputs("client environment fixture error\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
evo::client::EnvironmentLayer environment;
|
||||
evo::client::OrganismLayer population;
|
||||
@@ -239,13 +272,15 @@ int main(int argc, char** argv) try {
|
||||
std::clamp(std::chrono::duration<double>(now - previous).count(), 0.0, 0.1);
|
||||
previous = now;
|
||||
const auto navigation = (*app)->take_navigation();
|
||||
// Fixture ticks only. No server session or simulation clock exists here.
|
||||
// Local input counter; in remote mode the session sets the server tick.
|
||||
const auto intention = (*app)->sample_intention(count);
|
||||
if (!intention)
|
||||
return 1;
|
||||
if (remote)
|
||||
remote->step(now, *intention);
|
||||
// The fixture authority advances at its own cadence. Presentations refresh
|
||||
// every N authority ticks; in between the advanced watermark shows as stale.
|
||||
if (count % frames_per_authority_tick == 0) {
|
||||
if (!remote && count % frames_per_authority_tick == 0) {
|
||||
if (count != 0 && !advance(*authority))
|
||||
return 1;
|
||||
if ((authority->tick - 1) % refresh_every == 0) {
|
||||
@@ -276,14 +311,16 @@ int main(int argc, char** argv) try {
|
||||
if (auto result = camera->zoom(std::exp2(navigation.wheel / 4), anchor);
|
||||
!result && result.error() != evo::client::CameraError::out_of_range)
|
||||
return 1;
|
||||
const auto& shown_environment = remote ? remote->environment() : environment;
|
||||
const auto& shown_organisms = remote ? remote->organisms() : population;
|
||||
// Copied presentation only; clipped to the viewport before float conversion.
|
||||
if (!evo::render::build_environment(boxes, environment.current(),
|
||||
environment.freshness(), *camera, display) ||
|
||||
!evo::render::append_organisms(boxes, organism_budget, population.current(),
|
||||
population.freshness(), *camera))
|
||||
if (!evo::render::build_environment(boxes, shown_environment.current(),
|
||||
shown_environment.freshness(), *camera, display) ||
|
||||
!evo::render::append_organisms(boxes, organism_budget, shown_organisms.current(),
|
||||
shown_organisms.freshness(), *camera))
|
||||
return 1;
|
||||
// Engineering inspector: biology gauges for the hovered organism only.
|
||||
if (const auto* shown = population.current(); inspect && shown != nullptr)
|
||||
if (const auto* shown = shown_organisms.current(); inspect && shown != nullptr)
|
||||
if (const auto index =
|
||||
evo::client::pick_organism(*shown, *camera, navigation.pointer))
|
||||
if (!evo::client::append_inspector(boxes, evo::client::inspector_rectangles,
|
||||
@@ -298,6 +335,8 @@ int main(int argc, char** argv) try {
|
||||
8,
|
||||
8,
|
||||
{240, 240, 240, 255}});
|
||||
if (remote)
|
||||
remote->status(boxes);
|
||||
const auto frame = evo::render::Frame::create(boxes, {16, 20, 28, 255});
|
||||
if (!frame)
|
||||
return 1;
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
#pragma once
|
||||
// M9.7 remote dev session for the engineering client (ADR-0083). Without
|
||||
// EVO_CLIENT_NETWORK (a build without EVO_BUILD_NETWORK) remote options are refused.
|
||||
// The client only presents copies and sends bounded intentions; it never predicts.
|
||||
#include "evo/client/environment_view.hpp"
|
||||
#include "evo/client/input.hpp"
|
||||
#include "evo/client/organism_view.hpp"
|
||||
#include "evo/render/frame.hpp"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef EVO_CLIENT_NETWORK
|
||||
#include "evo/network/session_client.hpp"
|
||||
#include <charconv>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#endif
|
||||
|
||||
namespace evo::client_app {
|
||||
struct RemoteOptions {
|
||||
std::string connect, server_name, authority, grants;
|
||||
[[nodiscard]] bool any() const noexcept {
|
||||
return !connect.empty() || !server_name.empty() || !authority.empty() || !grants.empty();
|
||||
}
|
||||
[[nodiscard]] bool complete() const noexcept {
|
||||
return !connect.empty() && !server_name.empty() && !authority.empty() && !grants.empty();
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef EVO_CLIENT_NETWORK
|
||||
inline constexpr bool remote_available = true;
|
||||
class RemoteSession {
|
||||
public:
|
||||
static std::optional<RemoteSession> open(const RemoteOptions& o) {
|
||||
const auto colon = o.connect.rfind(':');
|
||||
unsigned port = 0;
|
||||
if (colon == std::string::npos || colon == 0)
|
||||
return std::nullopt;
|
||||
const auto* digits = o.connect.data() + colon + 1;
|
||||
const auto [end, error] =
|
||||
std::from_chars(digits, o.connect.data() + o.connect.size(), port);
|
||||
if (error != std::errc{} || end != o.connect.data() + o.connect.size() || port == 0 ||
|
||||
port > 65535)
|
||||
return std::nullopt;
|
||||
const auto bundle = read(o.grants);
|
||||
if (bundle.empty() || bundle.size() % network::dev_grant_bytes != 0 ||
|
||||
bundle.size() / network::dev_grant_bytes > 64)
|
||||
return std::nullopt;
|
||||
network::SessionClientConfig config;
|
||||
config.host = o.connect.substr(0, colon);
|
||||
config.port = static_cast<std::uint16_t>(port);
|
||||
const auto pem = read(o.authority);
|
||||
config.trust = {{pem.begin(), pem.end()}, o.server_name};
|
||||
for (std::size_t at = 0; at < bundle.size(); at += network::dev_grant_bytes) {
|
||||
network::DevGrant grant{};
|
||||
std::copy_n(bundle.begin() + static_cast<std::ptrdiff_t>(at), grant.size(),
|
||||
grant.begin());
|
||||
config.grants.push_back(grant);
|
||||
}
|
||||
auto made = network::SessionClient::create(std::move(config));
|
||||
if (!made)
|
||||
return std::nullopt;
|
||||
RemoteSession session;
|
||||
session.client_ = std::move(*made);
|
||||
return session;
|
||||
}
|
||||
[[nodiscard]] const client::EnvironmentLayer& environment() const noexcept {
|
||||
return client_->environment();
|
||||
}
|
||||
[[nodiscard]] const client::OrganismLayer& organisms() const noexcept {
|
||||
return client_->organisms();
|
||||
}
|
||||
// Services the connection and sends the intention when its vector changed, at
|
||||
// most once per received server tick (the server also rate-limits).
|
||||
void step(std::chrono::steady_clock::time_point now, const client::Intention& intention) {
|
||||
client_->poll(now);
|
||||
const auto view = client_->latest_view();
|
||||
const bool changed = intention.move_x != sent_x_ || intention.move_y != sent_y_;
|
||||
if (view && changed && (!sent_tick_ || view->server_tick > *sent_tick_) &&
|
||||
client_->send(intention)) {
|
||||
sent_x_ = intention.move_x;
|
||||
sent_y_ = intention.move_y;
|
||||
sent_tick_ = view->server_tick;
|
||||
}
|
||||
for (const auto& e : client_->take_events())
|
||||
report(e);
|
||||
}
|
||||
// Connection chip and last-intention chip, below the capture bar.
|
||||
void status(std::vector<render::Rectangle>& out) const {
|
||||
using network::SessionPhase;
|
||||
const auto phase = client_->phase();
|
||||
const render::Color connection =
|
||||
phase == SessionPhase::established ? render::Color{64, 180, 140, 255}
|
||||
: phase == SessionPhase::exhausted ? render::Color{200, 40, 40, 255}
|
||||
: render::Color{240, 170, 40, 255};
|
||||
out.push_back({8, 72, 28, 6, connection});
|
||||
out.push_back({40, 72, 6, 6, intent_});
|
||||
}
|
||||
|
||||
private:
|
||||
static std::vector<std::uint8_t> read(const std::string& path) {
|
||||
std::ifstream file{path, std::ios::binary};
|
||||
return {std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{}};
|
||||
}
|
||||
void report(const network::ClientEvent& e) {
|
||||
using Kind = network::ClientEvent::Kind;
|
||||
constexpr render::Color pending{240, 240, 240, 255}, durable{64, 180, 140, 255},
|
||||
refused{200, 40, 40, 255}, unknown{130, 130, 130, 255};
|
||||
switch (e.kind) {
|
||||
case Kind::welcome:
|
||||
sent_tick_.reset(); // New session: resend the current intention.
|
||||
sent_x_ = sent_y_ = 0;
|
||||
std::printf("session welcome session=%llu epoch=%llu tick=%llu commit=%llu\n",
|
||||
static_cast<unsigned long long>(e.welcome.session),
|
||||
static_cast<unsigned long long>(e.welcome.epoch),
|
||||
static_cast<unsigned long long>(e.welcome.server_tick),
|
||||
static_cast<unsigned long long>(e.welcome.commit_watermark));
|
||||
break;
|
||||
case Kind::closed:
|
||||
std::printf("session closed reason=%u\n", static_cast<unsigned>(e.reason));
|
||||
break;
|
||||
case Kind::lost:
|
||||
std::puts("session lost (reconnecting with a fresh grant)");
|
||||
break;
|
||||
case Kind::result:
|
||||
intent_ = e.result.status == network::IntentStatus::admitted ? pending : refused;
|
||||
std::printf("intent %llu status=%u\n", static_cast<unsigned long long>(e.sequence),
|
||||
static_cast<unsigned>(e.result.status));
|
||||
break;
|
||||
case Kind::outcome:
|
||||
intent_ = e.outcome.finality == network::IntentFinality::committed_no_effect ? durable
|
||||
: refused;
|
||||
std::printf("intent %llu final=%u tick=%llu commit=%llu\n",
|
||||
static_cast<unsigned long long>(e.sequence),
|
||||
static_cast<unsigned>(e.outcome.finality),
|
||||
static_cast<unsigned long long>(e.outcome.tick),
|
||||
static_cast<unsigned long long>(e.outcome.commit_sequence));
|
||||
break;
|
||||
case Kind::unknown:
|
||||
intent_ = unknown;
|
||||
std::printf("intent %llu outcome unknown (connection lost)\n",
|
||||
static_cast<unsigned long long>(e.sequence));
|
||||
break;
|
||||
case Kind::exhausted:
|
||||
std::puts("session grants exhausted; issue a new bundle to reconnect");
|
||||
break;
|
||||
}
|
||||
std::fflush(stdout);
|
||||
}
|
||||
std::unique_ptr<network::SessionClient> client_;
|
||||
std::optional<std::uint64_t> sent_tick_;
|
||||
std::int16_t sent_x_{}, sent_y_{};
|
||||
render::Color intent_{60, 60, 66, 255};
|
||||
};
|
||||
#else
|
||||
inline constexpr bool remote_available = false;
|
||||
class RemoteSession {
|
||||
public:
|
||||
static std::optional<RemoteSession> open(const RemoteOptions&) {
|
||||
return std::nullopt;
|
||||
}
|
||||
[[nodiscard]] const client::EnvironmentLayer& environment() const noexcept {
|
||||
return environment_;
|
||||
}
|
||||
[[nodiscard]] const client::OrganismLayer& organisms() const noexcept {
|
||||
return organisms_;
|
||||
}
|
||||
void step(std::chrono::steady_clock::time_point, const client::Intention&) {}
|
||||
void status(std::vector<render::Rectangle>&) const {}
|
||||
|
||||
private:
|
||||
client::EnvironmentLayer environment_;
|
||||
client::OrganismLayer organisms_;
|
||||
};
|
||||
#endif
|
||||
} // namespace evo::client_app
|
||||
Reference in New Issue
Block a user