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

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:
dingo
2026-10-03 22:09:06 -04:00
co-authored by Claude Opus 5.5
parent 890c57a77f
commit e2f6208433
18 changed files with 1155 additions and 48 deletions
+140 -3
View File
@@ -1,5 +1,6 @@
#include "evo/identity/identity.hpp"
#include "evo/network/dev_grant.hpp"
#include "evo/network/intent_admission.hpp"
#include "evo/network/session_control.hpp"
#include "evo/network/session_grant.hpp"
#include "evo/network/session_protocol.hpp"
@@ -326,7 +327,7 @@ void session_codec() {
WireGrant grant{};
for (std::size_t i = 0; i < grant.size(); ++i)
grant.at(i) = static_cast<std::uint8_t>(i * 7);
SessionWelcome welcome{1, 2, 3, 4, 5, 6, 7};
SessionWelcome welcome{1, 2, 3, 4, 5, 6, 7, 8};
const std::vector<SessionMessage> messages{
SessionHello{0, grant},
welcome,
@@ -334,7 +335,14 @@ void session_codec() {
SessionRefreshResult{0, 99},
SessionRefreshResult{static_cast<std::uint8_t>(SessionCloseReason::stale_grant), 0},
SessionClose{SessionCloseReason::superseded},
SessionClose{SessionCloseReason::shutdown}};
SessionClose{SessionCloseReason::shutdown},
SessionIntention{1, 2, 3, 4, -1000, 7},
IntentionReceipt{3, AdmitStatus::not_ready, 9},
SimulatedThrough{2, 3, 4},
SessionAction{1, 2, 77, 1, 5},
ActionReceipt{77, AdmitStatus::duplicate, 4, 5},
ActionOutcome{77, ActionResult::committed_no_effect, 5, 12},
ActionQuery{77}};
for (const auto& m : messages) {
const auto bytes = encode_session(m);
CHECK(bytes.at(0) == 'E' && bytes.at(1) == 'V' && bytes.at(2) == 'S' && bytes.at(3) == 'N');
@@ -359,7 +367,7 @@ void session_codec() {
mutated = bytes;
mutated.at(7) = 1;
CHECK(refused(decode_session(mutated), SessionCodecError::reserved_flags));
for (const auto type : std::array<std::uint8_t, 3>{0, 6, 255}) {
for (const auto type : std::array<std::uint8_t, 3>{0, 13, 255}) {
mutated = bytes;
mutated.at(6) = type;
CHECK(refused(decode_session(mutated), SessionCodecError::unknown_type));
@@ -378,12 +386,140 @@ void session_codec() {
CHECK(refused(decode_session(result), SessionCodecError::invalid_value));
}
}
// Decoded values survive exactly (signed vectors, every field).
const SessionIntention intent{9, 8, 7, 6, -1000, 999};
CHECK(std::get<SessionIntention>(*decode_session(encode_session(intent))) == intent);
const ActionOutcome outcome{5, ActionResult::not_committed, 0, 0};
CHECK(std::get<ActionOutcome>(*decode_session(encode_session(outcome))) == outcome);
// A state claim appended to an intention (position, energy) is not a valid message.
auto claimed = encode_session(intent);
for (int i = 0; i < 16; ++i)
claimed.push_back(0x7F);
CHECK(refused(decode_session(claimed), SessionCodecError::wrong_length));
for (const auto bad : std::array<std::uint8_t, 3>{11, 200, 255}) {
auto receipt = encode_session(IntentionReceipt{1, AdmitStatus::admitted, 1});
receipt.at(session_header_bytes + 8) = bad;
CHECK(refused(decode_session(receipt), SessionCodecError::invalid_value));
}
for (const auto bad : std::array<std::uint8_t, 3>{0, 5, 255}) {
auto o = encode_session(outcome);
o.at(session_header_bytes + 8) = bad;
CHECK(refused(decode_session(o), SessionCodecError::invalid_value));
}
for (const auto zero : {0, 1}) {
auto w = welcome;
(zero == 0 ? w.session : w.epoch) = 0;
CHECK(refused(decode_session(encode_session(w)), SessionCodecError::invalid_value));
}
}
void intent_admission() {
IntentLimits limits;
limits.max_unresolved = 6;
limits.max_finals = 4;
CHECK(refused(IntentAdmission::create(IntentLimits{0}), IntentConfigError::invalid));
auto a = *IntentAdmission::create(limits);
const auto alice = account(1), bob = account(2);
CHECK(a.open(1, alice) && a.open(2, bob) && !a.open(1, alice) && !a.open(0, alice));
AdmissionFacts f{true, 5, 100};
const auto intention = [&](std::uint64_t session, std::uint64_t seq, std::uint64_t tick,
std::int16_t x = 0, std::uint64_t epoch = 5) {
return a.intention(session, SessionIntention{session, epoch, seq, tick, x, 0}, f).status;
};
// Every refusal, in the order admission applies them.
CHECK(intention(1, 1, 101) == AdmitStatus::admitted);
CHECK(a.intention(1, SessionIntention{2, 5, 2, 102, 0, 0}, f).status ==
AdmitStatus::unknown_session); // Names another session.
CHECK(a.intention(9, SessionIntention{9, 5, 2, 102, 0, 0}, f).status ==
AdmitStatus::unknown_session); // No such session.
CHECK(intention(1, 2, 102, 0, 4) == AdmitStatus::stale_epoch);
CHECK(intention(1, 2, 102, 1001) == AdmitStatus::invalid_vector);
CHECK(intention(1, 1, 102) == AdmitStatus::replayed);
CHECK(intention(1, 2, 100) == AdmitStatus::outside_window); // Not in the future.
CHECK(intention(1, 2, 109) == AdmitStatus::outside_window); // Beyond 8 ticks.
CHECK(intention(1, 2, 101) == AdmitStatus::outside_window); // Same tick as before.
CHECK(intention(1, 2, 102) == AdmitStatus::rate_limited); // 8 attempts this window.
f.server_tick = 108; // New window.
f.ready = false;
CHECK(intention(1, 2, 109) == AdmitStatus::not_ready);
f.ready = true;
CHECK(intention(1, 2, 109) == AdmitStatus::admitted);
CHECK(intention(1, 3, 110) == AdmitStatus::admitted);
// Simulated watermark: only intentions whose tick ran, cumulatively.
f.server_tick = 109;
auto marks = a.simulated(f);
CHECK(marks.size() == 1 && marks[0].first == 1 &&
marks[0].second == SimulatedThrough{5, 2, 109});
CHECK(a.simulated(f).empty()); // Unchanged: not repeated yet.
f.server_tick = 110;
marks = a.simulated(f);
CHECK(marks.size() == 1 && marks[0].second.sequence == 3);
f.server_tick = 130;
marks = a.simulated(f); // Repeated after 20 ticks so a lost datagram is covered.
CHECK(marks.size() == 1 && marks[0].second == SimulatedThrough{5, 3, 130});
// Actions: receipt, carried with its tick's batch, final after the commit.
const auto action = [&](std::uint64_t session, std::uint64_t id, std::uint64_t tick,
std::uint16_t kind = 1) {
return a.action(session, SessionAction{session, 5, id, kind, tick}, f);
};
f.server_tick = 200;
auto r = action(1, 10, 203);
CHECK(r.status == AdmitStatus::admitted && r.tick == 203 && r.server_tick == 200);
CHECK(a.query(1, {10}).result == ActionResult::pending);
CHECK(action(1, 0, 203).status == AdmitStatus::invalid_action);
CHECK(action(1, 11, 203, 9).status == AdmitStatus::invalid_action);
{ // Wire kind 257 must not truncate to a known kind.
auto other = *IntentAdmission::create(IntentLimits{});
CHECK(other.open(1, alice));
CHECK(other.action(1, SessionAction{1, 5, 1, 257, 101}, AdmissionFacts{true, 5, 100})
.status == AdmitStatus::invalid_action);
}
r = action(1, 10, 204); // Retry with another tick: the original stands.
CHECK(r.status == AdmitStatus::duplicate && r.tick == 203);
CHECK(action(1, 12, 203).status == AdmitStatus::rate_limited); // 4 action attempts.
CHECK(a.carry(202).empty());
const auto carried = a.carry(203);
CHECK(carried.size() == 1 && carried[0] == CarriedAction{alice, 10, 203, ActionKind::probe});
CHECK(a.carry(203).empty()); // Each action is carried once.
CHECK(a.committed(202, 7).empty());
auto outcomes = a.committed(203, 8);
CHECK(outcomes.size() == 1 && outcomes[0].account == alice &&
outcomes[0].outcome == ActionOutcome{10, ActionResult::committed_no_effect, 203, 8});
CHECK(a.query(1, {10}) == outcomes[0].outcome);
CHECK(a.query(2, {10}).result == ActionResult::unknown); // Bob's account has no action 10.
// A reconnect of the same account (new session) sees the same outcome.
a.close(1);
CHECK(a.query(1, {10}).result == ActionResult::unknown); // Closed session asks nothing.
CHECK(a.open(3, alice) && a.session_of(alice) == 3u);
CHECK(a.query(3, {10}) == outcomes[0].outcome);
f.server_tick = 300;
CHECK(action(3, 10, 301).status == AdmitStatus::duplicate); // Never admitted twice.
// Unresolved cap counts intentions and actions; abandon finalizes only uncarried actions.
CHECK(action(3, 20, 301).status == AdmitStatus::admitted);
CHECK(action(3, 21, 308).status == AdmitStatus::admitted);
(void)a.carry(301);
for (std::uint64_t i = 0; i < 4; ++i)
CHECK(a.intention(3, SessionIntention{3, 5, i + 1, 302 + i, 0, 0}, f).status ==
AdmitStatus::admitted);
CHECK(a.unresolved(3) == 6);
CHECK(a.intention(3, SessionIntention{3, 5, 9, 307, 0, 0}, f).status ==
AdmitStatus::too_many_unresolved);
outcomes = a.abandon();
CHECK(outcomes.size() == 1 &&
outcomes[0].outcome == ActionOutcome{21, ActionResult::not_committed, 0, 0});
CHECK(a.query(3, {20}).result == ActionResult::pending); // Carried: awaits its record.
CHECK(a.unresolved(3) == 1);
CHECK(a.committed(301, 9).size() == 1); // Its batch turned out durable.
// Final outcomes are kept within a bound; older ones become unknown here.
for (std::uint64_t id = 30; id < 34; ++id) {
f.server_tick += 8;
CHECK(action(3, id, f.server_tick + 1).status == AdmitStatus::admitted);
(void)a.carry(f.server_tick + 1);
CHECK(a.committed(f.server_tick + 1, id).size() == 1);
}
CHECK(a.query(3, {10}).result == ActionResult::unknown);
CHECK(a.query(3, {33}).result == ActionResult::committed_no_effect);
}
} // namespace
void control_tests() {
@@ -391,5 +527,6 @@ void control_tests() {
identity_adapter();
control_rules();
session_codec();
intent_admission();
}
} // namespace evo::network_test