Add M10.4a intentions, actions and admission
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
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>
This commit is contained in:
@@ -62,14 +62,16 @@ struct RegionSessions::Impl {
|
||||
};
|
||||
|
||||
Impl(RegionSessionsConfig c, std::unique_ptr<network::quic::Endpoint> e,
|
||||
network::GrantVerifier v, network::SessionControl s)
|
||||
network::GrantVerifier v, network::SessionControl s, network::IntentAdmission i)
|
||||
: config{std::move(c)}, endpoint{std::move(e)}, verifier{std::move(v)},
|
||||
control{std::move(s)} {}
|
||||
control{std::move(s)}, intents{std::move(i)} {}
|
||||
|
||||
RegionSessionsConfig config;
|
||||
std::unique_ptr<network::quic::Endpoint> endpoint;
|
||||
network::GrantVerifier verifier;
|
||||
network::SessionControl control;
|
||||
network::IntentAdmission intents;
|
||||
HostFacts facts;
|
||||
std::vector<Connection> connections;
|
||||
std::vector<RegionSessionEvent> events;
|
||||
|
||||
@@ -89,6 +91,13 @@ struct RegionSessions::Impl {
|
||||
// A refused send (budget) leaves the peer to observe the transport close instead.
|
||||
(void)endpoint->send_message(c.id, network::encode_session(m)).has_value();
|
||||
}
|
||||
// Realtime answers: a refused datagram is dropped; cumulative watermarks cover it.
|
||||
void send_datagram(const Connection& c, const network::SessionMessage& m) {
|
||||
(void)endpoint->send_datagram(c.id, network::encode_session(m)).has_value();
|
||||
}
|
||||
[[nodiscard]] network::AdmissionFacts admission() const {
|
||||
return {facts.ready, control.epoch(), facts.simulated_tick};
|
||||
}
|
||||
// Sends Close, releases control, reports, and closes after the flush deadline.
|
||||
void close(Connection& c, SessionCloseReason reason, Clock::time_point now) {
|
||||
if (c.state == State::closing)
|
||||
@@ -101,6 +110,8 @@ struct RegionSessions::Impl {
|
||||
event.account = c.account;
|
||||
event.reason = reason;
|
||||
events.push_back(std::move(event));
|
||||
if (c.state == State::established)
|
||||
intents.close(c.session);
|
||||
if (c.session != 0) // May already be released (superseded, expired, epoch).
|
||||
(void)control.close(c.session).has_value();
|
||||
// A superseded session's durable control already moved to its successor.
|
||||
@@ -166,11 +177,14 @@ struct RegionSessions::Impl {
|
||||
return;
|
||||
}
|
||||
}
|
||||
welcome(c);
|
||||
welcome(c, now);
|
||||
}
|
||||
|
||||
void welcome(Connection& c) {
|
||||
void welcome(Connection& c, Clock::time_point now) {
|
||||
if (!intents.open(c.session, c.account_id))
|
||||
return close(c, SessionCloseReason::capacity, now);
|
||||
c.state = State::established;
|
||||
c.welcome.server_tick = facts.simulated_tick;
|
||||
send(c, c.welcome);
|
||||
events.push_back({RegionSessionEvent::Kind::opened, c.session, c.account, {}});
|
||||
}
|
||||
@@ -225,6 +239,24 @@ struct RegionSessions::Impl {
|
||||
send(c, result);
|
||||
}
|
||||
|
||||
// Only established sessions may send datagrams, and only intentions.
|
||||
void datagram(Connection& c, std::span<const std::uint8_t> bytes, Clock::time_point now) {
|
||||
if (c.state == State::closing)
|
||||
return;
|
||||
const auto decoded = network::decode_session(bytes);
|
||||
const auto* m = decoded ? std::get_if<network::SessionIntention>(&*decoded) : nullptr;
|
||||
if (c.state != State::established || !m)
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
send_datagram(c, intents.intention(c.session, *m, admission()));
|
||||
}
|
||||
|
||||
void deliver(const std::vector<network::AccountOutcome>& outcomes) {
|
||||
for (const auto& o : outcomes)
|
||||
if (const auto session = intents.session_of(o.account))
|
||||
if (auto* c = by_session(*session); c && c->state == State::established)
|
||||
send(*c, o.outcome);
|
||||
}
|
||||
|
||||
void message(Connection& c, std::span<const std::uint8_t> bytes, std::uint64_t now_seconds,
|
||||
Clock::time_point now) {
|
||||
if (c.state == State::closing)
|
||||
@@ -245,6 +277,19 @@ struct RegionSessions::Impl {
|
||||
}
|
||||
if (const auto* m = std::get_if<network::SessionRefresh>(&*decoded))
|
||||
return refresh(c, *m, now_seconds, now);
|
||||
if (const auto* m = std::get_if<network::SessionAction>(&*decoded)) {
|
||||
const auto receipt = intents.action(c.session, *m, admission());
|
||||
send(c, receipt);
|
||||
// A duplicate of a final action: answer with the outcome as well.
|
||||
if (receipt.status == network::AdmitStatus::duplicate)
|
||||
if (const auto o = intents.query(c.session, {m->action_id});
|
||||
o.result == network::ActionResult::committed_no_effect ||
|
||||
o.result == network::ActionResult::not_committed)
|
||||
send(c, o);
|
||||
return;
|
||||
}
|
||||
if (const auto* m = std::get_if<network::ActionQuery>(&*decoded))
|
||||
return send(c, intents.query(c.session, *m));
|
||||
if (const auto* m = std::get_if<network::SessionClose>(&*decoded);
|
||||
m && m->reason == SessionCloseReason::client_closed) {
|
||||
close(c, SessionCloseReason::client_closed, now);
|
||||
@@ -275,22 +320,31 @@ RegionSessions::create(RegionSessionsConfig config) {
|
||||
for (const auto& k : config.issuer_keys)
|
||||
if (!verifier->add_key(k.key_id, k.public_key))
|
||||
return std::unexpected(RegionSessionsError::keys);
|
||||
config.intents.max_sessions = config.control.max_sessions;
|
||||
auto intents = network::IntentAdmission::create(config.intents);
|
||||
if (!intents)
|
||||
return std::unexpected(RegionSessionsError::configuration);
|
||||
auto endpoint = network::quic::Endpoint::serve(config.transport);
|
||||
if (!endpoint)
|
||||
return std::unexpected(RegionSessionsError::transport);
|
||||
return std::unique_ptr<RegionSessions>{new RegionSessions{std::make_unique<Impl>(
|
||||
std::move(config), std::move(*endpoint), std::move(*verifier), std::move(*control))}};
|
||||
return std::unique_ptr<RegionSessions>{new RegionSessions{
|
||||
std::make_unique<Impl>(std::move(config), std::move(*endpoint), std::move(*verifier),
|
||||
std::move(*control), std::move(*intents))}};
|
||||
}
|
||||
|
||||
void RegionSessions::poll(std::uint64_t epoch, std::uint64_t now_seconds, Clock::time_point now) {
|
||||
void RegionSessions::poll(const HostFacts& facts, std::uint64_t now_seconds,
|
||||
Clock::time_point now) {
|
||||
auto& m = *impl_;
|
||||
if (epoch > m.control.epoch()) {
|
||||
// Every session ends with the epoch (ADR-0089); control has released them.
|
||||
const auto closed = m.control.advance_epoch(epoch);
|
||||
m.facts = facts;
|
||||
if (facts.epoch > m.control.epoch()) {
|
||||
// Every session ends with the epoch (ADR-0089); control has released them. Actions
|
||||
// never carried are final; carried ones await their durable record.
|
||||
const auto closed = m.control.advance_epoch(facts.epoch);
|
||||
if (closed)
|
||||
for (const auto session : *closed)
|
||||
if (auto* c = m.by_session(session))
|
||||
m.close(*c, SessionCloseReason::stale_epoch, now);
|
||||
(void)m.intents.abandon(); // Kept for queries; no session is left to tell.
|
||||
}
|
||||
for (auto& e : m.endpoint->poll()) {
|
||||
using network::quic::EventKind;
|
||||
@@ -307,6 +361,8 @@ void RegionSessions::poll(std::uint64_t epoch, std::uint64_t now_seconds, Clock:
|
||||
m.connections, [&](const Impl::Connection& c) { return c.id == e.connection; });
|
||||
if (it == m.connections.end())
|
||||
continue;
|
||||
if (it->state == Impl::State::established)
|
||||
m.intents.close(it->session);
|
||||
if (it->state == Impl::State::pending) {
|
||||
(void)m.control.close(it->session).has_value();
|
||||
if (m.config.ledger && it->generation != 0)
|
||||
@@ -323,15 +379,21 @@ void RegionSessions::poll(std::uint64_t epoch, std::uint64_t now_seconds, Clock:
|
||||
: SessionCloseReason::connection_lost});
|
||||
}
|
||||
m.connections.erase(it);
|
||||
} // Datagrams carry nothing before 10.4.
|
||||
} else if (e.kind == EventKind::datagram) {
|
||||
if (auto* c = m.find(e.connection))
|
||||
m.datagram(*c, e.bytes, now);
|
||||
}
|
||||
}
|
||||
for (const auto& [session, watermark] : m.intents.simulated(m.admission()))
|
||||
if (auto* c = m.by_session(session); c && c->state == Impl::State::established)
|
||||
m.send_datagram(*c, watermark);
|
||||
for (const auto session : m.control.expire(now_seconds))
|
||||
if (auto* c = m.by_session(session))
|
||||
m.close(*c, SessionCloseReason::expired, now);
|
||||
for (auto& c : m.connections) {
|
||||
m.renew(c, now);
|
||||
if (c.state == Impl::State::pending && now >= c.deadline)
|
||||
m.welcome(c);
|
||||
m.welcome(c, now);
|
||||
if (c.state == Impl::State::hello && now >= c.deadline)
|
||||
m.close(c, SessionCloseReason::timeout, now);
|
||||
if (c.state == Impl::State::closing && now >= c.deadline && !c.close_requested) {
|
||||
@@ -341,6 +403,14 @@ void RegionSessions::poll(std::uint64_t epoch, std::uint64_t now_seconds, Clock:
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<network::CarriedAction> RegionSessions::carry(std::uint64_t tick) {
|
||||
return impl_->intents.carry(tick);
|
||||
}
|
||||
|
||||
void RegionSessions::committed(std::uint64_t end_tick, std::uint64_t commit_sequence) {
|
||||
impl_->deliver(impl_->intents.committed(end_tick, commit_sequence));
|
||||
}
|
||||
|
||||
void RegionSessions::shutdown(Clock::time_point now) {
|
||||
for (auto& c : impl_->connections)
|
||||
impl_->close(c, SessionCloseReason::shutdown, now);
|
||||
|
||||
Reference in New Issue
Block a user