Files
aevolution/include/evo/network/session_client.hpp
T
dingoandClaude Opus 5.5 8e319322f4 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>
2026-10-01 20:12:18 -04:00

75 lines
3.1 KiB
C++

#pragma once
#include "evo/client/environment_view.hpp"
#include "evo/client/input.hpp"
#include "evo/client/organism_view.hpp"
#include "evo/network/dev_grant.hpp"
#include "evo/network/protocol.hpp"
#include "evo/network/tls_channel.hpp"
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <memory>
#include <optional>
#include <string>
#include <vector>
// M9.7 dev session client (ADR-0083). Non-blocking; the desktop host calls poll()
// once per frame. Holds presentation copies only: it never predicts, simulates or
// treats a local value as authority. Each Hello consumes one single-use grant (except
// after a `server_shutdown`/`capacity` refusal, when the server never recorded it);
// every new session starts from a fresh server baseline.
namespace evo::network {
struct SessionClientConfig {
std::string host;
std::uint16_t port{};
ClientTrust trust;
std::vector<DevGrant> grants; // Consumed in order, one per Hello.
std::uint32_t lead_ticks{4}; // Intended tick = newest view tick + lead.
std::chrono::milliseconds attempt_deadline{5000}; // Connect to Welcome.
std::chrono::milliseconds first_retry{500}, max_retry{8000};
};
enum class SessionPhase : std::uint8_t { backoff, connecting, established, exhausted };
struct ClientEvent {
enum class Kind : std::uint8_t {
welcome,
closed,
lost, // Transport/TLS failure or deadline: no Close received.
result, // IntentResult.
outcome, // IntentOutcome (durable or not committed).
unknown, // Admitted intention whose outcome died with its connection.
exhausted // No grants left; reconnection stops.
} kind{};
Welcome welcome{};
CloseReason reason{};
IntentResult result{};
IntentOutcome outcome{};
std::uint64_t sequence{};
};
enum class SessionClientError : std::uint8_t { configuration };
class SessionClient {
public:
static constexpr std::size_t max_outstanding = 256;
[[nodiscard]] static std::expected<std::unique_ptr<SessionClient>, SessionClientError>
create(SessionClientConfig config);
SessionClient(const SessionClient&) = delete;
SessionClient& operator=(const SessionClient&) = delete;
~SessionClient();
void poll(std::chrono::steady_clock::time_point now);
// Sends when established and a view has arrived; never queued across connections.
[[nodiscard]] bool send(const client::Intention& intention);
[[nodiscard]] SessionPhase phase() const noexcept;
[[nodiscard]] const client::EnvironmentLayer& environment() const noexcept;
[[nodiscard]] const client::OrganismLayer& organisms() const noexcept;
[[nodiscard]] std::optional<Welcome> welcome() const noexcept;
[[nodiscard]] std::optional<ViewHeader> latest_view() const noexcept;
[[nodiscard]] std::size_t grants_left() const noexcept;
[[nodiscard]] std::vector<ClientEvent> take_events();
private:
struct Impl;
explicit SessionClient(std::unique_ptr<Impl> impl);
std::unique_ptr<Impl> impl_;
};
} // namespace evo::network