Add canonical cellular action input codec
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (ecs) (push) Canceled after 1m39s
Foundation / checks (network) (push) Canceled after 1m8s
Foundation / checks (client) (push) Canceled after 1m49s

This commit is contained in:
dingo
2026-10-10 22:59:05 -04:00
parent 49f6fac3e7
commit a2e5cd5f68
6 changed files with 94 additions and 0 deletions
+5
View File
@@ -186,6 +186,11 @@ scoped change before starting the next segment.
defines a 24-byte canonical biological input, profile-4 commit action block,
and isolated cellular publisher. V7 server admission remains refused until
this input-aware ledger and exact-retry resolution are implemented.
- 11.3d-5c: the protocol library now exposes canonical 24-byte cellular input
encode/decode, excluding reconnect-specific session and epoch values. Focused
tests verify identical retry bytes and reject zero ticks, malformed flags,
reserved bytes and noncanonical absent-target addresses. Durable lookup and
publication remain open.
## Exit boundary
+14
View File
@@ -6138,3 +6138,17 @@ result, exact-byte duplicate rule and isolated profile-4 publisher. V7 login
and action admission remain disabled until these records and the recovery path
are implemented. This contract-only segment was checked with `git diff --check`;
the migration and PostgreSQL process checks are pending.
## 2026-10-10 — M11.3d-5c canonical cellular input bytes (CI pending)
Added the exact 24-byte biological input codec from ADR-0112. It deliberately
omits session and epoch so identical retries across connections have identical
stored bytes. The focused test verifies round-trip and cross-session canonical
equality and rejects zero tick, invalid target flags, nonzero reserved bytes
and absent-target coordinates.
Executed locally: warning-as-error MSVC 19.44 Debug and Release/NDEBUG direct
compile/run of the cellular protocol test and codec, plus `git diff --check`.
The CMake/Ninja target remains stalled before compilation. `clang-format` and
`clang-tidy` are unavailable on this Windows PATH. Durable ledger lookup,
PostgreSQL publication, crash resolution and CI remain pending.
+14
View File
@@ -151,6 +151,16 @@ struct CellularIntention {
std::uint32_t intake_x_um{}, intake_y_um{};
friend bool operator==(const CellularIntention&, const CellularIntention&) = default;
};
// Canonical biological input saved with a durable cellular action. Transport session,
// epoch and action id are deliberately absent so the same retry survives reconnects.
struct CellularActionInput {
std::uint64_t tick{};
std::int16_t move_x{}, move_y{};
bool has_intake_target{};
std::uint32_t intake_x_um{}, intake_y_um{};
friend bool operator==(const CellularActionInput&, const CellularActionInput&) = default;
};
inline constexpr std::size_t cellular_action_input_bytes = 24;
// v7 reliable input: stable account-scoped action id makes retries safe across reconnects.
// The server resolves the optional intake address and all biological effects.
struct CellularAction {
@@ -285,4 +295,8 @@ using SessionMessage =
decode_session(std::span<const std::uint8_t> bytes);
[[nodiscard]] std::expected<SessionMessage, SessionCodecError>
decode_session(std::span<const std::uint8_t> bytes, std::uint16_t* version);
[[nodiscard]] std::array<std::uint8_t, cellular_action_input_bytes>
encode_cellular_action_input(const CellularActionInput& input);
[[nodiscard]] std::expected<CellularActionInput, SessionCodecError>
decode_cellular_action_input(std::span<const std::uint8_t> bytes);
} // namespace evo::network
@@ -31,3 +31,9 @@ and its cellular state committed together; the client reads its authoritative
view for the resulting state. This result is accepted only in v7. Exact retry,
ID conflict, query, and commit resolution behavior follows ADR-0111 and the
durable cellular publication contract.
For persistence, the biological input is canonicalized separately as 24 bytes:
tick u64, movement X/Y i16, target flag u8, three zero bytes, and target X/Y
u32, all little-endian. Session, epoch and action id are excluded; the latter
is already the durable record key. Thus an exact reconnect retry yields the
same stored input bytes.
+35
View File
@@ -581,4 +581,39 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
return std::unexpected(SessionCodecError::unknown_type);
}
}
std::array<std::uint8_t, cellular_action_input_bytes>
encode_cellular_action_input(const CellularActionInput& input) {
std::vector<std::uint8_t> bytes;
bytes.reserve(cellular_action_input_bytes);
put(bytes, input.tick, 8);
put(bytes, static_cast<std::uint16_t>(input.move_x), 2);
put(bytes, static_cast<std::uint16_t>(input.move_y), 2);
bytes.push_back(input.has_intake_target ? 1 : 0);
put(bytes, 0, 3);
put(bytes, input.intake_x_um, 4);
put(bytes, input.intake_y_um, 4);
std::array<std::uint8_t, cellular_action_input_bytes> out{};
std::ranges::copy(bytes, out.begin());
return out;
}
std::expected<CellularActionInput, SessionCodecError>
decode_cellular_action_input(std::span<const std::uint8_t> bytes) {
if (bytes.size() != cellular_action_input_bytes)
return std::unexpected(SessionCodecError::wrong_length);
if (bytes[12] > 1 || bytes[13] != 0 || bytes[14] != 0 || bytes[15] != 0)
return std::unexpected(SessionCodecError::invalid_value);
CellularActionInput input;
input.tick = get(bytes, 0, 8);
input.move_x = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(bytes, 8, 2)));
input.move_y = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(bytes, 10, 2)));
input.has_intake_target = bytes[12] != 0;
input.intake_x_um = static_cast<std::uint32_t>(get(bytes, 16, 4));
input.intake_y_um = static_cast<std::uint32_t>(get(bytes, 20, 4));
if (input.tick == 0 ||
(!input.has_intake_target && (input.intake_x_um != 0 || input.intake_y_um != 0)))
return std::unexpected(SessionCodecError::invalid_value);
return input;
}
} // namespace evo::network
+20
View File
@@ -78,6 +78,15 @@ void v7_reliable_action_is_stable_and_strict() {
CHECK(encode_session(*decoded) == bytes);
CHECK(encode_session(SessionMessage{action}, session_protocol_v6).empty());
const CellularActionInput input{31, -707, 707, true, 4'000, 5'000};
const auto canonical = encode_cellular_action_input(input);
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);
const auto outcome = ActionOutcome{29, ActionResult::committed, 31, 41};
const auto outcome_bytes = encode_session(SessionMessage{outcome}, session_protocol_v7);
CHECK(std::get<ActionOutcome>(*decode_session(outcome_bytes)) == outcome);
@@ -94,6 +103,17 @@ void v7_reliable_action_is_stable_and_strict() {
bad = encode_session(SessionMessage{CellularAction{1, 2, 3, 4, 0, 0, false, 0, 0}});
bad[session_header_bytes + 44] = 1;
CHECK(!decode_session(bad)); // An absent patch has no coordinates.
auto malformed_input = canonical;
malformed_input[12] = 2;
CHECK(!decode_cellular_action_input(malformed_input));
malformed_input = canonical;
malformed_input[13] = 1;
CHECK(!decode_cellular_action_input(malformed_input));
malformed_input = canonical;
// The canonical biological input itself requires a nonzero tick.
std::fill(malformed_input.begin(), malformed_input.begin() + 8, std::uint8_t{0});
CHECK(!decode_cellular_action_input(malformed_input));
}
} // namespace