From 04a50be9cd2248c9f842df51d2a88bafdcdcb11d Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 10 Oct 2026 21:35:22 -0400 Subject: [PATCH] Admit and schedule cellular intentions --- cmake/Network.cmake | 5 ++ docs/engineering/M11_3_DELIVERY_PLAN.md | 4 + docs/engineering/VALIDATION.md | 18 ++++ include/evo/network/intent_admission.hpp | 17 +++- .../network/session-v6-cellular-intention.md | 9 ++ src/network/protocol/intent_admission.cpp | 38 +++++++- tests/cellular_intent_admission_tests.cpp | 90 +++++++++++++++++++ 7 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 tests/cellular_intent_admission_tests.cpp diff --git a/cmake/Network.cmake b/cmake/Network.cmake index 6d9a6b8..ca65e0b 100644 --- a/cmake/Network.cmake +++ b/cmake/Network.cmake @@ -70,6 +70,11 @@ if(BUILD_TESTING) evo_owned_target(evo-cellular-intent-protocol-tests) add_test(NAME cellular-intention-protocol-v6 COMMAND evo-cellular-intent-protocol-tests) set_tests_properties(cellular-intention-protocol-v6 PROPERTIES TIMEOUT 30 LABELS "network") + add_executable(evo-cellular-intent-admission-tests tests/cellular_intent_admission_tests.cpp) + target_link_libraries(evo-cellular-intent-admission-tests PRIVATE evo_network_protocol) + evo_owned_target(evo-cellular-intent-admission-tests) + add_test(NAME cellular-intent-admission COMMAND evo-cellular-intent-admission-tests) + set_tests_properties(cellular-intent-admission PROPERTIES TIMEOUT 30 LABELS "network") add_executable(evo-network-tests tests/network_protocol.cpp tests/network_tls.cpp tests/network_session.cpp tests/network_control.cpp tests/network_replication.cpp tests/network_motion.cpp tests/network_interpolation.cpp tests/network_main.cpp) diff --git a/docs/engineering/M11_3_DELIVERY_PLAN.md b/docs/engineering/M11_3_DELIVERY_PLAN.md index 4e009f4..3dcc3d3 100644 --- a/docs/engineering/M11_3_DELIVERY_PLAN.md +++ b/docs/engineering/M11_3_DELIVERY_PLAN.md @@ -130,6 +130,10 @@ scoped change before starting the next segment. - 11.3b-3: ADR-0105 and the v6 codec define cellular intention bytes for movement and an optional food-patch target. Server admission, durable simulation and client presentation are still open. +- 11.3b-4: v6 intentions reuse the existing bounded session/epoch/tick/sequence + admission rules and expose a deterministic read-only schedule until the host + advances its simulated watermark. `RegionSessions` and a durable cellular host + still do not consume this schedule. ## Exit boundary diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index cf9be02..ad786f2 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -5949,3 +5949,21 @@ The CMake/Ninja build of `evo-network-tests` remained idle for about 90 seconds (cmake 0.02 CPU seconds, ninja 0.09, no `cl`/`link` child), so I interrupted it; the full M10 network suite and server admission/QUIC integration remain pending. Linux network CI has not yet qualified this version. + +## 2026-10-10 — M11.3b-4 cellular intention admission (CI pending) + +Cellular v6 intentions now pass through the established authenticated-session, +epoch, movement-bound, increasing-sequence, future-tick, rate and unresolved +input checks. The pending schedule is read-only until the simulated watermark +advances and orders by tick, account, session ID and sequence, including the +case where one account has multiple open sessions. The cellular region owner +and durable publication path still do not consume this schedule. + +Executed locally: warning-as-error MSVC 19.44 Debug and Release/NDEBUG direct +compile/run of the focused admission regression; existing CTest +`cellular-intention-protocol-v6` (1/1 passed); clang-format 19.1.5 on the new +test, changed header and implementation ranges; clang-tidy 19.1.5 on the changed +test and implementation using `-std=c++23`; and `git diff --check`. The network +CMake configure stalled during MSVC compiler detection, so the new CTest +registration and complete network build await CI. Linux and full M10 network +checks remain pending. diff --git a/include/evo/network/intent_admission.hpp b/include/evo/network/intent_admission.hpp index 714509a..dd4b3e6 100644 --- a/include/evo/network/intent_admission.hpp +++ b/include/evo/network/intent_admission.hpp @@ -51,6 +51,12 @@ struct AccountOutcome { AccountId account; ActionOutcome outcome; }; +struct ScheduledCellularIntention { + AccountId account; + CellularIntention intention; + friend bool operator==(const ScheduledCellularIntention&, + const ScheduledCellularIntention&) = default; +}; enum class IntentConfigError : std::uint8_t { invalid }; // Durable action records (10.4b): the region host implements it over its lease (schema v11); // tests use fakes. `find` answers with the committed outcome, nothing when the action was @@ -94,6 +100,12 @@ class IntentAdmission { // 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]] IntentionReceipt intention(std::uint64_t session, const CellularIntention& m, + const AdmissionFacts& facts); + // Read-only pending inputs up to this tick, in deterministic tick/account/sequence order. + // They remain available until simulated() advances the committed/simulated watermark. + [[nodiscard]] std::vector + scheduled_cellular_intentions(std::uint64_t tick) const; [[nodiscard]] ActionReceipt action(std::uint64_t session, const SessionAction& m, const AdmissionFacts& facts); // The same admission with the durable uniqueness check deferred (M10.9d): nothing when the @@ -133,7 +145,10 @@ class IntentAdmission { private: struct Pending { - std::uint64_t sequence{}, tick{}; + std::uint64_t sequence{}, tick{}, epoch{}; + std::int16_t move_x{}, move_y{}; + bool has_intake_target{}; + std::uint32_t intake_x_um{}, intake_y_um{}; }; struct Session { std::uint64_t id{}; diff --git a/schemas/network/session-v6-cellular-intention.md b/schemas/network/session-v6-cellular-intention.md index 7926ca5..412bc1d 100644 --- a/schemas/network/session-v6-cellular-intention.md +++ b/schemas/network/session-v6-cellular-intention.md @@ -28,3 +28,12 @@ Movement remains an intention only; the server derives position, costs and resource balances. Truncated frames, trailing bytes, nonzero reserved bytes, invalid flags, noncanonical absent-target coordinates and versions below 6 are refused by the codec. + +After decode, admission applies the authenticated connection/session match, +current control epoch, ready authority, one-intention-per-tick and increasing +sequence rules, bounded future tick window, movement norm and per-window rate +and unresolved-input caps from ADR-0089/0092. The biology owner further checks +the patch address against its provisioned map and that session's authoritative +perception before resolving contact. Scheduled inputs remain available for +deterministic replay until the host marks their tick simulated; a cellular host +must tie that watermark to its chosen durable publication boundary. diff --git a/src/network/protocol/intent_admission.cpp b/src/network/protocol/intent_admission.cpp index ebbc636..4c537ba 100644 --- a/src/network/protocol/intent_admission.cpp +++ b/src/network/protocol/intent_admission.cpp @@ -103,11 +103,47 @@ IntentionReceipt IntentAdmission::intention(std::uint64_t session, const Session r.status = AdmitStatus::too_many_unresolved; if (r.status == AdmitStatus::admitted) { s->last_sequence = m.sequence; - s->pending.push_back({m.sequence, m.tick}); + s->pending.push_back({m.sequence, m.tick, m.epoch, m.move_x, m.move_y, false, 0, 0}); } return r; } +IntentionReceipt IntentAdmission::intention(std::uint64_t session, const CellularIntention& m, + const AdmissionFacts& facts) { + const SessionIntention movement{m.session, m.epoch, m.sequence, m.tick, m.move_x, m.move_y}; + auto receipt = intention(session, movement, facts); + if (receipt.status == AdmitStatus::admitted) { + auto* admitted = find(session); + auto& pending = admitted->pending.back(); + pending.has_intake_target = m.has_intake_target; + pending.intake_x_um = m.intake_x_um; + pending.intake_y_um = m.intake_y_um; + } + return receipt; +} + +std::vector +IntentAdmission::scheduled_cellular_intentions(std::uint64_t tick) const { + std::vector out; + for (const auto& session : sessions_) + for (const auto& pending : session.pending) + if (pending.tick <= tick) + out.push_back({session.account, + {session.id, pending.epoch, pending.sequence, pending.tick, + pending.move_x, pending.move_y, pending.has_intake_target, + pending.intake_x_um, pending.intake_y_um}}); + std::ranges::sort(out, [](const auto& left, const auto& right) { + if (left.intention.tick != right.intention.tick) + return left.intention.tick < right.intention.tick; + if (left.account != right.account) + return left.account < right.account; + if (left.intention.session != right.intention.session) + return left.intention.session < right.intention.session; + return left.intention.sequence < right.intention.sequence; + }); + return out; +} + ActionReceipt IntentAdmission::screen(Session& s, const SessionAction& m, const AdmissionFacts& facts, bool& check) { ActionReceipt r{m.action_id, AdmitStatus::admitted, facts.server_tick, m.tick}; diff --git a/tests/cellular_intent_admission_tests.cpp b/tests/cellular_intent_admission_tests.cpp new file mode 100644 index 0000000..9e2ba35 --- /dev/null +++ b/tests/cellular_intent_admission_tests.cpp @@ -0,0 +1,90 @@ +#include "evo/network/intent_admission.hpp" + +#include +#include +#include +#include + +namespace { +using namespace evo::network; +void check(bool value, std::source_location at = std::source_location::current()) { + if (!value) + throw std::runtime_error("cellular intent admission line " + std::to_string(at.line())); +} +#define CHECK(...) check(static_cast(__VA_ARGS__)) + +AccountId account(std::uint8_t id) { + AccountId value{}; + value.bytes.back() = id; + return value; +} + +void admission_and_rejections() { + auto made = IntentAdmission::create({}); + CHECK(made); + auto queue = std::move(*made); + CHECK(queue.open(22, account(2))); + CHECK(queue.open(33, account(1))); + CHECK(queue.open(11, account(1))); + const AdmissionFacts facts{true, 7, 10}; + + const CellularIntention b{22, 7, 1, 12, -500, 500, true, 3'000, 2'000}; + const CellularIntention a{11, 7, 1, 12, 0, 1000, false, 0, 0}; + CHECK(queue.intention(22, b, facts).status == AdmitStatus::admitted); + CHECK(queue.intention(11, a, facts).status == AdmitStatus::admitted); + + const auto rejected_epoch = queue.intention(11, CellularIntention{11, 8, 2, 13}, facts); + CHECK(rejected_epoch.status == AdmitStatus::stale_epoch); + const auto rejected_vector = + queue.intention(11, CellularIntention{11, 7, 2, 13, 1000, 1000}, facts); + CHECK(rejected_vector.status == AdmitStatus::invalid_vector); + const auto rejected_window = queue.intention(11, CellularIntention{11, 7, 2, 19}, facts); + CHECK(rejected_window.status == AdmitStatus::outside_window); + const auto rejected_replay = queue.intention(11, a, facts); + CHECK(rejected_replay.status == AdmitStatus::replayed); + const auto rejected_connection = queue.intention(11, CellularIntention{99, 7, 2, 13}, facts); + CHECK(rejected_connection.status == AdmitStatus::unknown_session); +} + +void scheduled_inputs_are_stable_until_simulated() { + auto made = IntentAdmission::create({}); + CHECK(made); + auto queue = std::move(*made); + CHECK(queue.open(22, account(2))); + CHECK(queue.open(33, account(1))); + CHECK(queue.open(11, account(1))); + const AdmissionFacts facts{true, 7, 10}; + CHECK(queue.intention(22, CellularIntention{22, 7, 1, 12, -500, 500, true, 3'000, 2'000}, facts) + .status == AdmitStatus::admitted); + CHECK(queue.intention(33, CellularIntention{33, 7, 1, 12, 0, 0}, facts).status == + AdmitStatus::admitted); + CHECK(queue.intention(11, CellularIntention{11, 7, 1, 12, 0, 1000}, facts).status == + AdmitStatus::admitted); + + CHECK(queue.scheduled_cellular_intentions(11).empty()); + const auto before = queue.scheduled_cellular_intentions(12); + CHECK(before.size() == 3); + CHECK(before[0].account == account(1)); // Stable account order, not connection order. + CHECK(before[0].intention == CellularIntention{11, 7, 1, 12, 0, 1000, false, 0, 0}); + CHECK(before[1].account == account(1)); + CHECK(before[1].intention == CellularIntention{33, 7, 1, 12, 0, 0, false, 0, 0}); + CHECK(before[2].account == account(2)); + CHECK(before[2].intention == CellularIntention{22, 7, 1, 12, -500, 500, true, 3'000, 2'000}); + CHECK(queue.scheduled_cellular_intentions(12) == before); // Read does not consume input. + + const auto marks = queue.simulated({true, 7, 12}); + CHECK(marks.size() == 3); + CHECK(queue.scheduled_cellular_intentions(12).empty()); +} +} // namespace + +int main() { + try { + admission_and_rejections(); + scheduled_inputs_are_stable_until_simulated(); + std::puts("PASS cellular intent admission: authority, ordering and retry-stable schedule"); + } catch (const std::exception& error) { + std::fprintf(stderr, "%s\n", error.what()); + return 1; + } +}