Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m45s
Foundation / checks (network) (push) Successful in 9m37s
Foundation / checks (client) (push) Successful in 12m14s
Foundation / checks (tsan) (push) Successful in 7m39s
Foundation / checks (checks) (push) Successful in 31m15s
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 32m59s
Session protocol v1 (not yet deployed, amended in place) gains realtime intentions on datagrams with receipts and a cumulative simulated watermark, and account-scoped actions with stable ids, receipts, final outcomes and queries. IntentAdmission enforces session binding, rate, authority, epoch, vector, sequence, tick window, duplicates and the unresolved bound; RegionSessions and the client carry it over QUIC. Intentions and actions have no biological effect yet. ADR-0092. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
5.1 KiB
C++
108 lines
5.1 KiB
C++
#pragma once
|
|
#include "evo/network/session_control.hpp"
|
|
#include "evo/network/session_protocol.hpp"
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <deque>
|
|
#include <expected>
|
|
#include <optional>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
// M10.4 admission of realtime intentions and discrete actions for one region (ADR-0092).
|
|
// Transport-neutral and single-owner; the host serializes calls. Three distinct answers:
|
|
// - receipt: admitted (scheduled for a tick) or a refusal, never more than that;
|
|
// - simulated: the cumulative watermark of admitted intentions whose tick has run;
|
|
// - final (actions only): committed_no_effect with its commit, or not_committed.
|
|
// Intentions are per session (sequence strictly increasing, superseded by later ones).
|
|
// Actions are per account, with client-chosen ids that are never admitted twice, so a
|
|
// retry or a reconnect resolves to the same outcome. Neither changes biology in M10.4.
|
|
namespace evo::network {
|
|
struct IntentLimits {
|
|
std::uint32_t intent_window{8}; // Ticks ahead of the server tick (ADR-0089).
|
|
std::uint32_t window_ticks{8}; // Rate window.
|
|
std::uint32_t max_intents_per_window{8}; // Every attempt counts.
|
|
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.
|
|
};
|
|
// The host's authority as admission must see it.
|
|
struct AdmissionFacts {
|
|
bool ready{};
|
|
std::uint64_t epoch{}, server_tick{};
|
|
};
|
|
// An action the host must record durably with the batch that covers its tick.
|
|
struct CarriedAction {
|
|
AccountId account;
|
|
std::uint64_t action_id{}, tick{};
|
|
ActionKind kind{};
|
|
friend bool operator==(const CarriedAction&, const CarriedAction&) = default;
|
|
};
|
|
struct AccountOutcome {
|
|
AccountId account;
|
|
ActionOutcome outcome;
|
|
};
|
|
enum class IntentConfigError : std::uint8_t { invalid };
|
|
|
|
class IntentAdmission {
|
|
public:
|
|
[[nodiscard]] static std::expected<IntentAdmission, IntentConfigError>
|
|
create(IntentLimits limits);
|
|
// Session lifecycle, driven by session control (after Welcome, on any close).
|
|
[[nodiscard]] bool open(std::uint64_t session, const AccountId& account);
|
|
void close(std::uint64_t session);
|
|
// `session` is the connection's authenticated session; a message naming another is
|
|
// refused. Every attempt by a known session counts toward its rate.
|
|
[[nodiscard]] IntentionReceipt intention(std::uint64_t session, const SessionIntention& m,
|
|
const AdmissionFacts& facts);
|
|
[[nodiscard]] ActionReceipt action(std::uint64_t session, const SessionAction& m,
|
|
const AdmissionFacts& facts);
|
|
// What this process knows about an action of the session's account.
|
|
[[nodiscard]] ActionOutcome query(std::uint64_t session, const ActionQuery& m) const;
|
|
// Watermarks to send after the host simulated through facts.server_tick.
|
|
[[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.
|
|
[[nodiscard]] std::vector<CarriedAction> carry(std::uint64_t tick);
|
|
// A commit covering ticks up to `end_tick` is durable: its carried actions are final.
|
|
[[nodiscard]] std::vector<AccountOutcome> committed(std::uint64_t end_tick,
|
|
std::uint64_t commit_sequence);
|
|
// Authority lost or epoch advanced: actions never carried are final (not_committed);
|
|
// carried ones stay unresolved until a durable record decides them (10.4b).
|
|
[[nodiscard]] std::vector<AccountOutcome> abandon();
|
|
// The current session of an account, for delivering outcomes.
|
|
[[nodiscard]] std::optional<std::uint64_t> session_of(const AccountId& account) const;
|
|
[[nodiscard]] std::size_t unresolved(std::uint64_t session) const;
|
|
|
|
private:
|
|
struct Pending {
|
|
std::uint64_t sequence{}, tick{};
|
|
};
|
|
struct Session {
|
|
std::uint64_t id{};
|
|
AccountId account;
|
|
std::uint64_t last_sequence{}, window_start{};
|
|
std::uint32_t intent_attempts{}, action_attempts{};
|
|
std::deque<Pending> pending;
|
|
std::uint64_t watermark{}, sent_watermark{}, sent_at_tick{};
|
|
};
|
|
enum class Stage : std::uint8_t { scheduled, carried };
|
|
struct Action {
|
|
CarriedAction carried;
|
|
Stage stage{};
|
|
};
|
|
explicit IntentAdmission(IntentLimits limits) : limits_{limits} {}
|
|
Session* find(std::uint64_t session);
|
|
const Session* find(std::uint64_t session) const;
|
|
void count_window(Session& s, std::uint64_t server_tick) const;
|
|
[[nodiscard]] std::size_t unresolved_of(const Session& s) const;
|
|
void remember(const AccountId& account, const ActionOutcome& outcome);
|
|
IntentLimits limits_;
|
|
std::vector<Session> sessions_;
|
|
std::vector<Action> actions_;
|
|
std::deque<AccountOutcome> finals_;
|
|
};
|
|
} // namespace evo::network
|