feat: durable liquid regions (bundle 14, schema 58), cellular-v9 and session v13
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m25s
Foundation / postgres-tools (push) Successful in 1m12s
Foundation / server-image (push) Successful in 4m20s
Foundation / image (push) Successful in 4m54s

ADR-0178. Bundle 14 (rules 12 on owner format 10) is admitted by schema 58
through parser-local normalization to bundle 13, with an exact fenced 13 -> 14
upgrade whose only input, the liquid rules, recovery reads from the target.
Schema 58 also widens the canonical action input: byte 13 bit 0 is brake.

evo-world-clone gains the cellular-v9 opening: cellular-v8 followed by the liquid
upgrade from --tuning FILE (region size must match) and an optional
--current-seed; resumable and idempotent at bundle 14.

Session v13 adds the owner's velocity, heading and the region's current
configuration to its perception, each deposit's world velocity, and a brake on
cellular actions; older sessions keep their layouts. A rules-12 server lists every
pool and the nearest 256 moving bubbles. The client speaks v13, brakes on Space
(rebindable; older controls files take the default), draws currents as drifting
streaks and carries bubbles along their velocities between perceptions.

Tests: protocol v13 round trips and refusals, action-input brake, controls files,
and a PostgreSQL cellular-v9 provisioning test whose player is born, swims and
brakes through the live host. Full local PostgreSQL qualification, the Linux debug
suite and the Windows client suite pass. Refreshes the DEV session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-21 18:08:59 -04:00
co-authored by Claude Opus 5.5
parent 3f82795c18
commit d2f603b582
39 changed files with 1106 additions and 103 deletions
+67 -1
View File
@@ -110,9 +110,14 @@ void v7_reliable_action_is_stable_and_strict() {
auto malformed_input = canonical;
malformed_input[12] = 2;
CHECK(!decode_cellular_action_input(malformed_input));
// Byte 13 is a flags byte (schema 58): bit 0 brake, every other bit refused.
malformed_input = canonical;
malformed_input[13] = 1;
malformed_input[13] = 2;
CHECK(!decode_cellular_action_input(malformed_input));
auto braking_input = canonical;
braking_input[13] = 1;
const auto braking = decode_cellular_action_input(braking_input);
CHECK(braking && braking->brake && encode_cellular_action_input(*braking) == braking_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});
@@ -542,6 +547,66 @@ void v12_perception_carries_light_and_producers() {
CHECK(encode_session(SessionMessage{offer}, session_protocol_v12).empty());
}
// Rules 12: v13 is v12 plus liquid motion: the owner's velocity and heading and the region's
// current configuration in its view, each deposit's world velocity, and a brake on actions.
// Earlier versions refuse every liquid field.
void v13_perception_carries_liquid_motion() {
CellularLifeDiagnostics d;
d.reserve_energy_pj = 9;
d.light_pj = 3;
d.velocity_x_q10 = -190 * 1'024;
d.velocity_y_q10 = 12;
d.heading = 49'152;
CellularPerception view{77, 7, {}, d};
CellularPerceivedDeposit bubble{9, 9'000, 400, 30, CellularDepositShape::bubble,
false, {1, 0, 0, 4, 0}};
bubble.velocity_x_um_s = -250;
bubble.velocity_y_um_s = 60;
view.deposits.push_back(bubble);
view.currents = CellularCurrentsView{5, 60'000, 60'000, 250, 2, 4, 3'000, 6'000, 60, 300};
const auto bytes = encode_session(SessionMessage{view}, session_protocol_v13);
CHECK(bytes.size() == session_header_bytes + 18 + 64 + 40 + 16 + 56 + 30);
std::uint16_t version{};
const auto decoded = decode_session(bytes, &version);
CHECK(decoded && version == session_protocol_v13 &&
std::get<CellularPerception>(*decoded) == view);
// v12 has room for none of it.
CHECK(encode_session(SessionMessage{view}, session_protocol_v12).empty());
auto still = view;
still.currents.reset();
still.diagnostics->velocity_x_q10 = still.diagnostics->velocity_y_q10 = 0;
still.diagnostics->heading = 0;
still.deposits[0].velocity_x_um_s = still.deposits[0].velocity_y_um_s = 0;
CHECK(!encode_session(SessionMessage{still}, session_protocol_v12).empty());
// A region without currents sends a v13 view with the liquid flag clear.
CHECK(std::get<CellularPerception>(*decode_session(
encode_session(SessionMessage{still}, session_protocol_v13))) == still);
// The flag is 0 or 1, the reserved byte zero, and a cleared view carries no currents.
constexpr std::size_t flags = session_header_bytes + 18 + 64 + 40 + 16 + 10;
auto bad = bytes;
bad[flags] = 2;
CHECK(!decode_session(bad));
bad = bytes;
bad[flags + 1] = 1;
CHECK(!decode_session(bad));
auto cleared = still;
cleared.life_identity = 0;
cleared.diagnostics.reset();
cleared.deposits.clear();
cleared.currents = view.currents;
CHECK(encode_session(SessionMessage{cleared}, session_protocol_v13).empty());
// A brake travels only on v13 actions.
CellularAction braking{1, 2, 3, 4, 500, 0, false, 0, 0};
braking.brake = true;
const auto action = encode_session(SessionMessage{braking}, session_protocol_v13);
CHECK(std::get<CellularAction>(*decode_session(action)) == braking);
auto old_brake = encode_session(SessionMessage{CellularAction{1, 2, 3, 4, 500, 0, false, 0, 0}},
session_protocol_v12);
old_brake[session_header_bytes + 37] = 1;
CHECK(!decode_session(old_brake));
}
int main() {
try {
round_trip_and_version_gate();
@@ -556,6 +621,7 @@ int main() {
v10_effects_and_life_end_are_owner_only();
v11_perception_carries_deposits();
v12_perception_carries_light_and_producers();
v13_perception_carries_liquid_motion();
std::puts(
"PASS cellular protocol: v6 intention, v7 action, v8-v10 perception/action framing");
} catch (const std::exception& error) {
+1 -1
View File
@@ -15,7 +15,7 @@ using namespace evo::fixture;
constexpr biology::CellularArea area{48'000, 48'000};
CellularLiquidRules rules(std::uint64_t seed = 5) {
return {.currents = {seed, area.width_um, area.height_um, 250, 2, 4, 3'000, 6'000, 60, 300},
return {.currents = {seed, 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,
+8
View File
@@ -126,7 +126,15 @@ void file_format() {
CHECK(refused(parse_bindings("move_up W\n"), BindingError::malformed));
CHECK(refused(parse_bindings("evo-controls 2\n"), BindingError::unsupported_version));
CHECK(refused(parse_bindings("evo-controls 1 extra\n"), BindingError::malformed));
// Original actions stay required; one added later (brake) takes its default key when it
// is free, and is refused when another action already holds it.
CHECK(refused(parse_bindings(without("pan_down")), BindingError::missing_primary));
CHECK(parse_bindings(without("brake")) == *custom);
auto held = without("brake");
const auto left = held.find("move_left A\n");
CHECK(left != std::string::npos);
held.replace(left, 12, "move_left A Space\n");
CHECK(refused(parse_bindings(held), BindingError::missing_primary));
CHECK(refused(parse_bindings(text + "move_up W\n"), BindingError::malformed));
CHECK(refused(parse_bindings(text + "jump Space\n"), BindingError::malformed));
CHECK(refused(parse_bindings(without("move_up") + "move_up w\n"), BindingError::malformed));
+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) = 13; // A future version; protocol versions through 12 are supported.
mutated.at(4) = 14; // A future version; protocol versions through 13 are supported.
CHECK(refused(decode_session(mutated), SessionCodecError::unsupported_version));
mutated = bytes;
mutated.at(7) = 1;
+2 -1
View File
@@ -223,6 +223,7 @@ void upgrade_across_migration_and_barrier() {
" -v migration_sha_55=$(s 0055_retained_cellular_plans.sql)"
" -v migration_sha_56=$(s 0056_cellular_environment_publication.sql)"
" -v migration_sha_57=$(s 0057_photosynthesis_bundle.sql)"
" -v migration_sha_58=$(s 0058_liquid_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");
@@ -240,7 +241,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");
"47,48,49,50,51,52,53,54,55,56,57,58");
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 = "
+123
View File
@@ -2,6 +2,7 @@
// the object volume's free-space reserve, a genuinely failing write, the
// check-store probe (retention across runs, missing-volume refusal, privilege
// boundary) and a server whose volume is full. Run by tools/ci/postgres-check.sh.
#include "evo/biology/cellular_tuning.hpp"
#include "evo/persistence/account_control_store.hpp"
#include "evo/persistence/checkpoint_store.hpp"
#include "evo/persistence/region_checkpoint.hpp"
@@ -13,6 +14,7 @@
#include "fixtures/server_process.hpp"
#include <algorithm>
#include <csignal>
#include <fstream>
#include <source_location>
#include <sys/resource.h>
@@ -753,6 +755,126 @@ void cellular_v8_provisioning_declares_light() {
#endif
}
// Rules 12 (ADR-0177): cellular-v9 is cellular-v8 followed by the 13 -> 14 liquid upgrade from
// the Git tuning file, whose region size must match the opening; resumable and idempotent.
void cellular_v9_provisioning_declares_liquid() {
const ServerRegion r{{9777, 1}, fresh("cellular-v9-provision-9777")};
const std::string build(64, 'e');
const std::string commit = "b0b81e5c0f7e1d2ba1a0ce5c0f7e1d2e"; // Unique to this test.
const std::string motes = "40,1,2000000,50000,20000,0,0";
const auto write_tuning = [&](std::uint32_t side) {
auto parsed = evo::biology::parse_cellular_tuning(
"tuning.version = 1\nregion.width_um = 60000\nregion.height_um = 60000\n"
"region.organism_cap = 2000\nregion.deposit_limit = 8192\n"
"region.perception_radius_um = 5000\nfounder.thrust_um_per_s2 = 400\n"
"founder.reverse_thrust_um_per_s2 = 400\nfounder.drag_ppm_per_tick = 95163\n"
"founder.lateral_drag_ppm_per_tick = 95163\nfounder.turn_heading_per_s = 65536\n"
"currents.min_count = 2\ncurrents.max_count = 4\ncurrents.min_width_um = 3000\n"
"currents.max_width_um = 6000\ncurrents.min_speed_um_per_s = 60\n"
"currents.max_speed_um_per_s = 300\ncurrents.grid_pitch_um = 250\n"
"food.merged_bubble_cap_multiple = 8\nfood.visible_moving_bubbles = 256\n"
"food.induced_drift_radius_um = 200\nfood.induced_drift_max_um_per_s = 100\n"
"food.induced_drift_decay_ppm_per_tick = 95163\nthermal.ambient_min_mk = 278150\n"
"thermal.ambient_max_mk = 313150\nfounder.preferred_mk = 293150\n"
"founder.comfort_band_mk = 5000\nfounder.body_tau_ms = 20000\n"
"founder.lethal_cold_mk = 273150\nfounder.lethal_heat_mk = 318150\n"
"thermal.off_preference_per_mille_per_k = 80\n"
"thermal.transition_per_mille_per_k = 40\nthermal.multiplier_cap_per_mille = 8000\n"
"lifecycle.logout_delay_ms = 10000\nmutation.step_points = 5\n"
"mutation.paired_points = 2\nmutation.recovery_floor_per_mille = 100\n"
"mutation.offer_interval_ms = 25000\nmutation.offer_options = 3\n");
CHECK(parsed);
parsed->region_width_um = parsed->region_height_um = side;
const auto path = r.root / ("cellular-" + std::to_string(side) + ".tuning");
std::ofstream{path, std::ios::binary} << evo::biology::encode_cellular_tuning(*parsed);
return path.string();
};
int code = -1;
provision_cellular(r, "9777", "cellular-v9", build, commit, motes, code, "--motes",
{"--light-pj", "40"});
CHECK(code != 0); // cellular-v9 requires --tuning.
provision_cellular(r, "9777", "cellular-v9", build, commit, motes, code, "--motes",
{"--light-pj", "40", "--tuning", write_tuning(20'000)});
CHECK(code != 0); // The tuning region size must match the opening's.
const auto tuning = write_tuning(10'000);
const auto first = provision_cellular(r, "9777", "cellular-v9", build, commit, motes, code,
"--motes", {"--light-pj", "40", "--tuning", tuning});
CHECK(code == 0 && has(first, "provisioned world=9777 region=1 sequence=6 tick=1"));
const auto again = provision_cellular(r, "9777", "cellular-v9", build, commit, motes, code,
"--motes", {"--light-pj", "40", "--tuning", tuning});
CHECK(code == 0 && has(again, "already-provisioned world=9777 region=1 sequence=6 tick=1"));
auto db = owner();
const auto head = load_region_checkpoint(*db, r.key, 5s);
CHECK(head);
const auto manifest = decode_manifest(head->manifest);
CHECK(manifest && manifest->cellular_versions == cellular_v14_versions &&
manifest->history_profile == cellular_revision_history_profile);
#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.
using namespace evo::server;
const auto connect = [&]() -> std::expected<std::unique_ptr<Postgres>, PgFailure> {
return Postgres::connect({env("PGHOST"),
{},
env("PGPORT"),
env("PGDATABASE"),
env("EVO_PG_RUNTIME_USER"),
{},
{}},
5s);
};
CHECK(db->query("INSERT INTO evolution.life_allocators VALUES(9777,1000)", {}, 5s));
Sha256Digest digest{};
digest.fill(0xEE);
auto objects = FilesystemObjectStore::open(r.root, r.key, max_cellular_lives_bytes);
CHECK(objects);
auto made =
CellularRegionHost::create({r.key, 9, {}, digest, {digest}}, connect, std::move(*objects));
CHECK(made);
auto host = std::move(*made);
CHECK(host->step().ready && host->state() &&
host->state()->rules_version() == cellular_lives_liquid_rules &&
host->state()->flow_field() != nullptr);
auto runtime = connect();
CHECK(runtime);
Uuid account{};
account[0] = 0x9E;
account.back() = 0x14;
const auto control =
claim_account_control(**runtime, r.key, *host->authority(), account, 1, 1, 20'000ms, 5s);
CHECK(control);
CHECK(host->create_primitive_life(account, control->generation, 5).result ==
evo::network::PrimitiveLifeResult::pending);
const std::vector births(host->queued_births().begin(), host->queued_births().end());
auto builder = CellularSessionBatchBuilder::create(*host->state(), host->committed()->head);
CHECK(builder);
CHECK(builder->append_with_birth_refusals(host->state()->tick() + 1, {}, {}, births, {}));
CHECK(builder->refused_births().empty() &&
builder->batch().format_version == cellular_batch_inheritance_format);
CHECK(host->publish(builder->batch(), builder->actions(), builder->mutation_actions()));
CHECK(host->query_primitive_life(account, control->generation, 5).result ==
evo::network::PrimitiveLifeResult::born);
// Ticks of swimming then braking publish and leave the founder in motion state.
for (int tick = 0; tick < 6; ++tick) {
std::vector<CellularLifeIntent> intents;
for (const auto& life : host->state()->lives()) {
CellularLifeIntent intent{life.identity.life, {}};
intent.intent.movement = {1'000, 0};
intent.intent.brake = tick >= 4;
intents.push_back(intent);
}
std::ranges::sort(intents, {}, &CellularLifeIntent::life_id);
auto next = CellularSessionBatchBuilder::create(*host->state(), host->committed()->head);
CHECK(next && next->append(host->state()->tick() + 1, intents, {}));
CHECK(host->publish(next->batch(), next->actions(), next->mutation_actions()));
}
CHECK(host->state()->lives().front().identity.genome != 0);
const auto genome =
host->state()->archive().find(host->state()->lives().front().identity.genome);
CHECK(genome && genome->schema_version() == evo::biology::genome_schema_v6);
#endif
}
#ifdef EVO_POSTGRES_M10
// A player on a cellular-v8 region feeds by contact until offered a mutation, chooses it
// and publishes the choice, all through the host and session builder as evo-server does.
@@ -884,6 +1006,7 @@ void run_region_store_tests() {
cellular_v6_provisioning_uses_the_reproduction_bundle();
cellular_v7_provisioning_scatters_bubbles();
cellular_v8_provisioning_declares_light();
cellular_v9_provisioning_declares_liquid();
#ifdef EVO_POSTGRES_M10
cellular_v8_player_chooses_a_mutation();
#endif