diff --git a/apps/evo-server/cellular_bridge.hpp b/apps/evo-server/cellular_bridge.hpp index 7fbb6f3..e94fd11 100644 --- a/apps/evo-server/cellular_bridge.hpp +++ b/apps/evo-server/cellular_bridge.hpp @@ -25,7 +25,8 @@ namespace evo::server_app { // Profile-4 network boundary. Biology and persistence remain owned by the cellular host; -// this bridge handles admission, v7 action receipts and read-only replicated cell views. +// this bridge handles admission, v7/v8 action receipts, public cell replication and +// owner-filtered v8 perception. class CellularBridge { public: static std::optional @@ -167,6 +168,26 @@ class CellularBridge { return result; }; sessions_->replicate(tick, source); + sessions_->clear_cellular_perceptions(tick); + for (const auto& life : state.lives()) { + const auto perceived = state.perceive(life.identity.life); + if (!perceived) + continue; + network::CellularPerception view; + view.tick = tick; + view.life_identity = life.identity.life; + view.patches.reserve(perceived->size()); + for (const auto& patch : *perceived) { + network::CellularPerceivedPatch visible; + visible.x_um = patch.address.x_um; + visible.y_um = patch.address.y_um; + visible.energy_pj = patch.available.energy.value; + for (std::size_t i = 0; i < visible.matter_fg.size(); ++i) + visible.matter_fg[i] = patch.available.matter[i].value; + view.patches.push_back(visible); + } + (void)sessions_->send_cellular_perception(network::AccountId{life.account}, view); + } replicated_tick_ = tick; } void shutdown() { diff --git a/docs/engineering/M11_3_DELIVERY_PLAN.md b/docs/engineering/M11_3_DELIVERY_PLAN.md index de024b5..c5652d1 100644 --- a/docs/engineering/M11_3_DELIVERY_PLAN.md +++ b/docs/engineering/M11_3_DELIVERY_PLAN.md @@ -358,6 +358,12 @@ scoped change before starting the next segment. address-ordered inventory list and keeps v1-v7 layouts unchanged. The server still needs to route each view to its authenticated owner; the client needs cellular input and presentation before the hands-on probe. +- 11.3e-2: v8 sessions can receive the exact perceived patch list through an + account-keyed reliable unicast; v7 and other accounts are excluded, and a + zero-life view clears stale client state. The QUIC regression test exercises + that boundary. The profile bridge now projects authoritative `CellularLives` + perception each tick. Client controls and an on-screen view remain to be + connected before the hands-on probe. ## Exit boundary diff --git a/include/evo/client/region_session.hpp b/include/evo/client/region_session.hpp index db78fee..a8f5b9f 100644 --- a/include/evo/client/region_session.hpp +++ b/include/evo/client/region_session.hpp @@ -59,7 +59,7 @@ class RegionSessionClient { // retries and reconnects). False unless established and sent. [[nodiscard]] bool send_action(std::uint64_t action_id, network::ActionKind kind, std::uint64_t tick); - // Protocol v7 only. Reuse the exact same fields and action id after reconnect. + // Protocol v7/v8. Reuse the exact same fields and action id after reconnect. [[nodiscard]] bool send_cellular_action( std::uint64_t action_id, std::uint64_t tick, std::int16_t move_x, std::int16_t move_y, std::optional> intake_target = {}); @@ -82,6 +82,9 @@ class RegionSessionClient { [[nodiscard]] bool set_interest(const network::SessionInterest& interest); // The newest complete snapshot, or null before the first. [[nodiscard]] const network::ReplicatedView* view() const noexcept; + // Newest owner-filtered cellular sensor view (v8), cleared when no owned life exists. + [[nodiscard]] const std::optional& + cellular_perception() const noexcept; [[nodiscard]] std::expected environment() const; [[nodiscard]] std::expected organisms() const; diff --git a/include/evo/server/region_sessions.hpp b/include/evo/server/region_sessions.hpp index 4ea1bcb..67ea204 100644 --- a/include/evo/server/region_sessions.hpp +++ b/include/evo/server/region_sessions.hpp @@ -92,7 +92,7 @@ struct RegionSessionsConfig { // M10.8d recovery: this often, open outgoing transfers prepared more than ticket_lifetime // + 10 s ago (by the store's clock, e.g. by a process that died) are aborted. std::chrono::milliseconds overdue_poll{5000}; - // v5 is accepted only when both primitive-life handlers are supplied. Callbacks + // v5/v8 are accepted only when both primitive-life handlers are supplied. Callbacks // receive the authenticated account and durable control generation for this session. // A cellular host may enable v5 together with the v7 cellular action path; each // connection remains fixed to its negotiated protocol. @@ -104,8 +104,8 @@ struct RegionSessionsConfig { query_primitive_life; // M11.3 v6 cellular intentions. Opt-in until a cellular state owner consumes them. bool accept_cellular_intentions{}; - // M11.3 v7 durable cellular actions. Requires durable control and action ledgers; - // the caller must forward carried inputs to the profile-4 region host. + // M11.3 v7 durable cellular actions and v8 owner-filtered perception. Requires durable + // control and action ledgers; the caller forwards carried inputs to profile 4. bool accept_cellular_actions{}; }; // The region host's authority, read once per poll. @@ -155,6 +155,11 @@ class RegionSessions { std::uint64_t tick, const std::function& source, const network::Perceives& perceives = {}); + // V8 reliable cellular perception is unicast to the current established session + // for the supplied authenticated account. Empty views clear that owner's stale view. + [[nodiscard]] bool send_cellular_perception( + const network::AccountId& account, const network::CellularPerception& perception); + void clear_cellular_perceptions(std::uint64_t tick); [[nodiscard]] network::ReplicationStats replication_stats() const; // M10.9a (ADR-0097): the host's load governor output. While `refuse_logins`, a Hello // carrying a grant is closed with `capacity` before signature work (handoff tickets are diff --git a/src/client/session/region_session.cpp b/src/client/session/region_session.cpp index cd2ba21..33a6369 100644 --- a/src/client/session/region_session.cpp +++ b/src/client/session/region_session.cpp @@ -27,6 +27,7 @@ struct RegionSessionClient::Impl { std::vector primitive_life_receipts; std::vector primitive_life_outcomes; std::optional snapshots; + std::optional cellular_perception; std::uint64_t snapshot_chunks{}, snapshot_bytes{}; std::optional handoff; // v4: continue at another region. std::optional redirect; // v4: the probe is owned elsewhere. @@ -129,6 +130,11 @@ struct RegionSessionClient::Impl { } if (const auto* m = std::get_if(&*decoded)) return keep(action_outcomes, *m); + if (const auto* m = std::get_if(&*decoded)) { + seen_tick(m->tick); + cellular_perception = *m; + return; + } if (const auto* m = std::get_if(&*decoded)) { seen_tick(m->server_tick); return keep(primitive_life_receipts, *m); @@ -152,7 +158,8 @@ RegionSessionClient::connect(RegionSessionClientConfig config, Clock::time_point if (config.protocol_version != network::session_protocol_version && config.protocol_version != network::session_protocol_v5 && config.protocol_version != network::session_protocol_v6 && - config.protocol_version != network::session_protocol_v7) + config.protocol_version != network::session_protocol_v7 && + config.protocol_version != network::session_protocol_v8) return std::unexpected(network::quic::EndpointError::configuration); auto endpoint = network::quic::Endpoint::connect(config.transport); if (!endpoint) @@ -257,7 +264,8 @@ bool RegionSessionClient::send_cellular_action( std::uint64_t action_id, std::uint64_t tick, std::int16_t move_x, std::int16_t move_y, std::optional> intake_target) { auto& m = *impl_; - return m.protocol_version == network::session_protocol_v7 && + return (m.protocol_version == network::session_protocol_v7 || + m.protocol_version == network::session_protocol_v8) && m.state == RegionSessionState::established && m.welcome && action_id != 0 && tick != 0 && m.send(network::CellularAction{m.welcome->session, m.welcome->epoch, action_id, tick, move_x, move_y, intake_target.has_value(), @@ -268,20 +276,23 @@ bool RegionSessionClient::send_cellular_action( bool RegionSessionClient::query_action(std::uint64_t action_id) { auto& m = *impl_; return (m.protocol_version == network::session_protocol_version || - m.protocol_version == network::session_protocol_v7) && + m.protocol_version == network::session_protocol_v7 || + m.protocol_version == network::session_protocol_v8) && m.state == RegionSessionState::established && m.send(network::ActionQuery{action_id}); } bool RegionSessionClient::request_primitive_life(std::uint64_t request_id) { auto& m = *impl_; - return m.protocol_version == network::session_protocol_v5 && + return (m.protocol_version == network::session_protocol_v5 || + m.protocol_version == network::session_protocol_v8) && m.state == RegionSessionState::established && m.welcome && request_id != 0 && m.send(network::PrimitiveLifeRequest{m.welcome->session, m.welcome->epoch, request_id}); } bool RegionSessionClient::query_primitive_life(std::uint64_t request_id) { auto& m = *impl_; - return m.protocol_version == network::session_protocol_v5 && + return (m.protocol_version == network::session_protocol_v5 || + m.protocol_version == network::session_protocol_v8) && m.state == RegionSessionState::established && request_id != 0 && m.send(network::PrimitiveLifeQuery{request_id}); } @@ -317,7 +328,8 @@ std::uint64_t RegionSessionClient::server_tick() const noexcept { bool RegionSessionClient::set_interest(const network::SessionInterest& interest) { auto& m = *impl_; return (m.protocol_version == network::session_protocol_version || - m.protocol_version == network::session_protocol_v7) && + m.protocol_version == network::session_protocol_v7 || + m.protocol_version == network::session_protocol_v8) && m.state == RegionSessionState::established && m.send(interest); } @@ -326,6 +338,11 @@ const network::ReplicatedView* RegionSessionClient::view() const noexcept { return snapshots ? snapshots->latest() : nullptr; } +const std::optional& +RegionSessionClient::cellular_perception() const noexcept { + return impl_->cellular_perception; +} + std::expected RegionSessionClient::environment() const { const auto& snapshots = impl_->snapshots; diff --git a/src/server/session/region_sessions.cpp b/src/server/session/region_sessions.cpp index 28b7f97..4378f56 100644 --- a/src/server/session/region_sessions.cpp +++ b/src/server/session/region_sessions.cpp @@ -398,7 +398,8 @@ struct RegionSessions::Impl { !((config.accept_cellular_intentions && c.protocol_version == network::session_protocol_v6) || (config.accept_cellular_actions && - c.protocol_version == network::session_protocol_v7)))) + (c.protocol_version == network::session_protocol_v7 || + c.protocol_version == network::session_protocol_v8))))) return close(c, SessionCloseReason::protocol, now); if (const auto* ack = std::get_if(&*decoded)) return replication.acknowledge(c.session, *ack); @@ -560,12 +561,13 @@ struct RegionSessions::Impl { c.protocol_version = wire_version; const bool primitive_v5 = static_cast(config.create_primitive_life); const bool cellular_v6 = config.accept_cellular_intentions; - const bool cellular_v7 = config.accept_cellular_actions; + const bool cellular_actions = config.accept_cellular_actions; if ((primitive_v5 && wire_version < network::session_protocol_v5) || (wire_version == network::session_protocol_v5 && !primitive_v5) || (wire_version == network::session_protocol_v6 && !cellular_v6) || - (wire_version == network::session_protocol_v7 && !cellular_v7) || - wire_version > network::session_protocol_v7) + ((wire_version == network::session_protocol_v7 || + wire_version == network::session_protocol_v8) && !cellular_actions) || + wire_version > network::session_protocol_v8) return close(c, SessionCloseReason::unsupported_version, now); } else if (wire_version != c.protocol_version) { return close(c, SessionCloseReason::unsupported_version, now); @@ -588,7 +590,8 @@ struct RegionSessions::Impl { return; } if (const auto* m = std::get_if(&*decoded)) { - if (c.protocol_version != network::session_protocol_v7) + if (c.protocol_version != network::session_protocol_v7 && + c.protocol_version != network::session_protocol_v8) return close(c, SessionCloseReason::protocol, now); if (const auto receipt = intents.admit(c.session, *m, admission())) answer(c, *receipt); @@ -835,6 +838,31 @@ void RegionSessions::replicate( m.send_datagram(*c, chunk); // A refused chunk leaves the snapshot unacknowledged. } +bool RegionSessions::send_cellular_perception( + const network::AccountId& account, const network::CellularPerception& perception) { + auto& m = *impl_; + for (const auto& c : m.connections) { + if (c.state != Impl::State::established || c.protocol_version != network::session_protocol_v8 || + c.account_id != account) + continue; + return m.endpoint + ->send_message(c.id, network::encode_session(perception, c.protocol_version)) + .has_value(); + } + return false; +} + +void RegionSessions::clear_cellular_perceptions(std::uint64_t tick) { + if (tick == 0) + return; + auto& m = *impl_; + const network::CellularPerception cleared{tick, 0, {}}; + for (const auto& c : m.connections) + if (c.state == Impl::State::established && + c.protocol_version == network::session_protocol_v8) + m.send(c, cleared); +} + network::ReplicationStats RegionSessions::replication_stats() const { return impl_->replication.stats(); } diff --git a/tests/cellular_intent_protocol_tests.cpp b/tests/cellular_intent_protocol_tests.cpp index 75d11d6..b420833 100644 --- a/tests/cellular_intent_protocol_tests.cpp +++ b/tests/cellular_intent_protocol_tests.cpp @@ -140,6 +140,12 @@ void v8_perception_is_bounded_and_canonical() { const CellularPerception cleared{19, 0, {}}; const auto clear_bytes = encode_session(SessionMessage{cleared}); CHECK(std::get(*decode_session(clear_bytes)) == cleared); + auto oversized = perception; + oversized.patches.clear(); + for (std::size_t i = 0; i <= max_cellular_perceived_patches; ++i) + oversized.patches.push_back( + {static_cast(i), 0, 0, {0, 0, 0, 0}}); + CHECK(encode_session(SessionMessage{oversized}).empty()); } } // namespace diff --git a/tests/quic_sessions.cpp b/tests/quic_sessions.cpp index d57c4ca..d41e2a4 100644 --- a/tests/quic_sessions.cpp +++ b/tests/quic_sessions.cpp @@ -589,8 +589,14 @@ void cellular_v5_spawn_and_v7_action_share_region_sessions(const Files& f) { }}; auto spawn_client = h.connect(h.issuer.grant(account(0xB5), 1), session_protocol_v5); auto action_client = h.connect(h.issuer.grant(account(0xB7), 1), session_protocol_v7); + const auto owner_account = account(0xB8); + auto perception_owner = h.connect(h.issuer.grant(owner_account, 1), session_protocol_v8); + auto other_owner = h.connect(h.issuer.grant(account(0xB9), 1), session_protocol_v8); CHECK(h.settled(*spawn_client) && spawn_client->state() == RegionSessionState::established); CHECK(h.settled(*action_client) && action_client->state() == RegionSessionState::established); + CHECK(h.settled(*perception_owner) && + perception_owner->state() == RegionSessionState::established); + CHECK(h.settled(*other_owner) && other_owner->state() == RegionSessionState::established); CHECK(spawn_client->request_primitive_life(44)); std::vector birth_outcomes; @@ -623,6 +629,22 @@ void cellular_v5_spawn_and_v7_action_share_region_sessions(const Files& f) { CHECK(action_client->view()->organisms.size() == 1 && action_client->view()->organisms.front().id == 901); CHECK(action_client->set_interest({1, 0, 0, 2})); + + const CellularPerception perception{101, 901, {{1'000, 2'000, 3, {4, 5, 6, 7}}}}; + CHECK(h.server->send_cellular_perception(owner_account, perception)); + CHECK(h.until([&] { + return perception_owner->cellular_perception() && + perception_owner->cellular_perception()->tick == perception.tick; + })); + CHECK(*perception_owner->cellular_perception() == perception); + CHECK(!other_owner->cellular_perception() && !action_client->cellular_perception()); + h.server->clear_cellular_perceptions(102); + CHECK(h.until([&] { + return perception_owner->cellular_perception() && + perception_owner->cellular_perception()->tick == 102; + })); + CHECK(perception_owner->cellular_perception()->life_identity == 0 && + perception_owner->cellular_perception()->patches.empty()); } // M10.4: intentions, actions and their distinct answers against a simulated host.