feat(cellular): session v14, bundle 15 and rules-13 wildlife
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 24s
Foundation / server-image (push) Successful in 4m33s
Foundation / image (push) Successful in 4m59s

Session v14 carries the rules-13 revamp: a body block in the owner's view
(members, emergence threshold, exclusions, Emerge open, payable energy,
mass and the 20 traits), become, emerge and channel exclusions on actions,
become on mutation choices, catalog offers (id, chance, cost) and the
emerged ending. Older sessions never see a v14 field. The client shows
Stay / Become offspring offers named from the shared catalog, continuing
as a bud, the organism and its Emerge button, kept channels, the body and
the emerged end screen.

Bundle 15 (rules 13 on owner format 11) is durable: schema 60 admits it
raw-only, stores become as bit 15 of the choice's operator, widens the
action input and mutation results, and publishes the 14 -> 15 revamp
profile migration. evo-world-clone opens cellular-v10 (cellular-v9 plus the
revamp upgrade from --revamp-tuning), resumable and recoverable.

Wildlife counts reserve matter as energy, waits for the bud fee, grows
organisms one short of emerging, and hunts by the region step's rules-13
engulf test. The play summary adds organisms, offers and the spent pool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-26 07:31:32 -04:00
co-authored by Claude Opus 5.5
parent f454e038a1
commit 4bc5d5eee7
48 changed files with 1602 additions and 174 deletions
+112
View File
@@ -607,6 +607,117 @@ void v13_perception_carries_liquid_motion() {
CHECK(!decode_session(old_brake));
}
// Rules 13: v14 is v13 plus the revamp: the body block in the view, become, emerge and
// exclusions on actions, become on choices, catalog offers and the emerged ending. Earlier
// versions refuse every revamp field.
void v14_carries_the_revamp() {
CellularLifeDiagnostics d;
d.reserve_energy_pj = 9;
d.members = 3;
d.emerge_members = 8;
d.exclude = 0b0101;
d.can_emerge = false;
d.payable_energy_pj = 12'000;
d.total_mass_fg = 24'000'000;
for (std::size_t i = 0; i < d.traits.size(); ++i)
d.traits.at(i) = static_cast<std::uint16_t>(100 + i);
CellularPerception view{77, 7, {}, d};
const auto bytes = encode_session(SessionMessage{view}, session_protocol_v14);
CHECK(bytes.size() == session_header_bytes + 18 + 64 + 40 + 16 + 56 + 64);
std::uint16_t version{};
const auto decoded = decode_session(bytes, &version);
CHECK(decoded && version == session_protocol_v14 &&
std::get<CellularPerception>(*decoded) == view);
CHECK(encode_session(SessionMessage{view}, session_protocol_v13).empty());
// A life has at least one member; exclusions are four channels; the flag is 0 or 1.
auto none = view;
none.diagnostics->members = 0;
CHECK(encode_session(SessionMessage{none}, session_protocol_v14).empty());
constexpr std::size_t block = session_header_bytes + 18 + 64 + 40 + 16 + 56;
auto bad = bytes;
bad[block + 4] = 0x10;
CHECK(!decode_session(bad));
bad = bytes;
bad[block + 5] = 2;
CHECK(!decode_session(bad));
bad = bytes;
bad[block + 6] = 1;
CHECK(!decode_session(bad));
// A cleared view carries an empty block.
CellularPerception cleared{78, 0, {}, std::nullopt};
const auto empty = encode_session(SessionMessage{cleared}, session_protocol_v14);
CHECK(std::get<CellularPerception>(*decode_session(empty)) == cleared);
auto stray = empty;
stray[block] = 1;
CHECK(!decode_session(stray));
// Actions: become with a bud, emerge without a target, exclusions; v14 only.
CellularAction become{1, 2, 3, 4, 0, 0, false, 0, 0};
become.bud = true;
become.become = true;
become.exclude = 0x0F;
CHECK(std::get<CellularAction>(*decode_session(
encode_session(SessionMessage{become}, session_protocol_v14))) == become);
CHECK(encode_session(SessionMessage{become}, session_protocol_v13).empty());
auto lone = become;
lone.bud = false;
CHECK(encode_session(SessionMessage{lone}, session_protocol_v14).empty());
CellularAction emerge{1, 2, 3, 4, 300, 0, false, 0, 0};
emerge.emerge = true;
CHECK(std::get<CellularAction>(*decode_session(
encode_session(SessionMessage{emerge}, session_protocol_v14))) == emerge);
auto feeding = emerge;
feeding.engulf = true;
CHECK(encode_session(SessionMessage{feeding}, session_protocol_v14).empty());
auto wide = become;
wide.exclude = 0x10;
CHECK(encode_session(SessionMessage{wide}, session_protocol_v14).empty());
auto forged = encode_session(SessionMessage{emerge}, session_protocol_v14);
forged[session_header_bytes + 36] = 3; // Emerge with a bud.
CHECK(!decode_session(forged));
// The canonical action input keeps them (schema 60).
CellularActionInput input{9, 0, 0, false, 0, 0, false, true, false, true, false, 0b0011};
const auto stored = encode_cellular_action_input(input);
CHECK(stored[13] == 2 && stored[14] == 3 && decode_cellular_action_input(stored) == input);
auto loose = stored;
loose[12] = 0; // Become without the bud.
CHECK(!decode_cellular_action_input(loose));
// Choices: become travels only on v14.
CellularMutationAction choice{1, 2, 3, 40, 7, 1, 30, 12};
choice.become = true;
CHECK(std::get<CellularMutationAction>(*decode_session(
encode_session(SessionMessage{choice}, session_protocol_v14))) == choice);
CHECK(encode_session(SessionMessage{choice}, session_protocol_v13).empty());
// Offers name catalog mutations with a chance and a cost, nothing operator-shaped.
CellularMutationOffer offer{40, 7, 1, 30, {}};
CellularOfferedCandidate named{};
named.operator_id = 12;
named.parameter = 700'000;
named.cost_energy_pj = 5;
named.cost_matter_fg = {1, 2, 3, 4};
offer.candidates.push_back(named);
named.operator_id = 49;
named.parameter = 10;
offer.candidates.push_back(named);
CHECK(std::get<CellularMutationOffer>(*decode_session(
encode_session(SessionMessage{offer}, session_protocol_v14))) == offer);
auto shaped = offer;
shaped.candidates[0].capability = 1;
CHECK(encode_session(SessionMessage{shaped}, session_protocol_v14).empty());
auto certain = offer;
certain.candidates[0].parameter = 1'000'001;
CHECK(encode_session(SessionMessage{certain}, session_protocol_v14).empty());
// The emerged ending is v14's.
CellularLifeEnded emerged{50, 7, CellularDeathReason::emerged};
CHECK(std::get<CellularLifeEnded>(*decode_session(
encode_session(SessionMessage{emerged}, session_protocol_v14))) == emerged);
CHECK(encode_session(SessionMessage{emerged}, session_protocol_v13).empty());
}
int main() {
try {
round_trip_and_version_gate();
@@ -622,6 +733,7 @@ int main() {
v11_perception_carries_deposits();
v12_perception_carries_light_and_producers();
v13_perception_carries_liquid_motion();
v14_carries_the_revamp();
std::puts(
"PASS cellular protocol: v6 intention, v7 action, v8-v10 perception/action framing");
} catch (const std::exception& error) {
+21
View File
@@ -1,4 +1,5 @@
#include "evo/server/lifecycle/cellular_batch.hpp"
#include "evo/server/lifecycle/cellular_play_summary.hpp"
#include "fixtures/cellular_ecology.hpp"
#include <algorithm>
@@ -348,6 +349,22 @@ void a_choice_splits_the_cell(bool become) {
"a split below full growth was not refused with the offer kept");
closed(*state);
}
// Rules 13 wildlife (the founder after become): its controller's intents are always
// admissible, with matter as energy, fee-aware buds and the revamp engulf test.
if (become) {
for (int tick = 0; tick < 300; ++tick) {
auto intents = checked(wildlife_intents(*state, state->tick() + 1), "wildlife intents");
for (const auto& life : state->lives())
if (life.account != LifeAccount{}) {
CellularLifeIntent owned{life.identity.life, {}};
owned.intent.movement = {600, 300};
intents.push_back(owned);
}
std::ranges::sort(intents, {}, &CellularLifeIntent::life_id);
checked(state->advance_tick(intents), "wildlife tick");
}
closed(*state);
}
const auto copy = restore(*state);
require(copy->snapshot() == state->snapshot(), "a split region did not restore exactly");
}
@@ -589,6 +606,10 @@ void an_organism_forms_grows_and_emerges() {
closed(*state);
require(cellular_can_emerge(life_of(*state, identity), state->revamp_rules()),
"a three-member organism could not emerge");
const auto summary = checked(summarize_cellular_play(*state), "play summary");
require(summary.organisms == 1 && summary.largest_organism == 3 && summary.merged == 1 &&
summary.offers_earned >= 1,
"the play summary missed the organism");
// Emerge: the whole organism leaves as an export and the life ends as emerged.
const auto outgoing = state->boundary_ledger().outgoing;
+145
View File
@@ -323,6 +323,150 @@ void durable_mutation_reservations_bind_to_the_exact_offer() {
(*departed_replay)->lives()[0].mutation.offer.has_value());
}
// Rules 13 (session v14): emerge, become and exclusions reach the owner's intents and the trace
// check, and a catalog choice with become binds to the revamp offer through its reservation.
std::unique_ptr<CellularLives> revamp_owner() {
const auto endowment = biology::primitive_endowment(biology::primitive_founder_v3);
CHECK(endowment);
auto funding = endowment->body;
funding.energy.value = 2 * (endowment->reserve.energy.value + endowment->construction.value);
for (auto& channel : funding.matter)
channel.value *= 2;
auto primitive =
PrimitiveLives::create({94, 1, 1, 17, funding, {{1'000, 1'000}, {1'000, 4'000}}});
CHECK(primitive);
biology::CellularHabitatConfig config{94, 1, 1, 48'000, 48'000, {}};
config.format = biology::cellular_habitat_deposit_format;
auto habitat = biology::CellularHabitat::create(std::move(config));
CHECK(habitat);
auto created =
CellularLives::create(**primitive, std::move(*habitat), {{48'000, 48'000}, 0, 293'150},
CellularLivesProfile::foraging);
CHECK(created);
auto state = std::move(*created);
CHECK(state->advance_tick(std::span<const CellularLifeIntent>{}));
const auto step = [&](auto next) {
CHECK(next);
state = std::move(*next);
};
step(state->migration_upgrade_candidate());
step(state->maturation_upgrade_candidate());
step(state->inheritance_upgrade_candidate());
step(state->photosynthesis_upgrade_candidate({0, 1, {0}}));
step(state->liquid_upgrade_candidate(
{.currents = {5, 48'000, 48'000, 250, 2, 4, 3'000, 6'000, 60, 300},
.founder = {.thrust_q10 = 20'480,
.reverse_thrust_q10 = 20'480,
.forward_drag_ppm = 95'163,
.lateral_drag_ppm = 95'163,
.turn = 3'276},
.deposits = {.drift_radius_um = 200,
.max_drift_q10 = 100 * 1'024,
.drift_decay_ppm = 95'163,
.merged_cap = 8,
.bubble_radius_um = biology::cellular_mote_radius_um}}));
CellularRevampRules rules{.burn_pj_per_kfg = {2'000, 2'000, 2'000, 2'000},
.step = {.membrane_collection_per_mille_per_point = 2,
.engulf_ratio_milli = 1'500,
.engulf_reserve_percent = 100,
.kill_bubble_per_thousand = 500},
.drip_interval_ticks = 20,
.drip_bubble_pj = 20'000'000,
.drip_bubble_fg = 1'000'000,
.reserve_load_per_thousand = 1'000};
rules.offer_interval_ticks = 40;
step(state->revamp_upgrade_candidate(rules));
LifeRequest request{};
request.account.back() = 2;
request.action = 1;
step(state->birth_candidate(request, {101, 101, 101, 101, {state->tick()}}));
return state;
}
void rules_13_actions_and_choices_bind() {
auto state = revamp_owner();
for (int tick = 0; tick < 40; ++tick) {
const std::array swim{CellularLifeIntent{101, {{1'000, 0}, {}}}};
CHECK(state->advance_tick(swim));
}
const auto& life = state->lives().front();
CHECK(life.identity.life == 101 && life.revamp.offer.count == 3);
const auto tick = state->tick() + 1;
const std::array baseline{CellularLifeIntent{101, {}}};
// Emerge and exclusions travel in the canonical input and must match the trace.
const auto input = network::encode_cellular_action_input(
{tick, 300, 0, false, 0, 0, false, false, false, false, true, 0b0101});
const std::array actions{network::CarriedAction{network::AccountId{life.account}, 90, tick,
network::ActionKind::cellular, input}};
const auto prepared = prepare_cellular_session_tick(*state, tick, baseline, actions);
CHECK(prepared && prepared->intents.lives[0].intent.emerge &&
prepared->intents.lives[0].intent.exclude == 0b0101);
CellularBatch batch;
batch.format_version = cellular_batch_inheritance_format;
batch.header = {state->world(), state->region(), state->frame(), {}, {}, state->tick(), tick};
batch.header.predecessor.fill(1);
batch.header.predecessor_digest.fill(2);
batch.ticks.push_back(prepared->intents);
CHECK(match_cellular_actions_to_trace(*state, batch, prepared->actions));
auto kept = batch;
kept.ticks[0].lives[0].intent.exclude = 0;
CHECK(!match_cellular_actions_to_trace(*state, kept, prepared->actions));
// A catalog choice with become (bit 15 of the stored operator).
persistence::CellularMutationReservation reservation;
reservation.account = life.account;
reservation.action_id = 43;
reservation.region = state->region();
reservation.generation = 7;
reservation.target_tick = tick;
reservation.successor_identity = 9'500;
const auto put_field = [&](std::size_t offset, std::uint64_t value, std::size_t bytes) {
for (std::size_t i = 0; i < bytes; ++i)
reservation.input[offset + i] = static_cast<std::uint8_t>(value >> (i * 8U));
};
const auto chosen = life.revamp.offer.ids.at(0);
put_field(0, tick, 8);
put_field(8, 101, 8);
put_field(16, life.revamp.offer.event_index, 8);
put_field(24, life.revamp.offer.offer_tick, 8);
put_field(32, chosen | 0x8000U, 2);
persistence::RegionHead head{};
head.frame = state->frame();
head.sequence = 3;
head.end_tick = state->tick();
head.commit.fill(0x31);
head.digest.fill(0x41);
auto builder = CellularSessionBatchBuilder::create(*state, head);
CHECK(builder);
const std::array reservations{reservation};
CHECK(builder->append(tick, baseline, {}, {}, reservations));
const auto& selection = builder->batch().ticks.back().mutations.front();
CHECK(selection.become && selection.operator_id == chosen &&
builder->mutation_actions().front().input.become &&
encode_cellular_mutation_input(builder->mutation_actions().front())[33] >= 0x80 &&
match_cellular_mutation_actions_to_trace(*state, builder->batch(),
builder->mutation_actions()));
std::vector<CellularMutationOutcome> outcomes;
const auto replayed = replay_cellular_batch(*state, builder->batch(), outcomes);
CHECK(replayed && (*replayed)->snapshot() == builder->candidate().snapshot() &&
outcomes.size() == 1 && outcomes.front().result == CellularMutationResult::split_applied);
// The player became the offspring.
const auto& lives = builder->candidate().lives();
CHECK(std::ranges::find(lives, life.account, &CellularOwnedLife::account)->identity.life !=
101);
// Become with a decline is refused.
auto declined = reservation;
declined.input[32] = 0;
declined.input[33] = 0x80;
auto refusing = CellularSessionBatchBuilder::create(*state, head);
CHECK(refusing);
const std::array declines{declined};
CHECK(refusing->append(tick, baseline, {}, {}, declines).error() ==
CellularSessionBatchError::mutation);
}
void builder_batches_reserved_birth_after_empty_tick() {
auto primitive = PrimitiveLives::create({93, 1, 1, 17, founder_price(1), {{0, 0}}});
CHECK(primitive);
@@ -414,6 +558,7 @@ void unavailable_birth_does_not_freeze_the_tick() {
int main() try {
actions_bind_to_owned_life_and_preserve_other_inputs();
durable_mutation_reservations_bind_to_the_exact_offer();
rules_13_actions_and_choices_bind();
builder_batches_reserved_birth_after_empty_tick();
unavailable_birth_does_not_freeze_the_tick();
std::puts("cellular session batch: ok");
+7 -4
View File
@@ -594,12 +594,15 @@ void cellular_v10(const Files& files) {
sent_view = r.tick;
view_session = *session;
sent_life = life;
// The trial client speaks v14: a single cell's view carries its body block, and a
// rules-13 region offers catalog mutations (here id 3 at a 50% chance).
CellularLifeDiagnostics body{};
body.members = 1;
CHECK(r.sessions->send_cellular_perception(
owner,
{r.tick, life, {}, life ? std::optional{CellularLifeDiagnostics{}} : std::nullopt}));
owner, {r.tick, life, {}, life ? std::optional{body} : std::nullopt}));
if (offer && life != 0)
CHECK(r.sessions->send_mutation_offer(owner,
{r.tick, life, 1, 99, {{3, 2, 0, 50, 20, 30}}}));
CHECK(r.sessions->send_mutation_offer(
owner, {r.tick, life, 1, 99, {{3, 0, 0, 500'000, 0, 0}}}, true));
};
Client c;
CHECK(c.host.connect(
+30
View File
@@ -496,6 +496,35 @@ void cellular_action_effects() {
play.observe({204, 700, {}, effect});
CHECK(play.history().back().engulf == CellularEngulfResult::membrane_too_thick);
}
// Rules 13 (v14): a bud may carry become, a choice its become, Emerge is a discrete action,
// and an emerged ending ends the life like any other.
void cellular_revamp_actions() {
using namespace evo::client_app;
using namespace evo::network;
CellularPlay play;
play.initialize(70);
play.connected();
CellularLifeDiagnostics body;
body.members = 1;
play.observe({300, 800, {}, body});
CHECK(play.queue(CellAction::bud, 301, {}, true) && required(play.pending()).become);
play.sent();
play.outcome({required(play.pending()).id, ActionResult::committed, 301, 1});
CHECK(play.history().back().become);
CHECK(play.queue(CellAction::engulf, 302, {}, true) && !required(play.pending()).become);
play.sent();
play.outcome({required(play.pending()).id, ActionResult::committed, 302, 1});
play.observe_offer(CellularMutationOffer{303, 800, 1, 300, {{12, 0, 0, 700'000, 0, 0}}});
CHECK(play.queue(CellAction::mutation, 304, {800, 1, 300, 12, true}) &&
required(play.pending()).choice.become);
play.sent();
play.outcome({required(play.pending()).id, ActionResult::committed, 304, 1});
CHECK(play.queue(CellAction::emerge, 305));
play.sent();
play.observe_end({305, 800, CellularDeathReason::emerged});
CHECK(play.life() == 0 && play.ended() && play.ended()->cause == CellularDeathReason::emerged &&
play.can_restart());
}
void cellular_energy_and_birth_wait() {
using namespace evo::client_app;
using namespace evo::network;
@@ -576,6 +605,7 @@ int main() try {
session_host();
cellular_play();
cellular_action_effects();
cellular_revamp_actions();
cellular_energy_and_birth_wait();
cellular_assistance();
cell_headings();
+1 -1
View File
@@ -371,7 +371,7 @@ void session_codec() {
mutated.at(0) ^= 1;
CHECK(refused(decode_session(mutated), SessionCodecError::bad_magic));
mutated = bytes;
mutated.at(4) = 14; // A future version; protocol versions through 13 are supported.
mutated.at(4) = 15; // A future version; protocol versions through 14 are supported.
CHECK(refused(decode_session(mutated), SessionCodecError::unsupported_version));
mutated = bytes;
mutated.at(7) = 1;
+2 -1
View File
@@ -225,6 +225,7 @@ void upgrade_across_migration_and_barrier() {
" -v migration_sha_57=$(s 0057_photosynthesis_bundle.sql)"
" -v migration_sha_58=$(s 0058_liquid_bundle.sql)"
" -v migration_sha_59=$(s 0059_durable_mutation_queue.sql)"
" -v migration_sha_60=$(s 0060_cellular_revamp_bundle.sql)"
" -v runtime_role=evo_runtime_test -f migrations/apply.sql"
" > /dev/null 2>&1") != 0);
CHECK(history(*owner_db) == "1,2,3,4,5,6,7");
@@ -242,7 +243,7 @@ void upgrade_across_migration_and_barrier() {
"tools/migrate-postgres.sh\" > /dev/null") == 0);
CHECK(history(*owner_db) == "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
"25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,"
"47,48,49,50,51,52,53,54,55,56,57,58,59");
"47,48,49,50,51,52,53,54,55,56,57,58,59,60");
CHECK(scalar(*owner_db, "SELECT (c.condeferrable AND c.condeferred AND "
"c.confrelid = 'evolution.region_commits'::regclass)::text "
"FROM pg_catalog.pg_constraint c WHERE c.conrelid = "
+39
View File
@@ -810,6 +810,45 @@ void cellular_v9_provisioning_declares_liquid() {
const auto manifest = decode_manifest(head->manifest);
CHECK(manifest && manifest->cellular_versions == cellular_v14_versions &&
manifest->history_profile == cellular_revision_history_profile);
// Rules 13 (ADR-0179): cellular-v10 is cellular-v9 plus the durable bundle 14 -> 15 revamp
// upgrade declaring the Git revamp tuning file's rules; a rerun reports the region.
{
const ServerRegion v10{{9779, 1}, fresh("cellular-v10-provision-9779")};
const std::string revamp =
env("EVO_SOURCE_ROOT") + "/deploy/kubernetes/region/dev/tuning/cellular-revamp.tuning";
const std::string v10_commit = "c0c81e5c0f7e1d2ba1a0ce5c0f7e1d2f";
provision_cellular(v10, "9779", "cellular-v10", build, v10_commit, motes, code, "--motes",
{"--light-pj", "40", "--tuning", tuning});
CHECK(code != 0); // cellular-v10 requires --revamp-tuning.
const auto made = provision_cellular(
v10, "9779", "cellular-v10", build, v10_commit, motes, code, "--motes",
{"--light-pj", "40", "--tuning", tuning, "--revamp-tuning", revamp});
CHECK(code == 0 && has(made, "provisioned world=9779 region=1 sequence=7 tick=1"));
const auto rerun = provision_cellular(
v10, "9779", "cellular-v10", build, v10_commit, motes, code, "--motes",
{"--light-pj", "40", "--tuning", tuning, "--revamp-tuning", revamp});
CHECK(code == 0 && has(rerun, "already-provisioned world=9779 region=1 sequence=7 tick=1"));
const auto revamp_head = load_region_checkpoint(*db, v10.key, 5s);
CHECK(revamp_head);
const auto revamp_manifest = decode_manifest(revamp_head->manifest);
CHECK(revamp_manifest && revamp_manifest->cellular_versions == cellular_v15_versions &&
revamp_manifest->history_profile == cellular_revision_history_profile);
// The upgrade's evidence recovers: the target re-derives from the source and its rules.
Sha256Digest retained{};
retained.fill(0xEE);
auto store =
FilesystemObjectStore::open(v10.root, v10.key, evo::server::max_cellular_lives_bytes);
CHECK(store);
const auto lease =
acquire_region_lease(*db, v10.key, retained, std::chrono::seconds{30}, 5s);
CHECK(lease);
const std::array<Sha256Digest, 1> builds{retained};
const auto recovered =
recover_cellular_checkpoint(*db, **store, v10.key, *lease, builds, 5s);
CHECK(recovered &&
recovered->state->rules_version() == evo::server::cellular_lives_revamp_rules);
CHECK(release_region_lease(*db, v10.key, *lease, 5s));
}
#ifdef EVO_POSTGRES_M10
// A player is born on the liquid head and swims and brakes through the live server path:
// host reservation, session batch builder, host publication with a braking trace.