Define cellular owner diagnostics v9
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 40s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (postgres) (push) Failing after 53s
Foundation / checks (tsan) (push) Failing after 32s
Foundation / checks (network) (push) Failing after 3m1s
Foundation / checks (client) (push) Failing after 4m26s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-11 01:52:33 -04:00
parent a6a18dd6cd
commit fe03a0f8e4
9 changed files with 313 additions and 42 deletions
+2 -2
View File
@@ -68,8 +68,8 @@ if(BUILD_TESTING)
add_executable(evo-cellular-intent-protocol-tests tests/cellular_intent_protocol_tests.cpp)
target_link_libraries(evo-cellular-intent-protocol-tests PRIVATE evo_network_protocol)
evo_owned_target(evo-cellular-intent-protocol-tests)
add_test(NAME cellular-session-protocol-v6-v7 COMMAND evo-cellular-intent-protocol-tests)
set_tests_properties(cellular-session-protocol-v6-v7 PROPERTIES TIMEOUT 30 LABELS "network")
add_test(NAME cellular-session-protocol-v6-v9 COMMAND evo-cellular-intent-protocol-tests)
set_tests_properties(cellular-session-protocol-v6-v9 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)
@@ -0,0 +1,68 @@
# ADR-0117: Owner-only cellular tick diagnostics protocol v9
## Status
Accepted M11.3 engineering direction under the maintainer's standing authorization
to proceed with recommendations and revisit decisions after implementation. It adds
no gameplay or biological rule.
## Context
ADR-0115 freezes v8 as the owner-filtered exact nearby patch view. Its playtest UI
shows stock but not the controlled cell's reserve or why movement/intake failed, so
players cannot judge the visible cost of steering and feeding. Those observations
already exist in the authoritative one-tick result. The M11.3 probe needs them before
mutation work expands.
## Decision
- Add session protocol v9 as an additive version. Keep v1-v8 byte layouts and behavior
unchanged; v9 retains all v8 actions and owner-filtered perception.
- Add the controlled live cell's exact current reserve by energy and four matter
channels. Include the latest committed one-tick maintenance and movement cost,
whether movement was absent, moved, blocked or unaffordable, and the existing intake
result (not requested, acquired, missing patch or out of contact).
- Send these fields only to the authenticated account that owns that life. Continue
hiding provenance and patches outside the existing ADR-0103 sensor view. A cleared
zero-life view has no diagnostics.
- These diagnostics are a transient presentation of an already committed tick. They
are not checkpointed, do not affect simulation hashes, costs, admission, or tick
resolution, and are not a new biological rule. Immediately after recovery, current
reserve is available while tick effects remain explicitly unavailable until the
next committed tick.
- Reject invalid enum values, nonzero reserved bytes, impossible status combinations,
diagnostics on a zero-life view, and missing diagnostics on a live v9 view. V8
messages remain exactly their frozen layout.
## Alternatives considered
- **Change v8 in place:** rejected because v8 has a frozen fixed layout.
- **Show a client-estimated cost:** rejected because server rules and reserves are
authoritative, and a client estimate could misstate a refusal or intake result.
- **Persist diagnostics:** rejected because replay already derives them from the
committed predecessor and intention; presentation detail need not expand durable
state or simulation-version compatibility.
## Benefits
The exploratory player can distinguish upkeep from motion, see remaining reserve,
and understand whether feeding succeeded, without exposing more of the world or
changing biological outcomes.
## Costs
The owner-filtered wire contract and UI gain fields. Session protocol v9 needs
parallel compatibility and privacy coverage, while v8 remains supported.
## Risks
A stale UI view remains stale after a session loss, so the client must keep the
existing stale-view signal visible. The latest tick report is not a substitute for
repeated playtest observations.
## Consequences
Protocol v9, server report projection, client presentation, bounded codec tests and
owner-isolation tests are required before the M11.3 cellular probe is considered
ready. A later rule change remains subject to its own ADR and simulation-version
review.
+1
View File
@@ -17,6 +17,7 @@
- [ADR-0114: First player life in cellular profile 4](0114-cellular-first-life-publication.md) - accepted M11.3 engineering direction: preserve empty genesis and add an allocator-backed, durable profile-4 birth operation so the 11.3e probe can start through the normal player path.
- [ADR-0115: Owner-filtered cellular perception protocol v8](0115-cellular-owner-perception-v8.md) - carries the existing exact sensor view only to its authenticated owner without changing v1-v7 behavior.
- [ADR-0116: Cellular life-owner routing](0116-cellular-life-owner-routing.md) - reuses authenticated SessionRedirect with an operator-provisioned per-world region route catalog; owner lookup happens before account-control claim.
- [ADR-0117: Owner-only cellular tick diagnostics protocol v9](0117-cellular-owner-tick-diagnostics-v9.md) - adds the live cell's authoritative reserve and latest committed maintenance, movement and intake result to its owner-filtered view; v1-v8 stay frozen and no gameplay rule changes.
- [ADR-0058: Region durability contract](0058-region-durability-contract.md) - accepted M7.1 full checkpoint batches and explicit state closure; storage implementation follows.
+5
View File
@@ -388,6 +388,11 @@ scoped change before starting the next segment.
patch-stock changes. This clarifies transport/scheduling failures; the protocol
still does not report per-tick reserve or itemized maintenance/movement costs,
so resource-cost legibility remains an open probe limitation.
- 11.3e-6a: ADR-0117 defines owner-only protocol v9 diagnostics for current
reserve and the latest committed tick's maintenance, movement and intake result.
The v9 codec keeps v8 bytes frozen and rejects malformed status combinations;
standalone MSVC `NDEBUG` protocol tests pass. Server report projection and the
client display remain the next parts of this subsection, with CI still pending.
## Exit boundary
+14
View File
@@ -6598,6 +6598,20 @@ control. GCC 13.2 strict-warning syntax compilation and Visual Studio LLVM
`clang-format` passed; the test binary has not run. CI execution remains
required.
## 2026-10-11 — M11.3e-6a cellular diagnostics protocol v9 (CI pending)
ADR-0117 and `schemas/network/session-v9-cellular-diagnostics.md` define an
additive owner-only report of current reserve and latest committed tick effects.
The v8 message stays byte-identical. The codec rejects malformed enums,
reserved bytes, impossible status combinations and missing live-life diagnostics.
Visual Studio LLVM `clang-format` and `git diff --check` passed. MSVC 19.44
compiled the modified codec and protocol test with `/W4 /WX`, `/DNDEBUG`; the
standalone protocol test executable passed its v6, v7, v8 and v9 checks. The
configured CMake/Ninja build still stalls before compilation at its glob
recheck. The CI network suite remains pending; no server/client integration or
live cellular playtest is claimed for this contract-only slice.
## 2026-10-11 — M11.3e-5 readable cellular action feedback (CI pending)
The cellular client now explains each protocol admission status and durable
+38 -9
View File
@@ -3,6 +3,7 @@
#include <cstddef>
#include <cstdint>
#include <expected>
#include <optional>
#include <span>
#include <string>
#include <variant>
@@ -29,6 +30,8 @@ inline constexpr std::uint16_t session_protocol_v6 = 6;
inline constexpr std::uint16_t session_protocol_v7 = 7;
// v8 adds the authenticated owner's exact, bounded cellular perception view.
inline constexpr std::uint16_t session_protocol_v8 = 8;
// v9 adds owner-only current reserve and last committed tick effects to the v8 view.
inline constexpr std::uint16_t session_protocol_v9 = 9;
inline constexpr std::size_t max_cellular_perceived_patches = 256;
inline constexpr std::size_t session_address_bytes = 64; // Endpoint or server name field.
inline constexpr std::size_t session_datagram_bytes = 1200; // Whole message, ADR-0089.
@@ -77,7 +80,7 @@ enum class AdmitStatus : std::uint8_t {
};
// Wire u16 (SessionAction::kind carries the raw value; admission validates it).
enum class ActionKind : std::uint8_t {
probe = 1, // No effect on biology: proves admission, scheduling and durability (M10.4).
probe = 1, // No effect on biology: proves admission, scheduling and durability (M10.4).
cellular = 2 // v7 biological input, committed with profile-4 state (ADR-0111/0112).
};
enum class ActionResult : std::uint8_t {
@@ -181,12 +184,38 @@ struct CellularPerceivedPatch {
std::uint32_t x_um{}, y_um{};
std::uint64_t energy_pj{};
std::array<std::uint64_t, 4> matter_fg{};
friend bool operator==(const CellularPerceivedPatch&, const CellularPerceivedPatch&) =
default;
friend bool operator==(const CellularPerceivedPatch&, const CellularPerceivedPatch&) = default;
};
enum class CellularMovementResult : std::uint8_t {
not_reported,
no_movement,
moved,
blocked,
insufficient_energy
};
enum class CellularIntakeResult : std::uint8_t {
not_reported,
not_requested,
acquired,
missing_patch,
out_of_contact
};
struct CellularLifeDiagnostics {
std::uint64_t reserve_energy_pj{};
std::array<std::uint64_t, 4> reserve_matter_fg{};
std::uint64_t maintenance_cost_pj{}, movement_cost_pj{};
CellularMovementResult movement{CellularMovementResult::not_reported};
CellularIntakeResult intake{CellularIntakeResult::not_reported};
bool has_tick_effects{};
friend bool operator==(const CellularLifeDiagnostics&,
const CellularLifeDiagnostics&) = default;
};
struct CellularPerception {
std::uint64_t tick{}, life_identity{}; // zero life plus no patches clears the view.
std::uint64_t tick{}, life_identity{}; // zero life plus no patches clears the view.
std::vector<CellularPerceivedPatch> patches; // strictly ordered by (x_um, y_um).
// Present only on v9 for an active life. The values are authoritative observations,
// not client claims or additional simulation state.
std::optional<CellularLifeDiagnostics> diagnostics;
friend bool operator==(const CellularPerception&, const CellularPerception&) = default;
};
struct IntentionReceipt {
@@ -301,11 +330,11 @@ struct SessionRedirect {
};
using SessionMessage =
std::variant<SessionHello, SessionWelcome, SessionRefresh, SessionRefreshResult, SessionClose,
SessionIntention, CellularIntention, CellularAction, IntentionReceipt, SimulatedThrough,
SessionAction, ActionReceipt, ActionOutcome, ActionQuery, SessionInterest,
SnapshotChunk, SnapshotAck, HandoffOffer, SessionRedirect, PrimitiveLifeRequest,
PrimitiveLifeReceipt, PrimitiveLifeOutcome, PrimitiveLifeQuery,
CellularPerception>;
SessionIntention, CellularIntention, CellularAction, IntentionReceipt,
SimulatedThrough, SessionAction, ActionReceipt, ActionOutcome, ActionQuery,
SessionInterest, SnapshotChunk, SnapshotAck, HandoffOffer, SessionRedirect,
PrimitiveLifeRequest, PrimitiveLifeReceipt, PrimitiveLifeOutcome,
PrimitiveLifeQuery, CellularPerception>;
[[nodiscard]] std::vector<std::uint8_t> encode_session(const SessionMessage& message);
[[nodiscard]] std::vector<std::uint8_t> encode_session(const SessionMessage& message,
@@ -0,0 +1,43 @@
# Session protocol v9 cellular owner diagnostics
ADR-0117 defines v9 as an additive extension of the owner-filtered type 24 view
from [v8](session-v8-cellular-perception.md). Versions 1–8 keep their exact
wire layouts. V9 retains the v8 reliable cellular action and patch-perception
behavior, and adds the owning life's current reserve and latest committed tick
effects. The new fields are diagnostic only and do not affect simulation state.
## Type 24
The 8-byte `EVSN` header uses version 9, type 24 and flags 0. The payload starts
with the v8 `tick u64`, `life_identity u64`, and `patch_count u16`, then a fixed
64-byte diagnostics block, then the v8 48-byte patch records. Tick is nonzero.
An active life has a nonzero identity and diagnostics. A cleared zero-life view
has no patches and an all-zero diagnostics block.
| Payload offset | Size | Field |
|---:|---:|---|
| 0 | 8 | server tick |
| 8 | 8 | life identity; zero clears view |
| 16 | 2 | patch count, at most 256 |
| 18 | 8 | current energy reserve, pJ |
| 26 | 32 | current reserve C, N, P, other, each fg |
| 58 | 8 | latest committed maintenance cost, pJ |
| 66 | 8 | latest committed movement cost, pJ |
| 74 | 1 | movement result: 0 unavailable, 1 no movement requested, 2 moved, 3 blocked, 4 insufficient energy |
| 75 | 1 | intake result: 0 unavailable, 1 not requested, 2 acquired, 3 patch missing, 4 out of contact |
| 76 | 1 | latest tick effects present: 0 or 1 |
| 77 | 5 | reserved, all zero |
| 82 | 48 × count | exact visible patch addresses and inventory, unchanged from v8 |
When the result-present flag is zero, both costs are zero and the movement/intake
results are 0. When present, neither result may be 0. A zero life may not carry
nonzero reserve, cost, status, or result-present fields. The decoder rejects
unknown enum values, invalid result combinations, reserved bits, wrong lengths,
unsorted or duplicate patch addresses, and over-limit patch counts before
publishing a view. The maximum message size is 12,378 bytes including the header.
The server sends the message only to the authenticated account's current v9
session, and only for its currently bound live cell. V8 sessions continue to
receive the byte-identical v8 view without these diagnostics. Tick effects are
transient: after recovery reserve is reported immediately, while effects remain
unavailable until a committed tick has run.
+101 -23
View File
@@ -14,6 +14,9 @@ constexpr std::size_t intention_bytes = (std::size_t{4} * 8) + 4;
constexpr std::size_t cellular_intention_bytes = (std::size_t{4} * 8) + 4 + 1 + 3 + 8;
constexpr std::size_t cellular_action_bytes = (std::size_t{4} * 8) + 4 + 1 + 3 + 8;
constexpr std::size_t cellular_perception_prefix_bytes = 8 + 8 + 2;
constexpr std::size_t cellular_diagnostics_bytes = 64;
constexpr std::size_t cellular_perception_v9_prefix_bytes =
cellular_perception_prefix_bytes + cellular_diagnostics_bytes;
constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8);
constexpr std::size_t intention_receipt_bytes = 8 + 1 + 8;
constexpr std::size_t simulated_bytes = std::size_t{3} * 8;
@@ -33,6 +36,20 @@ constexpr std::size_t life_receipt_bytes = 17;
constexpr std::size_t life_outcome_bytes = 25;
constexpr std::size_t life_query_bytes = 8;
bool valid_diagnostics(const CellularLifeDiagnostics& diagnostics) {
const auto movement = static_cast<std::uint8_t>(diagnostics.movement);
const auto intake = static_cast<std::uint8_t>(diagnostics.intake);
if (movement > static_cast<std::uint8_t>(CellularMovementResult::insufficient_energy) ||
intake > static_cast<std::uint8_t>(CellularIntakeResult::out_of_contact))
return false;
if (!diagnostics.has_tick_effects)
return diagnostics.maintenance_cost_pj == 0 && diagnostics.movement_cost_pj == 0 &&
diagnostics.movement == CellularMovementResult::not_reported &&
diagnostics.intake == CellularIntakeResult::not_reported;
return diagnostics.movement != CellularMovementResult::not_reported &&
diagnostics.intake != CellularIntakeResult::not_reported;
}
void put(std::vector<std::uint8_t>& out, std::uint64_t v, std::size_t count) {
for (std::size_t i = 0; i < count; ++i)
out.push_back(static_cast<std::uint8_t>(v >> (8 * i)));
@@ -106,17 +123,21 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
std::holds_alternative<PrimitiveLifeReceipt>(message) ||
std::holds_alternative<PrimitiveLifeOutcome>(message) ||
std::holds_alternative<PrimitiveLifeQuery>(message);
const auto version = std::holds_alternative<CellularPerception>(message) ? session_protocol_v8
: std::holds_alternative<CellularAction>(message) ? session_protocol_v7
: std::holds_alternative<CellularIntention>(message) ? session_protocol_v6
: is_life ? session_protocol_v5 : session_protocol_version;
const auto version =
std::holds_alternative<CellularPerception>(message)
? (std::get<CellularPerception>(message).diagnostics ? session_protocol_v9
: session_protocol_v8)
: std::holds_alternative<CellularAction>(message) ? session_protocol_v7
: std::holds_alternative<CellularIntention>(message) ? session_protocol_v6
: is_life ? session_protocol_v5
: session_protocol_version;
return encode_session(message, version);
}
std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uint16_t version) {
if (version != session_protocol_version && version != session_protocol_v5 &&
version != session_protocol_v6 && version != session_protocol_v7 &&
version != session_protocol_v8)
version != session_protocol_v8 && version != session_protocol_v9)
return {};
if (version == session_protocol_version &&
(std::holds_alternative<PrimitiveLifeRequest>(message) ||
@@ -127,20 +148,28 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
if (version != session_protocol_v6 && std::holds_alternative<CellularIntention>(message))
return {};
if (version != session_protocol_v7 && version != session_protocol_v8 &&
std::holds_alternative<CellularAction>(message))
version != session_protocol_v9 && std::holds_alternative<CellularAction>(message))
return {};
if (version != session_protocol_v7 && version != session_protocol_v8 &&
std::holds_alternative<ActionOutcome>(message) &&
version != session_protocol_v9 && std::holds_alternative<ActionOutcome>(message) &&
std::get<ActionOutcome>(message).result == ActionResult::committed)
return {};
if (version != session_protocol_v8 && std::holds_alternative<CellularPerception>(message))
if (version != session_protocol_v8 && version != session_protocol_v9 &&
std::holds_alternative<CellularPerception>(message))
return {};
if (const auto* perception = std::get_if<CellularPerception>(&message)) {
if (!perception->tick || perception->patches.size() > max_cellular_perceived_patches ||
(!perception->life_identity && !perception->patches.empty()) ||
!std::ranges::is_sorted(perception->patches, [](const auto& a, const auto& b) {
return std::pair{a.x_um, a.y_um} < std::pair{b.x_um, b.y_um};
}) ||
(version == session_protocol_v8 && perception->diagnostics) ||
(version == session_protocol_v9 && perception->life_identity &&
!perception->diagnostics) ||
(perception->life_identity == 0 && perception->diagnostics) ||
(perception->diagnostics && !valid_diagnostics(*perception->diagnostics)) ||
!std::ranges::is_sorted(perception->patches,
[](const auto& a, const auto& b) {
return std::pair{a.x_um, a.y_um} <
std::pair{b.x_um, b.y_um};
}) ||
std::adjacent_find(perception->patches.begin(), perception->patches.end(),
[](const auto& a, const auto& b) {
return a.x_um == b.x_um && a.y_um == b.y_um;
@@ -213,12 +242,27 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
}
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
auto out = header(SessionMessageType::cellular_perception,
cellular_perception_prefix_bytes +
(version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes) +
m.patches.size() * cellular_perceived_patch_bytes,
version);
put(out, m.tick, 8);
put(out, m.life_identity, 8);
put(out, m.patches.size(), 2);
if (version == session_protocol_v9) {
const auto& d = m.diagnostics;
put(out, d ? d->reserve_energy_pj : 0, 8);
for (const auto value : d ? d->reserve_matter_fg : std::array<std::uint64_t, 4>{})
put(out, value, 8);
put(out, d ? d->maintenance_cost_pj : 0, 8);
put(out, d ? d->movement_cost_pj : 0, 8);
out.push_back(d ? static_cast<std::uint8_t>(d->movement)
: static_cast<std::uint8_t>(CellularMovementResult::not_reported));
out.push_back(d ? static_cast<std::uint8_t>(d->intake)
: static_cast<std::uint8_t>(CellularIntakeResult::not_reported));
out.push_back(d && d->has_tick_effects ? 1 : 0);
put(out, 0, 5);
}
for (const auto& patch : m.patches) {
put(out, patch.x_um, 4);
put(out, patch.y_um, 4);
@@ -360,7 +404,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
const auto wire_version = static_cast<std::uint16_t>(get(bytes, 4, 2));
if (wire_version != session_protocol_version && wire_version != session_protocol_v5 &&
wire_version != session_protocol_v6 && wire_version != session_protocol_v7 &&
wire_version != session_protocol_v8)
wire_version != session_protocol_v8 && wire_version != session_protocol_v9)
return std::unexpected(SessionCodecError::unsupported_version);
if (version)
*version = wire_version;
@@ -443,7 +487,8 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
return m;
}
case static_cast<std::uint8_t>(SessionMessageType::cellular_action): {
if (wire_version != session_protocol_v7 && wire_version != session_protocol_v8)
if (wire_version != session_protocol_v7 && wire_version != session_protocol_v8 &&
wire_version != session_protocol_v9)
return std::unexpected(SessionCodecError::unsupported_version);
if (!expect(cellular_action_bytes))
return std::unexpected(SessionCodecError::wrong_length);
@@ -465,22 +510,55 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
return m;
}
case static_cast<std::uint8_t>(SessionMessageType::cellular_perception): {
if (wire_version != session_protocol_v8)
if (wire_version != session_protocol_v8 && wire_version != session_protocol_v9)
return std::unexpected(SessionCodecError::unsupported_version);
if (payload.size() < cellular_perception_prefix_bytes)
const auto prefix = wire_version == session_protocol_v9
? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes;
if (payload.size() < prefix)
return std::unexpected(SessionCodecError::wrong_length);
const auto count = static_cast<std::size_t>(get(payload, 16, 2));
if (count > max_cellular_perceived_patches ||
payload.size() != cellular_perception_prefix_bytes +
count * cellular_perceived_patch_bytes)
payload.size() != prefix + count * cellular_perceived_patch_bytes)
return std::unexpected(SessionCodecError::wrong_length);
CellularPerception m;
m.tick = get(payload, 0, 8);
m.life_identity = get(payload, 8, 8);
if (!m.tick || (!m.life_identity && count))
return std::unexpected(SessionCodecError::invalid_value);
if (wire_version == session_protocol_v9) {
CellularLifeDiagnostics d;
d.reserve_energy_pj = get(payload, 18, 8);
for (std::size_t channel = 0; channel < d.reserve_matter_fg.size(); ++channel)
d.reserve_matter_fg[channel] = get(payload, 26 + channel * 8, 8);
d.maintenance_cost_pj = get(payload, 58, 8);
d.movement_cost_pj = get(payload, 66, 8);
if (payload[74] >
static_cast<std::uint8_t>(CellularMovementResult::insufficient_energy) ||
payload[75] > static_cast<std::uint8_t>(CellularIntakeResult::out_of_contact) ||
payload[76] > 1 ||
std::ranges::any_of(payload.subspan(77, 5),
[](std::uint8_t value) { return value != 0; }))
return std::unexpected(SessionCodecError::invalid_value);
d.movement = static_cast<CellularMovementResult>(payload[74]);
d.intake = static_cast<CellularIntakeResult>(payload[75]);
d.has_tick_effects = payload[76] != 0;
if (m.life_identity)
m.diagnostics = d;
else if (d.reserve_energy_pj ||
std::ranges::any_of(d.reserve_matter_fg,
[](std::uint64_t value) { return value != 0; }) ||
d.maintenance_cost_pj || d.movement_cost_pj || d.has_tick_effects ||
d.movement != CellularMovementResult::not_reported ||
d.intake != CellularIntakeResult::not_reported)
return std::unexpected(SessionCodecError::invalid_value);
}
if (wire_version == session_protocol_v9 && m.life_identity && !m.diagnostics)
return std::unexpected(SessionCodecError::invalid_value);
if (m.diagnostics && !valid_diagnostics(*m.diagnostics))
return std::unexpected(SessionCodecError::invalid_value);
m.patches.reserve(count);
std::size_t offset = cellular_perception_prefix_bytes;
std::size_t offset = prefix;
for (std::size_t i = 0; i < count; ++i) {
CellularPerceivedPatch patch;
patch.x_um = static_cast<std::uint32_t>(get(payload, offset, 4));
@@ -488,9 +566,8 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
patch.energy_pj = get(payload, offset + 8, 8);
for (std::size_t channel = 0; channel < patch.matter_fg.size(); ++channel)
patch.matter_fg[channel] = get(payload, offset + 16 + channel * 8, 8);
if (!m.patches.empty() &&
!(std::pair{m.patches.back().x_um, m.patches.back().y_um} <
std::pair{patch.x_um, patch.y_um}))
if (!m.patches.empty() && !(std::pair{m.patches.back().x_um, m.patches.back().y_um} <
std::pair{patch.x_um, patch.y_um}))
return std::unexpected(SessionCodecError::invalid_value);
m.patches.push_back(patch);
offset += cellular_perceived_patch_bytes;
@@ -535,7 +612,8 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
if (payload[8] < static_cast<std::uint8_t>(ActionResult::committed_no_effect) ||
payload[8] > static_cast<std::uint8_t>(ActionResult::committed) ||
(payload[8] == static_cast<std::uint8_t>(ActionResult::committed) &&
wire_version != session_protocol_v7 && wire_version != session_protocol_v8))
wire_version != session_protocol_v7 && wire_version != session_protocol_v8 &&
wire_version != session_protocol_v9))
return std::unexpected(SessionCodecError::invalid_value);
const ActionOutcome m{get(payload, 0, 8), static_cast<ActionResult>(payload[8]),
get(payload, 9, 8), get(payload, 17, 8)};
+41 -8
View File
@@ -83,9 +83,9 @@ void v7_reliable_action_is_stable_and_strict() {
CHECK(canonical.size() == cellular_action_input_bytes);
CHECK(decode_cellular_action_input(canonical) == input);
const CellularAction retry{99, 101, 29, 31, -707, 707, true, 4'000, 5'000};
CHECK(encode_cellular_action_input(
{retry.tick, retry.move_x, retry.move_y, retry.has_intake_target,
retry.intake_x_um, retry.intake_y_um}) == canonical);
CHECK(encode_cellular_action_input({retry.tick, retry.move_x, retry.move_y,
retry.has_intake_target, retry.intake_x_um,
retry.intake_y_um}) == canonical);
const auto outcome = ActionOutcome{29, ActionResult::committed, 31, 41};
const auto outcome_bytes = encode_session(SessionMessage{outcome}, session_protocol_v7);
@@ -135,18 +135,50 @@ void v8_perception_is_bounded_and_canonical() {
auto duplicate = perception;
duplicate.patches[1] = duplicate.patches[0];
CHECK(encode_session(SessionMessage{duplicate}).empty());
CHECK(encode_session(SessionMessage{CellularPerception{19, 0, {perception.patches[0]}}})
.empty());
CHECK(
encode_session(SessionMessage{CellularPerception{19, 0, {perception.patches[0]}}}).empty());
const CellularPerception cleared{19, 0, {}};
const auto clear_bytes = encode_session(SessionMessage{cleared});
CHECK(std::get<CellularPerception>(*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<std::uint32_t>(i), 0, 0, {0, 0, 0, 0}});
oversized.patches.push_back({static_cast<std::uint32_t>(i), 0, 0, {0, 0, 0, 0}});
CHECK(encode_session(SessionMessage{oversized}).empty());
}
void v9_perception_carries_only_valid_owner_diagnostics() {
CellularPerception perception{27, 82, {{2'000, 3'000, 17, {4, 5, 6, 7}}}};
perception.diagnostics = CellularLifeDiagnostics{
900, {11, 12, 13, 14}, 21, 8, CellularMovementResult::moved, CellularIntakeResult::acquired,
true};
const auto bytes = encode_session(SessionMessage{perception});
CHECK(!bytes.empty() && bytes.size() == session_header_bytes + 82 + 48);
std::uint16_t version{};
const auto decoded = decode_session(bytes, &version);
CHECK(decoded && version == session_protocol_v9);
CHECK(std::get<CellularPerception>(*decoded) == perception);
CHECK(encode_session(*decoded) == bytes);
auto malformed = bytes;
malformed[session_header_bytes + 77] = 1; // Reserved byte.
CHECK(!decode_session(malformed));
malformed = bytes;
malformed[session_header_bytes + 74] = 0xFF; // Unknown movement result.
CHECK(!decode_session(malformed));
malformed = bytes;
malformed[session_header_bytes + 76] = 0; // Costs/status require a tick result.
CHECK(!decode_session(malformed));
auto missing = perception;
missing.diagnostics.reset();
CHECK(encode_session(SessionMessage{missing}, session_protocol_v9).empty());
CHECK(encode_session(SessionMessage{perception}, session_protocol_v8).empty());
auto cleared = CellularPerception{27, 0, {}};
const auto clear_bytes = encode_session(SessionMessage{cleared}, session_protocol_v9);
CHECK(!clear_bytes.empty());
CHECK(std::get<CellularPerception>(*decode_session(clear_bytes)) == cleared);
}
} // namespace
int main() {
@@ -155,7 +187,8 @@ int main() {
malformed_frames_are_refused();
v7_reliable_action_is_stable_and_strict();
v8_perception_is_bounded_and_canonical();
std::puts("PASS cellular protocol: v6 intention, v7 action, v8 perception framing");
v9_perception_carries_only_valid_owner_diagnostics();
std::puts("PASS cellular protocol: v6 intention, v7 action, v8/v9 perception framing");
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;