Tell the owner what its engulf and bud did, and why its cell died
M11.8 server half (ADR-0129): v10 diagnostics report the tick's engulf and bud results in two reserved bytes, and v10 type 27 tells the owner its life ended with the cause (starved or engulfed). The bridge fills both from the owner's tick feedback and corpses; v9 views are unchanged. Client presentation stays with the maintainer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -238,6 +238,10 @@ class CellularBridge {
|
||||
diagnostics.intake = network::CellularIntakeResult::out_of_contact;
|
||||
break;
|
||||
}
|
||||
// ADR-0129 (v10): what an engulf or bud intention did this tick.
|
||||
diagnostics.engulf = engulf_result(feedback->engulf);
|
||||
diagnostics.bud = feedback->bud ? bud_outcome(*feedback->bud)
|
||||
: network::CellularBudOutcome::not_requested;
|
||||
}
|
||||
view.diagnostics = diagnostics;
|
||||
view.patches.reserve(perceived->size());
|
||||
@@ -257,8 +261,61 @@ class CellularBridge {
|
||||
return std::ranges::find(state.lives(), sent.account,
|
||||
&server::CellularOwnedLife::account) == state.lives().end();
|
||||
});
|
||||
announce_endings(state);
|
||||
replicated_tick_ = tick;
|
||||
}
|
||||
// ADR-0129: an owned life seen at the last replication and now a corpse is announced to
|
||||
// its owner once, with its recorded cause.
|
||||
void announce_endings(const server::CellularLives& state) {
|
||||
for (const auto& [account, life_id] : owned_) {
|
||||
if (std::ranges::find(state.lives(), life_id, [](const server::CellularOwnedLife& l) {
|
||||
return l.identity.life;
|
||||
}) != state.lives().end())
|
||||
continue;
|
||||
const auto corpse =
|
||||
std::ranges::find(state.corpses(), life_id, &server::CellularOwnedCorpse::life_id);
|
||||
if (corpse == state.corpses().end())
|
||||
continue;
|
||||
const auto cause = corpse->cause == biology::CellularDeathCause::starved
|
||||
? network::CellularDeathReason::starved
|
||||
: corpse->cause == biology::CellularDeathCause::engulfed
|
||||
? network::CellularDeathReason::engulfed
|
||||
: network::CellularDeathReason::unrecorded;
|
||||
static_cast<void>(sessions_->send_life_ended(network::AccountId{account},
|
||||
{corpse->died_tick, life_id, cause}));
|
||||
}
|
||||
owned_.clear();
|
||||
for (const auto& life : state.lives())
|
||||
if (life.account != server::LifeAccount{})
|
||||
owned_.emplace_back(life.account, life.identity.life);
|
||||
}
|
||||
static network::CellularEngulfResult engulf_result(biology::CellularEngulfStatus status) {
|
||||
switch (status) {
|
||||
case biology::CellularEngulfStatus::not_requested:
|
||||
return network::CellularEngulfResult::not_requested;
|
||||
case biology::CellularEngulfStatus::engulfed:
|
||||
return network::CellularEngulfResult::engulfed;
|
||||
case biology::CellularEngulfStatus::no_eligible_prey:
|
||||
return network::CellularEngulfResult::no_eligible_prey;
|
||||
case biology::CellularEngulfStatus::unsupported:
|
||||
return network::CellularEngulfResult::unsupported;
|
||||
}
|
||||
return network::CellularEngulfResult::not_reported;
|
||||
}
|
||||
static network::CellularBudOutcome bud_outcome(server::CellularBudResult result) {
|
||||
switch (result) {
|
||||
case server::CellularBudResult::budded:
|
||||
return network::CellularBudOutcome::budded;
|
||||
case server::CellularBudResult::life_died:
|
||||
case server::CellularBudResult::not_able:
|
||||
return network::CellularBudOutcome::not_able;
|
||||
case server::CellularBudResult::insufficient_funding:
|
||||
return network::CellularBudOutcome::insufficient_funding;
|
||||
case server::CellularBudResult::no_placement:
|
||||
return network::CellularBudOutcome::no_placement;
|
||||
}
|
||||
return network::CellularBudOutcome::not_reported;
|
||||
}
|
||||
// 11.4d: the owner's outstanding offer is sent reliably when it changes or the owner's
|
||||
// session changes; an empty view clears an offer that was consumed.
|
||||
void send_offer(const server::CellularOwnedLife& life, std::uint64_t tick) {
|
||||
@@ -311,6 +368,7 @@ class CellularBridge {
|
||||
friend bool operator==(const SentOffer&, const SentOffer&) = default;
|
||||
};
|
||||
std::vector<SentOffer> offers_; // Last offer view sent to each owner.
|
||||
std::vector<std::pair<server::LifeAccount, std::uint64_t>> owned_; // At last replication.
|
||||
bool shutdown_{};
|
||||
};
|
||||
} // namespace evo::server_app
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# ADR-0129: Cellular readable play signals (server half of M11.8)
|
||||
|
||||
## Status
|
||||
|
||||
Accepted (2026-10-14). The engineering client's presentation is the
|
||||
maintainer's; this records only what the server tells the owner.
|
||||
|
||||
## Context
|
||||
|
||||
M11.8 asks that energy and resource needs, mutation tradeoffs and death causes be
|
||||
understandable, with one shared presentation for players and wildlife. The owner
|
||||
already receives its reserve and costs (v9 diagnostics, ADR-0117) and its
|
||||
outstanding offer with each candidate's tradeoffs (v10 type 26, ADR-0121). It did
|
||||
not learn what its engulf or bud intention did, nor why its cell died: the view
|
||||
simply cleared. Wildlife and players already share one replicated presentation.
|
||||
|
||||
## Decision
|
||||
|
||||
- v10 diagnostics use two of the five reserved bytes after the tick-effects flag:
|
||||
byte 77 is the engulf result (0 not reported, 1 not requested, 2 engulfed, 3 no
|
||||
eligible prey, 4 unsupported) and byte 78 the bud result (0 not reported, 1 not
|
||||
requested, 2 budded, 3 not able, 4 insufficient funding, 5 no placement). Both
|
||||
are zero without tick effects. v9 keeps all five bytes zero; the server clears
|
||||
them before sending a v9 view.
|
||||
- v10 adds type 27, `CellularLifeEnded`: the tick, the life identity and the cause
|
||||
(0 not recorded, 1 starved, 2 engulfed), sent once to the owner's v10 session
|
||||
when its life becomes a corpse. The predator is not named.
|
||||
- Suspended cells (ADR-0128) are not replicated, so nothing reveals an absent player.
|
||||
|
||||
## Consequences
|
||||
|
||||
The client can say why a cell died and what a bud or engulf attempt did, without
|
||||
inferring it from a vanished view. v1-v9 are unchanged.
|
||||
@@ -29,6 +29,7 @@
|
||||
- [ADR-0126: PostgreSQL parameter bound for cellular traces](0126-postgres-parameter-bound-for-cellular-traces.md) - each query parameter may hold 4 MiB of text (was 4 KiB, ADR-0059), so every admitted cellular trace (64 ticks of 256 lives as hex bytea) reaches the database in one atomic publication.
|
||||
- [ADR-0127: Cellular permadeath and restart](0127-cellular-permadeath-and-restart.md) - M11.6: schema v37 marks a published life ended once (`end_cellular_lives`, recorded by the host after the death and again on recovery); one active life per account replaces one life per account, so a dead player starts a new primitive founder; a dead account's stale action no longer refuses the whole tick.
|
||||
- [ADR-0128: Cellular offline freeze, linger and resume](0128-cellular-offline-freeze-and-resume.md) - M11.7: a frozen step intent (set for owned lives without a session) freezes biology; owner format 6 / rules 5 track presence: lingering for 200 ticks (10 s, trial) perceivable and vulnerable, then suspended out of the world without aging; an unfrozen intent resumes in place or at the nearest clear spot within three extents; bundle v6, schema v38.
|
||||
- [ADR-0129: Cellular readable play signals](0129-cellular-readable-play-signals.md) - M11.8 server half: v10 diagnostics report engulf and bud results in two reserved bytes, and v10 type 27 tells the owner its life ended and why (starved or engulfed); presentation stays with the maintainer.
|
||||
|
||||
- [ADR-0058: Region durability contract](0058-region-durability-contract.md) - accepted M7.1 full checkpoint batches and explicit state closure; storage implementation follows.
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# M11.8: Deliver readable cellular gameplay UI
|
||||
|
||||
M11.8 makes energy and resource needs, mutation tradeoffs and death causes
|
||||
understandable, with one shared phenotype presentation for players and wildlife.
|
||||
The client UI is the maintainer's (client UI is deferred); this plan tracks the
|
||||
server and protocol signals it needs. Contract:
|
||||
[ADR-0129](../adr/0129-cellular-readable-play-signals.md).
|
||||
|
||||
## What the owner now receives (v10)
|
||||
|
||||
| Need | Signal |
|
||||
|---|---|
|
||||
| Energy and resource needs | Reserve per channel, maintenance and movement cost each tick (v9 diagnostics, ADR-0117) |
|
||||
| Feeding and movement results | Movement and intake results (v9) |
|
||||
| Engulf and bud results | Diagnostics bytes 77-78 (ADR-0129) |
|
||||
| Mutation tradeoffs | Outstanding offer with each candidate's value, maintenance and mass (type 26, ADR-0121) |
|
||||
| Mutation outcome | Receipt and `ActionOutcome` of a choice (ADR-0121) |
|
||||
| Death cause | Type 27: tick, life and cause (ADR-0129) |
|
||||
| Restart | A new life request after death (ADR-0127) |
|
||||
| Shared presentation | Players and wildlife replicate through the same organism presentation; suspended cells are not replicated (ADR-0128) |
|
||||
|
||||
## Remaining (maintainer)
|
||||
|
||||
The engineering client's HUD, death and restart screens, offer chooser, bud
|
||||
control, accessibility and the first-session observation checks.
|
||||
|
||||
## Progress
|
||||
|
||||
- 2026-10-14: server and protocol signals implemented and tested (codec and QUIC
|
||||
delivery tests).
|
||||
@@ -7445,3 +7445,16 @@ Run 374 (e71147f) failed `checks (tsan)`: `cellular-lives-owner` read the bud
|
||||
through a reference into the owner's previous state after the M11.5d controller
|
||||
check advanced a tick. The test now reads the current life. ASan locally confirms
|
||||
the fix; no product code was involved.
|
||||
|
||||
## 2026-10-14 — M11.8 server half: readable play signals (CI pending)
|
||||
|
||||
ADR-0129: v10 diagnostics carry engulf and bud results (bytes 77-78) filled from
|
||||
tick feedback; v10 type 27 `CellularLifeEnded` (tick, life, cause) is sent once to
|
||||
the owner when its life becomes a corpse; v9 views have the new bytes cleared. The
|
||||
client stores the last life end. `cellular-session-protocol-v6-v10` covers the
|
||||
codec (round trip, v9 refusal, unknown values, effects without tick effects,
|
||||
type 27 bounds); `quic-sessions` delivers type 27 to a v10 owner only.
|
||||
|
||||
Executed locally: MSVC Debug 69/69, network 75/75, client-network 89/89; g++-14
|
||||
`-Werror -Wshadow` and clang-tidy-19 on the protocol, sessions, client, tests and
|
||||
server main (with the bridge); clang-format 19.1.5.
|
||||
|
||||
@@ -98,6 +98,8 @@ class RegionSessionClient {
|
||||
// The owned life's outstanding mutation offer (v10), cleared when consumed or absent.
|
||||
[[nodiscard]] const std::optional<network::CellularMutationOffer>&
|
||||
mutation_offer() const noexcept;
|
||||
// The most recent end of the owned life (v10, ADR-0129): its tick and cause.
|
||||
[[nodiscard]] const std::optional<network::CellularLifeEnded>& life_ended() const noexcept;
|
||||
[[nodiscard]] std::expected<client::EnvironmentPresentation, client::ViewError>
|
||||
environment() const;
|
||||
[[nodiscard]] std::expected<client::OrganismPresentation, client::ViewError> organisms() const;
|
||||
|
||||
@@ -67,7 +67,8 @@ enum class SessionMessageType : std::uint8_t {
|
||||
cellular_action = 23,
|
||||
cellular_perception = 24,
|
||||
cellular_mutation_action = 25,
|
||||
cellular_mutation_offer = 26 // Server -> owner, stream (v10).
|
||||
cellular_mutation_offer = 26, // Server -> owner, stream (v10).
|
||||
cellular_life_ended = 27 // Server -> owner, stream (v10).
|
||||
};
|
||||
// Admission answers for intentions and actions (wire 0..10).
|
||||
enum class AdmitStatus : std::uint8_t {
|
||||
@@ -217,6 +218,14 @@ struct CellularMutationOffer {
|
||||
std::vector<CellularOfferedCandidate> candidates;
|
||||
friend bool operator==(const CellularMutationOffer&, const CellularMutationOffer&) = default;
|
||||
};
|
||||
// v10 (ADR-0129): the owner's life ended in ick. Cause 1 starved, 2 engulfed, 0 not
|
||||
// recorded (rules below 3). Death is final; a new life is a new request.
|
||||
enum class CellularDeathReason : std::uint8_t { unrecorded, starved, engulfed };
|
||||
struct CellularLifeEnded {
|
||||
std::uint64_t tick{}, life_identity{};
|
||||
CellularDeathReason cause{};
|
||||
friend bool operator==(const CellularLifeEnded&, const CellularLifeEnded&) = default;
|
||||
};
|
||||
// v8 server-to-owner view. Addresses and current inventory are already filtered by
|
||||
// authoritative cell position/range; provenance and account identity are omitted.
|
||||
struct CellularPerceivedPatch {
|
||||
@@ -239,6 +248,22 @@ enum class CellularIntakeResult : std::uint8_t {
|
||||
missing_patch,
|
||||
out_of_contact
|
||||
};
|
||||
// v10 tick effects (ADR-0129): what an engulf or bud intention did. v9 never reports them.
|
||||
enum class CellularEngulfResult : std::uint8_t {
|
||||
not_reported,
|
||||
not_requested,
|
||||
engulfed,
|
||||
no_eligible_prey,
|
||||
unsupported
|
||||
};
|
||||
enum class CellularBudOutcome : std::uint8_t {
|
||||
not_reported,
|
||||
not_requested,
|
||||
budded,
|
||||
not_able, // No reproduction capability, not fully grown, damaged, or suspended.
|
||||
insufficient_funding,
|
||||
no_placement
|
||||
};
|
||||
struct CellularLifeDiagnostics {
|
||||
std::uint64_t reserve_energy_pj{};
|
||||
std::array<std::uint64_t, 4> reserve_matter_fg{};
|
||||
@@ -246,6 +271,8 @@ struct CellularLifeDiagnostics {
|
||||
CellularMovementResult movement{CellularMovementResult::not_reported};
|
||||
CellularIntakeResult intake{CellularIntakeResult::not_reported};
|
||||
bool has_tick_effects{};
|
||||
CellularEngulfResult engulf{CellularEngulfResult::not_reported}; // v10 only.
|
||||
CellularBudOutcome bud{CellularBudOutcome::not_reported}; // v10 only.
|
||||
friend bool operator==(const CellularLifeDiagnostics&,
|
||||
const CellularLifeDiagnostics&) = default;
|
||||
};
|
||||
@@ -374,7 +401,7 @@ using SessionMessage =
|
||||
SessionInterest, SnapshotChunk, SnapshotAck, HandoffOffer, SessionRedirect,
|
||||
PrimitiveLifeRequest, PrimitiveLifeReceipt, PrimitiveLifeOutcome,
|
||||
PrimitiveLifeQuery, CellularPerception, CellularMutationAction,
|
||||
CellularMutationOffer>;
|
||||
CellularMutationOffer, CellularLifeEnded>;
|
||||
|
||||
[[nodiscard]] std::vector<std::uint8_t> encode_session(const SessionMessage& message);
|
||||
[[nodiscard]] std::vector<std::uint8_t> encode_session(const SessionMessage& message,
|
||||
|
||||
@@ -186,6 +186,9 @@ class RegionSessions {
|
||||
// The owner's outstanding offer (11.4d), to the account's current v10 session if any.
|
||||
[[nodiscard]] bool send_mutation_offer(const network::AccountId& account,
|
||||
const network::CellularMutationOffer& offer);
|
||||
// 11.8 (ADR-0129): the owner's life ended, with its cause, to its v10 session if any.
|
||||
[[nodiscard]] bool send_life_ended(const network::AccountId& account,
|
||||
const network::CellularLifeEnded& ended);
|
||||
[[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
|
||||
|
||||
@@ -70,3 +70,15 @@ Each candidate:
|
||||
A message with no candidates clears the client's offer and must carry zero event
|
||||
and offer tick; one with candidates must name a nonzero life, event and offer
|
||||
tick. Types 25 and 26 are not decoded under versions 1–9.
|
||||
|
||||
## v10 tick effects and type 27 (ADR-0129)
|
||||
|
||||
In a v10 cellular perception the diagnostics byte at payload offset 77 is the
|
||||
engulf result (0 not reported, 1 not requested, 2 engulfed, 3 no eligible prey,
|
||||
4 unsupported) and byte 78 the bud result (0 not reported, 1 not requested,
|
||||
2 budded, 3 not able, 4 insufficient funding, 5 no placement); bytes 79-81 stay
|
||||
zero, and both results are zero without tick effects. v9 keeps bytes 77-81 zero.
|
||||
|
||||
Type 27 (server to owner, reliable stream, v10 only) is exactly 24 bytes: the
|
||||
tick (u64, nonzero), the life identity (u64, nonzero), the cause (u8: 0 not
|
||||
recorded, 1 starved, 2 engulfed) and seven zero bytes.
|
||||
|
||||
@@ -30,6 +30,7 @@ struct RegionSessionClient::Impl {
|
||||
std::optional<network::SnapshotAssembler> snapshots;
|
||||
std::optional<network::CellularPerception> cellular_perception;
|
||||
std::optional<network::CellularMutationOffer> mutation_offer;
|
||||
std::optional<network::CellularLifeEnded> life_ended;
|
||||
std::uint64_t snapshot_chunks{}, snapshot_bytes{};
|
||||
std::optional<network::HandoffOffer> handoff; // v4: continue at another region.
|
||||
std::optional<network::RegionAddress> redirect; // v4: the probe is owned elsewhere.
|
||||
@@ -147,6 +148,12 @@ struct RegionSessionClient::Impl {
|
||||
cellular_perception = *m;
|
||||
return;
|
||||
}
|
||||
if (const auto* m = std::get_if<network::CellularLifeEnded>(&*decoded)) {
|
||||
seen_tick(m->tick);
|
||||
life_ended = *m;
|
||||
mutation_offer.reset(); // A dead life has no offer.
|
||||
return;
|
||||
}
|
||||
if (const auto* m = std::get_if<network::CellularMutationOffer>(&*decoded)) {
|
||||
seen_tick(m->tick);
|
||||
if (m->candidates.empty())
|
||||
@@ -395,6 +402,10 @@ RegionSessionClient::mutation_offer() const noexcept {
|
||||
return impl_->mutation_offer;
|
||||
}
|
||||
|
||||
const std::optional<network::CellularLifeEnded>& RegionSessionClient::life_ended() const noexcept {
|
||||
return impl_->life_ended;
|
||||
}
|
||||
|
||||
std::expected<client::EnvironmentPresentation, client::ViewError>
|
||||
RegionSessionClient::environment() const {
|
||||
const auto& snapshots = impl_->snapshots;
|
||||
|
||||
@@ -15,6 +15,7 @@ constexpr std::size_t cellular_intention_bytes = (std::size_t{4} * 8) + 4 + 1 +
|
||||
constexpr std::size_t cellular_action_bytes = (std::size_t{4} * 8) + 4 + 1 + 3 + 8;
|
||||
constexpr std::size_t cellular_mutation_action_bytes = (std::size_t{7} * 8) + 2 + 6;
|
||||
constexpr std::size_t cellular_offer_prefix_bytes = (std::size_t{4} * 8) + 2 + 6;
|
||||
constexpr std::size_t cellular_life_ended_bytes = (std::size_t{2} * 8) + 1 + 7;
|
||||
constexpr std::size_t cellular_offered_candidate_bytes = 2 + 1 + 1 + 4 + 8 + 8;
|
||||
constexpr std::size_t cellular_perception_prefix_bytes = 8 + 8 + 2;
|
||||
constexpr std::size_t cellular_diagnostics_bytes = 64;
|
||||
@@ -59,12 +60,16 @@ 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))
|
||||
intake > static_cast<std::uint8_t>(CellularIntakeResult::out_of_contact) ||
|
||||
diagnostics.engulf > CellularEngulfResult::unsupported ||
|
||||
diagnostics.bud > CellularBudOutcome::no_placement)
|
||||
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;
|
||||
diagnostics.intake == CellularIntakeResult::not_reported &&
|
||||
diagnostics.engulf == CellularEngulfResult::not_reported &&
|
||||
diagnostics.bud == CellularBudOutcome::not_reported;
|
||||
return diagnostics.movement != CellularMovementResult::not_reported &&
|
||||
diagnostics.intake != CellularIntakeResult::not_reported;
|
||||
}
|
||||
@@ -149,6 +154,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
: std::holds_alternative<CellularAction>(message) ? session_protocol_v7
|
||||
: std::holds_alternative<CellularMutationAction>(message) ? session_protocol_v10
|
||||
: std::holds_alternative<CellularMutationOffer>(message) ? session_protocol_v10
|
||||
: std::holds_alternative<CellularLifeEnded>(message) ? session_protocol_v10
|
||||
: std::holds_alternative<CellularIntention>(message) ? session_protocol_v6
|
||||
: is_life ? session_protocol_v5
|
||||
: session_protocol_version;
|
||||
@@ -183,6 +189,16 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
if (const auto* offer = std::get_if<CellularMutationOffer>(&message);
|
||||
offer && (version != session_protocol_v10 || !valid_offer(*offer)))
|
||||
return {};
|
||||
if (const auto* ended = std::get_if<CellularLifeEnded>(&message);
|
||||
ended && (version != session_protocol_v10 || ended->tick == 0 ||
|
||||
ended->life_identity == 0 || ended->cause > CellularDeathReason::engulfed))
|
||||
return {};
|
||||
// v9 has no room for engulf and bud effects; only v10 reports them (ADR-0129).
|
||||
if (const auto* perception = std::get_if<CellularPerception>(&message);
|
||||
perception && version != session_protocol_v10 && perception->diagnostics &&
|
||||
(perception->diagnostics->engulf != CellularEngulfResult::not_reported ||
|
||||
perception->diagnostics->bud != CellularBudOutcome::not_reported))
|
||||
return {};
|
||||
if (const auto* action = std::get_if<CellularAction>(&message);
|
||||
action && (action->engulf || action->bud) &&
|
||||
(version != session_protocol_v10 || action->has_intake_target || action->intake_x_um ||
|
||||
@@ -284,6 +300,15 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
put(out, 0, 6);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const CellularLifeEnded& m) const {
|
||||
auto out =
|
||||
header(SessionMessageType::cellular_life_ended, cellular_life_ended_bytes, version);
|
||||
put(out, m.tick, 8);
|
||||
put(out, m.life_identity, 8);
|
||||
out.push_back(static_cast<std::uint8_t>(m.cause));
|
||||
put(out, 0, 7);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const CellularMutationOffer& m) const {
|
||||
auto out = header(SessionMessageType::cellular_mutation_offer,
|
||||
cellular_offer_prefix_bytes +
|
||||
@@ -325,7 +350,13 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
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);
|
||||
if (version == session_protocol_v10) {
|
||||
out.push_back(d ? static_cast<std::uint8_t>(d->engulf) : 0);
|
||||
out.push_back(d ? static_cast<std::uint8_t>(d->bud) : 0);
|
||||
put(out, 0, 3);
|
||||
} else {
|
||||
put(out, 0, 5);
|
||||
}
|
||||
}
|
||||
for (const auto& patch : m.patches) {
|
||||
put(out, patch.x_um, 4);
|
||||
@@ -599,6 +630,22 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return m;
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::cellular_life_ended): {
|
||||
if (wire_version != session_protocol_v10)
|
||||
return std::unexpected(SessionCodecError::unsupported_version);
|
||||
if (!expect(cellular_life_ended_bytes))
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
CellularLifeEnded m;
|
||||
m.tick = get(payload, 0, 8);
|
||||
m.life_identity = get(payload, 8, 8);
|
||||
if (m.tick == 0 || m.life_identity == 0 ||
|
||||
payload[16] > static_cast<std::uint8_t>(CellularDeathReason::engulfed) ||
|
||||
std::ranges::any_of(payload.subspan(17, 7),
|
||||
[](std::uint8_t value) { return value != 0; }))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
m.cause = static_cast<CellularDeathReason>(payload[16]);
|
||||
return m;
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::cellular_mutation_offer): {
|
||||
if (wire_version != session_protocol_v10)
|
||||
return std::unexpected(SessionCodecError::unsupported_version);
|
||||
@@ -658,9 +705,16 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
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; }))
|
||||
std::ranges::any_of(payload.subspan(wire_version == session_protocol_v10 ? 79 : 77,
|
||||
wire_version == session_protocol_v10 ? 3 : 5),
|
||||
[](std::uint8_t value) { return value != 0; }) ||
|
||||
payload[77] > static_cast<std::uint8_t>(CellularEngulfResult::unsupported) ||
|
||||
payload[78] > static_cast<std::uint8_t>(CellularBudOutcome::no_placement))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
if (wire_version == session_protocol_v10) {
|
||||
d.engulf = static_cast<CellularEngulfResult>(payload[77]);
|
||||
d.bud = static_cast<CellularBudOutcome>(payload[78]);
|
||||
}
|
||||
d.movement = static_cast<CellularMovementResult>(payload[74]);
|
||||
d.intake = static_cast<CellularIntakeResult>(payload[75]);
|
||||
d.has_tick_effects = payload[76] != 0;
|
||||
@@ -671,7 +725,9 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
[](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)
|
||||
d.intake != CellularIntakeResult::not_reported ||
|
||||
d.engulf != CellularEngulfResult::not_reported ||
|
||||
d.bud != CellularBudOutcome::not_reported)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
}
|
||||
if ((wire_version == session_protocol_v9 || wire_version == session_protocol_v10) &&
|
||||
|
||||
@@ -940,6 +940,10 @@ bool RegionSessions::send_cellular_perception(const network::AccountId& account,
|
||||
auto delivered = perception;
|
||||
if (c.protocol_version == network::session_protocol_v8)
|
||||
delivered.diagnostics.reset();
|
||||
if (c.protocol_version == network::session_protocol_v9 && delivered.diagnostics) {
|
||||
delivered.diagnostics->engulf = network::CellularEngulfResult::not_reported;
|
||||
delivered.diagnostics->bud = network::CellularBudOutcome::not_reported;
|
||||
}
|
||||
return m.endpoint
|
||||
->send_message(c.id, network::encode_session(delivered, c.protocol_version))
|
||||
.has_value();
|
||||
@@ -952,6 +956,11 @@ bool RegionSessions::send_mutation_outcome(const network::AccountId& account,
|
||||
return impl_->send_to_v10_owner(account, outcome);
|
||||
}
|
||||
|
||||
bool RegionSessions::send_life_ended(const network::AccountId& account,
|
||||
const network::CellularLifeEnded& ended) {
|
||||
return impl_->send_to_v10_owner(account, ended);
|
||||
}
|
||||
|
||||
bool RegionSessions::send_mutation_offer(const network::AccountId& account,
|
||||
const network::CellularMutationOffer& offer) {
|
||||
return impl_->send_to_v10_owner(account, offer);
|
||||
|
||||
@@ -288,6 +288,48 @@ void v10_mutation_choice_is_a_strict_reliable_action() {
|
||||
CHECK(std::get<ActionOutcome>(*decode_session(outcome_bytes)) == outcome);
|
||||
}
|
||||
|
||||
// 11.8 (ADR-0129): v10 reports engulf and bud effects and announces a life's end.
|
||||
void v10_effects_and_life_end_are_owner_only() {
|
||||
CellularLifeDiagnostics d;
|
||||
d.reserve_energy_pj = 9;
|
||||
d.maintenance_cost_pj = 2;
|
||||
d.movement = CellularMovementResult::no_movement;
|
||||
d.intake = CellularIntakeResult::not_requested;
|
||||
d.has_tick_effects = true;
|
||||
d.engulf = CellularEngulfResult::no_eligible_prey;
|
||||
d.bud = CellularBudOutcome::insufficient_funding;
|
||||
const CellularPerception perception{40, 7, {}, d};
|
||||
const auto bytes = encode_session(SessionMessage{perception}, session_protocol_v10);
|
||||
CHECK(!bytes.empty() && bytes[session_header_bytes + 77] == 3 &&
|
||||
bytes[session_header_bytes + 78] == 4);
|
||||
CHECK(std::get<CellularPerception>(*decode_session(bytes)) == perception);
|
||||
// v9 has no room for them: an encoder refuses, a decoder refuses non-zero bytes.
|
||||
CHECK(encode_session(SessionMessage{perception}, session_protocol_v9).empty());
|
||||
auto as_v9 = bytes;
|
||||
as_v9[4] = static_cast<std::uint8_t>(session_protocol_v9);
|
||||
CHECK(!decode_session(as_v9));
|
||||
auto unknown_bud = bytes;
|
||||
unknown_bud[session_header_bytes + 78] = 6;
|
||||
CHECK(!decode_session(unknown_bud));
|
||||
auto idle = perception;
|
||||
idle.diagnostics = CellularLifeDiagnostics{};
|
||||
idle.diagnostics->bud = CellularBudOutcome::budded; // Effects need tick effects.
|
||||
CHECK(encode_session(SessionMessage{idle}, session_protocol_v10).empty());
|
||||
|
||||
const CellularLifeEnded ended{41, 7, CellularDeathReason::engulfed};
|
||||
const auto ended_bytes = encode_session(SessionMessage{ended});
|
||||
std::uint16_t version{};
|
||||
const auto decoded = decode_session(ended_bytes, &version);
|
||||
CHECK(ended_bytes.size() == session_header_bytes + 24 && decoded &&
|
||||
version == session_protocol_v10 && std::get<CellularLifeEnded>(*decoded) == ended);
|
||||
CHECK(encode_session(SessionMessage{ended}, session_protocol_v9).empty());
|
||||
auto bad_cause = ended_bytes;
|
||||
bad_cause[session_header_bytes + 16] = 3;
|
||||
CHECK(!decode_session(bad_cause));
|
||||
CHECK(encode_session(SessionMessage{CellularLifeEnded{41, 0, CellularDeathReason::starved}})
|
||||
.empty());
|
||||
}
|
||||
|
||||
// 11.4d: the owner's offer lists unranked candidates in operator order with their tradeoffs.
|
||||
void v10_mutation_offer_is_owner_only_and_canonical() {
|
||||
const CellularMutationOffer offer{
|
||||
@@ -337,6 +379,7 @@ int main() {
|
||||
v9_perception_carries_only_valid_owner_diagnostics();
|
||||
v10_mutation_choice_is_a_strict_reliable_action();
|
||||
v10_mutation_offer_is_owner_only_and_canonical();
|
||||
v10_effects_and_life_end_are_owner_only();
|
||||
std::puts(
|
||||
"PASS cellular protocol: v6 intention, v7 action, v8-v10 perception/action framing");
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
@@ -728,6 +728,12 @@ void cellular_v5_spawn_and_v7_action_share_region_sessions(const Files& f) {
|
||||
CHECK(engulf_client->mutation_offer() == std::optional{offered});
|
||||
CHECK(h.server->send_mutation_offer(account(0xBB), {104, 901, 0, 0, {}}));
|
||||
CHECK(h.until([&] { return !engulf_client->mutation_offer().has_value(); }));
|
||||
// 11.8 (ADR-0129): the end of the owner's life, with its cause, reaches v10 only.
|
||||
const CellularLifeEnded ended{105, 901, CellularDeathReason::starved};
|
||||
CHECK(!h.server->send_life_ended(account(0xB7), ended));
|
||||
CHECK(h.server->send_life_ended(account(0xBB), ended));
|
||||
CHECK(h.until([&] { return engulf_client->life_ended().has_value(); }));
|
||||
CHECK(engulf_client->life_ended() == std::optional{ended});
|
||||
|
||||
h.server->set_default_interest({0, 0, 0, 7});
|
||||
h.source = [](const SessionInterest&) {
|
||||
|
||||
Reference in New Issue
Block a user