diff --git a/docs/engineering/M11_3_DELIVERY_PLAN.md b/docs/engineering/M11_3_DELIVERY_PLAN.md index b5bfb00..4cd8748 100644 --- a/docs/engineering/M11_3_DELIVERY_PLAN.md +++ b/docs/engineering/M11_3_DELIVERY_PLAN.md @@ -144,6 +144,11 @@ scoped change before starting the next segment. exposes the scheduled input to the host; the session client can send v6 movement and a requested patch address. V6 currently has no M10 probe view. Biology ownership, durable publication and perceived cell views remain open. +- 11.3b-6: the cellular owner now exposes a life-scoped exact patch view using + its authoritative footprint and ADR-0103's fixed range. V7 action-to-life + binding refuses a requested patch unless it is in that cell's current view; + source provenance and unseen stock remain private. Network view replication + and client presentation remain open. - 11.3c-4: ADR-0106 defines stable life-identity arbitration for same-tick patch contention. A detached multi-life candidate resolves all claims against each patch's remaining per-channel stock; starvation still refuses the candidate diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index b695991..58ccdf4 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -6345,3 +6345,15 @@ GCC 13.2 strict-warning syntax checks pass for the updated adapter and test in debug and `NDEBUG`; `git diff --check` passes. Runtime test execution, the QUIC preset and CI remain pending; the local cached-MSVC CMake limitation is unchanged. + +## 2026-10-10 — M11.3b-6 authoritative cellular patch perception (CI pending) + +Added a life-scoped `CellularLives::perceive` API. It recomputes the cell's +authoritative phenotype footprint and returns only the exact in-range patch +address and stock, excluding provenance. The v7 action adapter now rejects +intake targets outside this view, including guessed distant patches. + +GCC 13.2 strict-warning syntax checks pass for the lifecycle, session adapter +and focused tests in debug and `NDEBUG`; `git diff --check` passes. Runtime test +execution and full CI are pending; local CMake remains blocked by its cached +MSVC C++23 feature detection. diff --git a/include/evo/server/cellular_session_batch.hpp b/include/evo/server/cellular_session_batch.hpp index 85609c6..5f7529a 100644 --- a/include/evo/server/cellular_session_batch.hpp +++ b/include/evo/server/cellular_session_batch.hpp @@ -18,6 +18,7 @@ enum class CellularSessionBatchError : std::uint8_t { action, life, duplicate_action, + unperceived_target, head, batch_full, action_limit, diff --git a/include/evo/server/lifecycle/cellular_lives.hpp b/include/evo/server/lifecycle/cellular_lives.hpp index e25d476..8ad5682 100644 --- a/include/evo/server/lifecycle/cellular_lives.hpp +++ b/include/evo/server/lifecycle/cellular_lives.hpp @@ -92,6 +92,11 @@ class CellularLives { [[nodiscard]] accounting::Inventory opening_total() const noexcept; [[nodiscard]] accounting::Inventory current_total() const noexcept; [[nodiscard]] std::vector snapshot() const; + // Exact stock view for one live cell, filtered by its authoritative footprint and the + // M11.3 perception radius. Patch provenance and out-of-range stock are never returned. + [[nodiscard]] std::expected, + CellularLivesError> + perceive(std::uint64_t life_id) const; [[nodiscard]] static std::expected, CellularLivesError> restore(std::span bytes, std::uint64_t world, std::uint64_t region, diff --git a/src/server/lifecycle/cellular_lives.cpp b/src/server/lifecycle/cellular_lives.cpp index a2242d9..6b98f4f 100644 --- a/src/server/lifecycle/cellular_lives.cpp +++ b/src/server/lifecycle/cellular_lives.cpp @@ -267,14 +267,14 @@ struct CellularLives::State { accounting::Inventory current_total{}; State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id, - CellularLivesConfig cfg, NurseryConfig nursery, + CellularLivesConfig cfg, NurseryConfig nursery_definition, std::unique_ptr map, std::vector living, std::vector dead, const biology::LineageArchive& history, accounting::Inventory source, accounting::Inventory accumulated_heat, accounting::Inventory initial, accounting::Inventory current) : world{world_id}, region{region_id}, frame{frame_id}, config{cfg}, - nursery_config{std::move(nursery)}, + nursery_config{std::move(nursery_definition)}, habitat{std::move(map)}, lives{std::move(living)}, corpses{std::move(dead)}, archive{history}, nursery{source}, heat{accumulated_heat}, opening_total{initial}, current_total{current} {} @@ -457,6 +457,23 @@ std::vector CellularLives::snapshot() const { return bytes; } +std::expected, CellularLivesError> +CellularLives::perceive(std::uint64_t life_id) const { + const auto life = std::ranges::find(state_->lives, life_id, [](const auto& owned) { + return owned.identity.life; + }); + if (life == state_->lives.end()) + return std::unexpected{CellularLivesError::invalid_life}; + const auto budget = budget_for(state_->archive, *life, + state_->config.ambient_temperature_millikelvin); + if (!budget) + return std::unexpected{budget.error()}; + auto view = state_->habitat->perceive(life->position, budget->phenotype.extent); + if (!view) + return std::unexpected{CellularLivesError::habitat}; + return std::move(*view); +} + std::expected, CellularLivesError> CellularLives::restore(std::span bytes, std::uint64_t world, std::uint64_t region, std::uint64_t frame, std::uint64_t tick) { diff --git a/src/server/session/cellular_session_batch.cpp b/src/server/session/cellular_session_batch.cpp index 24f0b12..afba405 100644 --- a/src/server/session/cellular_session_batch.cpp +++ b/src/server/session/cellular_session_batch.cpp @@ -37,6 +37,14 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick, &CellularOwnedLife::account); if (life == state.lives().end()) return std::unexpected{CellularSessionBatchError::life}; + if (input->has_intake_target) { + const auto view = state.perceive(life->identity.life); + const biology::CellularPatchAddress target{input->intake_x_um, input->intake_y_um}; + if (!view || std::ranges::find(*view, target, + &biology::CellularPatchPerception::address) == + view->end()) + return std::unexpected{CellularSessionBatchError::unperceived_target}; + } const auto owned_intent = std::ranges::lower_bound( prepared.intents.lives, life->identity.life, {}, &CellularLifeIntent::life_id); if (owned_intent == prepared.intents.lives.end() || diff --git a/tests/cellular_lives_tests.cpp b/tests/cellular_lives_tests.cpp index defec2c..3eb7fe9 100644 --- a/tests/cellular_lives_tests.cpp +++ b/tests/cellular_lives_tests.cpp @@ -73,6 +73,11 @@ void owner_advances_and_closes_death_atomically() { const auto first_life_id = owner.lives()[0].identity.life; const auto second_life_id = owner.lives()[1].identity.life; + const auto visible_patches = owner.perceive(first_life_id); + CHECK(visible_patches && visible_patches->size() == 1 && + visible_patches->front().address == (evo::biology::CellularPatchAddress{0, 0}) && + visible_patches->front().available == owner.habitat().patches()[0].stock); + CHECK(owner.perceive(0).error() == CellularLivesError::invalid_life); const std::array invalid_motion{ CellularLifeIntent{first_life_id, {}}, CellularLifeIntent{second_life_id, {{1'001, 0}, std::nullopt}}}; diff --git a/tests/cellular_session_batch_tests.cpp b/tests/cellular_session_batch_tests.cpp index 85c17e5..09406a7 100644 --- a/tests/cellular_session_batch_tests.cpp +++ b/tests/cellular_session_batch_tests.cpp @@ -41,15 +41,24 @@ void actions_bind_to_owned_life_and_preserve_other_inputs() { CHECK((*primitive)->spawn(request, {2, 102, 202, 302, {1}})); biology::CellularHabitatConfig habitat_config{ - 90, 1, 7, 3'000, 2'000, {{{0, 0}, 29, {{10}, {{{10}, {10}, {10}, {10}}}}}}}; + 90, + 1, + 7, + 20'000, + 20'000, + {{{0, 0}, 29, {{10}, {{{10}, {10}, {10}, {10}}}}}, + {{15'000, 15'000}, 30, {{10}, {{{10}, {10}, {10}, {10}}}}}}}; auto habitat = biology::CellularHabitat::create(std::move(habitat_config)); CHECK(habitat); auto state = CellularLives::create(**primitive, std::move(*habitat), - {{3'000, 2'000}, 1, 293'150}); + {{20'000, 20'000}, 1, 293'150}); CHECK(state && (*state)->lives().size() == 2); const auto& controlled = (*state)->lives()[0]; const auto& other = (*state)->lives()[1]; + const auto visible = (*state)->perceive(controlled.identity.life); + CHECK(visible && visible->size() == 1 && + visible->front().address == (biology::CellularPatchAddress{0, 0})); const std::array baseline{CellularLifeIntent{controlled.identity.life, {{5, 6}, {}}}, CellularLifeIntent{other.identity.life, {{7, 8}, {}}}}; const auto input = network::encode_cellular_action_input({2, -3, 4, true, 0, 0}); @@ -65,6 +74,14 @@ void actions_bind_to_owned_life_and_preserve_other_inputs() { CHECK(prepared->actions[0] == CellularActionRecord{controlled.account, 77, input}); + const auto guessed_input = + network::encode_cellular_action_input({2, 0, 0, true, 15'000, 15'000}); + const network::CarriedAction guessed{network::AccountId{controlled.account}, 78, 2, + network::ActionKind::cellular, guessed_input}; + const std::array guessed_actions{guessed}; + CHECK(prepare_cellular_session_tick(**state, 2, baseline, guessed_actions).error() == + CellularSessionBatchError::unperceived_target); + CellularBatch batch; batch.header = {(*state)->world(), (*state)->region(), (*state)->frame(), {}, {}, 1, 2}; batch.header.predecessor.fill(1);