Files
dingoandClaude Opus 5.5 819137c1df
Foundation / checks (deploy) (push) Successful in 1m0s
Foundation / checks (ecs) (push) Successful in 3m34s
Foundation / checks (network) (push) Successful in 8m8s
Foundation / checks (client) (push) Successful in 14m49s
Foundation / checks (tsan) (push) Successful in 7m35s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 16m18s
Foundation / checks (checks) (push) Canceled after 29m27s
Ratify M10.1 timing and workload budgets with session traces
ADR-0089 records the maintainer-ratified 50 ms tick, 1 s flush with final
outcomes p95 <= 1.5 s, responsiveness targets and reference hardware, plus
derived scheduling, sequence, identity, baseline, queue/byte/work budgets and the
exact/tolerant determinism contract (schemas/network/m10-budgets-v1.md). Adds
SessionClient traffic counters, `evo-dev-session trace` and a reproducible trace
script; development-reference results are in M10_TIMING_TRACES. Records that
genome v1 and metabolism rates are per tick, so the quantum fixes biology rates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 12:29:58 -04:00

93 lines
4.2 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};
// Liveness after Welcome: heartbeat when idle; a silent server past the timeout is
// treated as lost (stale presentation, unknown outcomes, reconnect).
std::chrono::milliseconds heartbeat_interval{1000}, liveness_timeout{5000};
};
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, // Sent intention whose outcome died with its connection.
backpressure, // Local event backlog: reconnect waits for take_events().
exhausted // No grants left; reconnection stops.
} kind{};
Welcome welcome{};
CloseReason reason{};
IntentResult result{};
IntentOutcome outcome{};
std::uint64_t sequence{};
};
// Received-frame counters for timing and bandwidth experiments (M10.1); bytes include
// the frame header. Monotonic for the client's lifetime, across reconnects.
struct ClientTraffic {
std::uint64_t frames{}, bytes{};
std::uint64_t environment_views{}, environment_view_bytes{};
std::uint64_t organism_views{}, organism_view_bytes{};
};
enum class SessionClientError : std::uint8_t { configuration };
class SessionClient {
public:
static constexpr std::size_t max_outstanding = 256, max_events = 1024;
[[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);
// Queues one intention when established, a view has arrived, fewer than
// max_outstanding are unresolved and the channel queue has room; otherwise false.
// Never carried 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;
// Attempts that failed before any session event (TCP connect or TLS handshake), so a
// caller can bound "unreachable" without an event per retry. Never reset.
[[nodiscard]] std::uint64_t unreachable_attempts() const noexcept;
[[nodiscard]] ClientTraffic traffic() const noexcept;
// Drains at most max_events and resumes reconnect after local backpressure.
[[nodiscard]] std::vector<ClientEvent> take_events();
private:
struct Impl;
explicit SessionClient(std::unique_ptr<Impl> impl);
std::unique_ptr<Impl> impl_;
};
} // namespace evo::network