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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user