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
+101 -2
View File
@@ -150,7 +150,7 @@ struct Harness {
return std::move(*made);
}
void pump() {
server->poll(epoch, now_seconds, Clock::now());
server->poll({ready, epoch, tick}, now_seconds, Clock::now());
for (auto& e : server->take_events())
events.push_back(std::move(e));
for (auto* c : clients)
@@ -189,7 +189,8 @@ struct Harness {
std::unique_ptr<RegionSessions> server;
std::vector<RegionSessionClient*> clients;
std::vector<RegionSessionEvent> events;
std::uint64_t epoch{5}, now_seconds{start};
std::uint64_t epoch{5}, now_seconds{start}, tick{100};
bool ready{true};
};
bool refused_with(Harness& h, const WireGrant& grant, Reason reason) {
@@ -370,6 +371,103 @@ struct FakeLedger final : ControlLedger {
std::vector<std::uint64_t> renewed, released;
};
// M10.4: intentions, actions and their distinct answers against a simulated host.
void intentions_and_actions(const Files& f) {
Harness h{f};
const auto alice = account(1);
auto a = h.connect(h.issuer.grant(alice, 1));
CHECK(h.settled(*a) && must(a->welcome()).server_tick == 100 && a->server_tick() == 100);
// Intention: a receipt, then the simulated watermark once its tick runs.
CHECK(a->send_intention(101, 10, -10) == 1u);
std::vector<IntentionReceipt> receipts;
CHECK(h.until([&] { return !(receipts = a->take_intention_receipts()).empty(); }));
CHECK(receipts[0] == IntentionReceipt{1, AdmitStatus::admitted, 100});
CHECK(!a->simulated());
CHECK(a->send_intention(150, 0, 0) == 2u);
CHECK(h.until([&] { return !(receipts = a->take_intention_receipts()).empty(); }));
CHECK(receipts[0].status == AdmitStatus::outside_window);
h.tick = 101;
CHECK(h.until([&] { return a->simulated() && a->simulated()->sequence == 1; }));
CHECK(must(a->simulated()) == SimulatedThrough{5, 1, 101} && a->server_tick() == 101);
h.ready = false;
CHECK(a->send_intention(103, 0, 0) == 3u);
CHECK(h.until([&] { return !(receipts = a->take_intention_receipts()).empty(); }));
CHECK(receipts[0].status == AdmitStatus::not_ready);
h.ready = true;
// Action: receipt (scheduled), carried with its tick's batch, final after the commit.
CHECK(a->send_action(7, ActionKind::probe, 103));
std::vector<ActionReceipt> action_receipts;
CHECK(h.until([&] { return !(action_receipts = a->take_action_receipts()).empty(); }));
CHECK(action_receipts[0] == ActionReceipt{7, AdmitStatus::admitted, 101, 103});
CHECK(a->query_action(7));
std::vector<ActionOutcome> outcomes;
CHECK(h.until([&] { return !(outcomes = a->take_action_outcomes()).empty(); }));
CHECK(outcomes[0].result == ActionResult::pending);
CHECK(h.server->carry(102).empty());
const auto carried = h.server->carry(103);
CHECK(carried.size() == 1 && carried[0] == CarriedAction{alice, 7, 103, ActionKind::probe});
h.server->committed(103, 4);
CHECK(h.until([&] { return !(outcomes = a->take_action_outcomes()).empty(); }));
CHECK(outcomes[0] == ActionOutcome{7, ActionResult::committed_no_effect, 103, 4});
// A retry gets a duplicate receipt and the same final outcome.
CHECK(a->send_action(7, ActionKind::probe, 104));
CHECK(h.until([&] { return !(outcomes = a->take_action_outcomes()).empty(); }));
CHECK(outcomes[0] == ActionOutcome{7, ActionResult::committed_no_effect, 103, 4});
// The stream is ordered: the duplicate receipt arrived before the repeated outcome.
const auto duplicates = a->take_action_receipts();
CHECK(duplicates.size() == 1 &&
duplicates[0] == ActionReceipt{7, AdmitStatus::duplicate, 101, 103});
// Reconnect (lost connection, new grant): the account's action resolves the same way.
auto b = h.connect(h.issuer.grant(alice, 2));
CHECK(h.settled(*b) && b->state() == RegionSessionState::established);
CHECK(b->query_action(7));
CHECK(h.until([&] { return !(outcomes = b->take_action_outcomes()).empty(); }));
CHECK(outcomes[0] == ActionOutcome{7, ActionResult::committed_no_effect, 103, 4});
// An action scheduled but never carried when the epoch moves on is final: not committed.
CHECK(b->send_action(8, ActionKind::probe, 108));
CHECK(h.until([&] { return !b->take_action_receipts().empty(); }));
h.epoch = 6;
CHECK(h.until([&] { return b->state() == RegionSessionState::closed; }));
auto c = h.connect(h.issuer.grant(alice, 3));
CHECK(h.settled(*c) && c->state() == RegionSessionState::established);
CHECK(c->query_action(8));
CHECK(h.until([&] { return !(outcomes = c->take_action_outcomes()).empty(); }));
CHECK(outcomes[0].result == ActionResult::not_committed);
// Intentions of an old epoch are refused.
CHECK(c->send_intention(h.tick + 1, 0, 0));
CHECK(h.until([&] { return !(receipts = c->take_intention_receipts()).empty(); }));
CHECK(receipts[0].status == AdmitStatus::admitted); // c is in epoch 6.
// A peer that appends state claims (position, energy) to an intention is closed.
auto peer = h.raw();
quic::ConnectionId id = 0;
std::optional<SessionWelcome> welcome;
std::optional<Reason> reason;
CHECK(h.until([&] {
for (auto& e : peer->poll()) {
if (e.kind == quic::EventKind::connected) {
id = e.connection;
CHECK(peer->send_message(
id, encode_session(SessionHello{0, h.issuer.grant(account(4), 1)})));
} else if (e.kind == quic::EventKind::message) {
const auto m = decode_session(e.bytes);
if (m && std::holds_alternative<SessionWelcome>(*m)) {
welcome = std::get<SessionWelcome>(*m);
auto claim = encode_session(
SessionIntention{welcome->session, welcome->epoch, 1, h.tick + 1, 0, 0});
for (int i = 0; i < 16; ++i)
claim.push_back(0x7F); // "position" and "energy"
CHECK(peer->send_datagram(id, claim));
} else if (m && std::holds_alternative<SessionClose>(*m)) {
reason = std::get<SessionClose>(*m).reason;
}
}
}
return reason.has_value();
}));
CHECK(welcome && reason == Reason::protocol);
}
void durable_control(const Files& f) {
FakeLedger ledger;
Harness h{f, 4, 64, &ledger};
@@ -444,6 +542,7 @@ int main() try {
login_rules(files);
limits(files);
durable_control(files);
intentions_and_actions(files);
std::filesystem::remove_all(files.dir);
std::puts("quic session tests passed");
return 0;