Show what a mutation costs and why an engulf failed
Foundation / checks (ecs) (push) Successful in 2m24s
Foundation / checks (deploy) (push) Successful in 4m7s
Foundation / checks (tsan) (push) Successful in 9m49s
Foundation / checks (client) (push) Successful in 17m12s
Foundation / checks (network) (push) Successful in 19m34s
Foundation / checks (checks) (push) Successful in 43m5s
Foundation / checks (postgres) (push) Successful in 44m57s
Foundation / server-image (push) Successful in 31s
Foundation / postgres-tools (push) Successful in 1m13s
Foundation / image (push) Successful in 3m24s

After the first M11.9 playtest (ADR-0129 amendment): each offered candidate now
carries its funded cost to the cell, construction energy and matter per channel,
so the client can grey out what the reserve cannot pay; a candidate is affordable
by that cost exactly when the owner would fund it. A failed engulf now reports no
contact, prey too large, or membrane too thick. The v10 candidate record grows to
64 bytes, so v10 clients must be rebuilt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-14 15:39:35 -04:00
co-authored by Claude Opus 5.5
parent dba73a97f5
commit 7c16a13dd9
16 changed files with 172 additions and 41 deletions
+15 -3
View File
@@ -177,18 +177,30 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
continue;
auto& predator = candidate.lives[p];
const auto* hunter = survivors[p];
// Why nothing was taken, for the owner: no contact, too large, or membrane.
bool membrane_blocked = false;
predator.engulf = CellularEngulfStatus::no_contact;
for (std::size_t q = 0; q < candidate.lives.size(); ++q) {
if (q == p || taken[q])
continue;
const auto* prey = survivors[q];
const auto& prey_step = candidate.lives[q].candidate;
if (!cellular_footprints_contact(predator.candidate.position, hunter->extent_um,
prey_step.position, prey->extent_um) ||
!product_at_least(hunter->budget.phenotype.total_mass, 1'000,
prey_step.position, prey->extent_um))
continue;
if (!product_at_least(hunter->budget.phenotype.total_mass, 1'000,
prey->budget.phenotype.total_mass,
cellular_engulf_ratio_milli_per_membrane_um *
prey->membrane_um))
prey->membrane_um)) {
membrane_blocked =
membrane_blocked ||
product_at_least(hunter->budget.phenotype.total_mass, 1'000,
prey->budget.phenotype.total_mass,
cellular_engulf_ratio_milli_per_membrane_um);
predator.engulf = membrane_blocked ? CellularEngulfStatus::membrane_too_thick
: CellularEngulfStatus::prey_too_large;
continue;
}
// The prey's whole inventory moves once: body matter and its post-step reserve.
accounting::Inventory whole = prey_step.reserve_after;
if (!add(whole, prey->body))
+19 -7
View File
@@ -16,7 +16,9 @@ constexpr std::size_t cellular_action_bytes = (std::size_t{4} * 8) + 4 + 1 + 3 +
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;
// A candidate: operator, capability, effect, parameter, maintenance, mass, then its cost to
// this cell (energy and four matter channels, ADR-0129).
constexpr std::size_t cellular_offered_candidate_bytes = 2 + 1 + 1 + 4 + 8 + 8 + 8 + (4 * 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 =
@@ -61,7 +63,7 @@ bool valid_diagnostics(const CellularLifeDiagnostics& diagnostics) {
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) ||
diagnostics.engulf > CellularEngulfResult::unsupported ||
diagnostics.engulf > CellularEngulfResult::membrane_too_thick ||
diagnostics.bud > CellularBudOutcome::no_placement)
return false;
if (!diagnostics.has_tick_effects)
@@ -325,6 +327,9 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
put(out, candidate.parameter, 4);
put(out, candidate.maintenance, 8);
put(out, candidate.total_mass, 8);
put(out, candidate.cost_energy_pj, 8);
for (const auto matter : candidate.cost_matter_fg)
put(out, matter, 8);
}
return out;
}
@@ -666,10 +671,17 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
return std::unexpected(SessionCodecError::invalid_value);
for (std::size_t i = 0; i < count; ++i) {
const auto at = cellular_offer_prefix_bytes + i * cellular_offered_candidate_bytes;
m.candidates.push_back({static_cast<std::uint16_t>(get(payload, at, 2)),
payload[at + 2], payload[at + 3],
static_cast<std::uint32_t>(get(payload, at + 4, 4)),
get(payload, at + 8, 8), get(payload, at + 16, 8)});
CellularOfferedCandidate candidate{static_cast<std::uint16_t>(get(payload, at, 2)),
payload[at + 2],
payload[at + 3],
static_cast<std::uint32_t>(get(payload, at + 4, 4)),
get(payload, at + 8, 8),
get(payload, at + 16, 8),
get(payload, at + 24, 8),
{}};
for (std::size_t channel = 0; channel < candidate.cost_matter_fg.size(); ++channel)
candidate.cost_matter_fg[channel] = get(payload, at + 32 + channel * 8, 8);
m.candidates.push_back(candidate);
}
if (!valid_offer(m))
return std::unexpected(SessionCodecError::invalid_value);
@@ -708,7 +720,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
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[77] > static_cast<std::uint8_t>(CellularEngulfResult::membrane_too_thick) ||
payload[78] > static_cast<std::uint8_t>(CellularBudOutcome::no_placement))
return std::unexpected(SessionCodecError::invalid_value);
if (wire_version == session_protocol_v10) {
+35 -7
View File
@@ -6,6 +6,7 @@
#include <algorithm>
#include <array>
#include <chrono>
#include <limits>
#include <utility>
namespace evo::server {
@@ -102,19 +103,46 @@ network::ActionOutcome action_outcome(const FinalCellularMutation& mutation) noe
mutation.tick, mutation.commit_sequence};
}
network::CellularMutationOffer offer_view(const CellularOwnedLife& life, std::uint64_t tick) {
network::CellularMutationOffer offer_view(const CellularLives& state, const CellularOwnedLife& life,
std::uint64_t tick) {
network::CellularMutationOffer view{tick, life.identity.life, 0, 0, {}};
const auto& offer = life.mutation.offer;
if (!offer)
return view;
view.event_index = life.mutation.event_index;
view.offer_tick = life.mutation.offer_tick;
for (const auto& candidate : offer->candidates)
if (view.candidates.size() < network::max_cellular_offered_candidates)
view.candidates.push_back(
{candidate.operator_id, static_cast<std::uint8_t>(candidate.target),
static_cast<std::uint8_t>(candidate.effect), candidate.parameter,
candidate.maintenance, candidate.total_mass});
const auto genome = state.archive().find(life.identity.genome);
// The cost does not depend on the reserve: fund against an ample one and read what it
// takes. The owner funds the real choice against the real reserve.
constexpr std::uint64_t ample = std::uint64_t{1} << 60U;
const accounting::Inventory unlimited{
{ample},
{accounting::Femtograms{ample}, accounting::Femtograms{ample},
accounting::Femtograms{ample}, accounting::Femtograms{ample}}};
constexpr auto probe_identity = std::numeric_limits<std::uint64_t>::max();
for (const auto& candidate : offer->candidates) {
if (view.candidates.size() >= network::max_cellular_offered_candidates)
break;
network::CellularOfferedCandidate shown{candidate.operator_id,
static_cast<std::uint8_t>(candidate.target),
static_cast<std::uint8_t>(candidate.effect),
candidate.parameter,
candidate.maintenance,
candidate.total_mass,
0,
{}};
if (genome) {
const auto funded =
biology::fund_mutation(*genome, offer->context, *offer, candidate.operator_id,
probe_identity, probe_identity, unlimited);
if (funded) {
shown.cost_energy_pj = funded->intake.energy.value;
for (std::size_t channel = 0; channel < shown.cost_matter_fg.size(); ++channel)
shown.cost_matter_fg[channel] = funded->intake.matter[channel].value;
}
}
view.candidates.push_back(shown);
}
std::ranges::sort(view.candidates, {}, &network::CellularOfferedCandidate::operator_id);
return view;
}