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
+2 -2
View File
@@ -240,7 +240,7 @@ ActionReceipt IntentAdmission::action(std::uint64_t session, const CellularActio
static_cast<std::uint16_t>(ActionKind::cellular), m.tick};
const auto bytes =
encode_cellular_action_input({m.tick, m.move_x, m.move_y, m.has_intake_target,
m.intake_x_um, m.intake_y_um, m.engulf, m.bud});
m.intake_x_um, m.intake_y_um, m.engulf, m.bud, m.brake});
auto* s = find(session);
if (!s)
return {m.action_id, AdmitStatus::unknown_session, facts.server_tick, m.tick};
@@ -282,7 +282,7 @@ std::optional<ActionReceipt> IntentAdmission::admit(std::uint64_t session, const
static_cast<std::uint16_t>(ActionKind::cellular), m.tick};
const auto bytes =
encode_cellular_action_input({m.tick, m.move_x, m.move_y, m.has_intake_target,
m.intake_x_um, m.intake_y_um, m.engulf, m.bud});
m.intake_x_um, m.intake_y_um, m.engulf, m.bud, m.brake});
auto* s = find(session);
if (!s)
return ActionReceipt{m.action_id, AdmitStatus::unknown_session, facts.server_tick, m.tick};
+104 -18
View File
@@ -32,9 +32,17 @@ constexpr std::size_t cellular_perception_v12_prefix_bytes =
cellular_perception_v10_prefix_bytes + 8 + 2 + 6;
// v12: organism, photosynthesis per thousand and 6 reserved bytes.
constexpr std::size_t cellular_perceived_producer_bytes = 8 + 2 + 6;
// v13 (rules 12) appends the owner's velocity (2 x i32) and heading (u16), a flags byte
// (bit 0: currents present), a reserved byte, and the current seed and nine u32 fields.
constexpr std::size_t cellular_liquid_block_bytes = 4 + 4 + 2 + 1 + 1 + 8 + (9 * 4);
constexpr std::size_t cellular_perception_v13_prefix_bytes =
cellular_perception_v12_prefix_bytes + cellular_liquid_block_bytes;
constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8);
// v11: id, centre, radius, shape, drained flag and five 16-bit amount codes.
constexpr std::size_t cellular_perceived_deposit_bytes = 4 + 4 + 4 + 2 + 1 + 1 + (5 * 2);
// v13: the same plus world velocity as two 16-bit um/s values.
constexpr std::size_t cellular_perceived_liquid_deposit_bytes =
cellular_perceived_deposit_bytes + 4;
constexpr std::size_t intention_receipt_bytes = 8 + 1 + 8;
constexpr std::size_t simulated_bytes = std::size_t{3} * 8;
constexpr std::size_t action_bytes = (std::size_t{3} * 8) + 2 + 8;
@@ -227,8 +235,20 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
!cellular_v10_family(version) && std::holds_alternative<CellularPerception>(message))
return {};
if (const auto* perception = std::get_if<CellularPerception>(&message)) {
// v12 alone carries captured light and producers (ADR-0176).
const bool producers = version == session_protocol_v12;
// v12 and v13 carry captured light and producers (ADR-0176); v13 alone carries
// liquid motion.
const bool producers = cellular_light_version(version);
const bool liquid = version == session_protocol_v13;
if (!liquid && (perception->currents ||
(perception->diagnostics && (perception->diagnostics->velocity_x_q10 ||
perception->diagnostics->velocity_y_q10 ||
perception->diagnostics->heading)) ||
std::ranges::any_of(perception->deposits, [](const auto& d) {
return d.velocity_x_um_s != 0 || d.velocity_y_um_s != 0;
})))
return {};
if (perception->currents && !perception->life_identity)
return {};
if ((!producers && (!perception->producers.empty() ||
(perception->diagnostics && perception->diagnostics->light_pj))) ||
perception->producers.size() > max_cellular_perceived_producers ||
@@ -337,7 +357,8 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
put(out, static_cast<std::uint16_t>(m.move_x), 2);
put(out, static_cast<std::uint16_t>(m.move_y), 2);
out.push_back(m.has_intake_target ? 1 : m.engulf ? 2 : m.bud ? 3 : 0); // Target kind.
put(out, 0, 3);
out.push_back(m.brake ? 1 : 0); // v13 flags: bit 0 brake.
put(out, 0, 2);
put(out, m.intake_x_um, 4);
put(out, m.intake_y_um, 4);
return out;
@@ -386,12 +407,15 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
auto out =
header(SessionMessageType::cellular_perception,
(version == session_protocol_v12 ? cellular_perception_v12_prefix_bytes
: cellular_v10_family(version) ? cellular_perception_v10_prefix_bytes
: version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes) +
(version == session_protocol_v13 ? cellular_perception_v13_prefix_bytes
: version == session_protocol_v12 ? cellular_perception_v12_prefix_bytes
: cellular_v10_family(version) ? cellular_perception_v10_prefix_bytes
: version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes) +
m.patches.size() * cellular_perceived_patch_bytes +
m.deposits.size() * cellular_perceived_deposit_bytes +
m.deposits.size() * (version == session_protocol_v13
? cellular_perceived_liquid_deposit_bytes
: cellular_perceived_deposit_bytes) +
m.producers.size() * cellular_perceived_producer_bytes,
version);
put(out, m.tick, 8);
@@ -417,11 +441,25 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
for (const auto value :
d ? d->bud_cost_matter_fg : std::array<std::uint64_t, 4>{})
put(out, value, 8);
if (version == session_protocol_v12) {
if (cellular_light_version(version)) {
put(out, d ? d->light_pj : 0, 8);
put(out, m.producers.size(), 2);
put(out, 0, 6);
}
if (version == session_protocol_v13) {
put(out, static_cast<std::uint32_t>(d ? d->velocity_x_q10 : 0), 4);
put(out, static_cast<std::uint32_t>(d ? d->velocity_y_q10 : 0), 4);
put(out, d ? d->heading : 0, 2);
out.push_back(m.currents ? 1 : 0);
out.push_back(0);
const auto c = m.currents.value_or(CellularCurrentsView{});
put(out, c.seed, 8);
for (const auto value :
{c.width_um, c.height_um, c.pitch_um, c.min_count, c.max_count,
c.min_route_width_um, c.max_route_width_um, c.min_speed_um_per_s,
c.max_speed_um_per_s})
put(out, value, 4);
}
} else {
put(out, 0, 5);
}
@@ -442,6 +480,10 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
out.push_back(deposit.drained ? 1 : 0);
for (const auto code : deposit.amount_codes)
put(out, code, 2);
if (version == session_protocol_v13) {
put(out, static_cast<std::uint16_t>(deposit.velocity_x_um_s), 2);
put(out, static_cast<std::uint16_t>(deposit.velocity_y_um_s), 2);
}
}
for (const auto& producer : m.producers) {
put(out, producer.organism, 8);
@@ -679,12 +721,14 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
m.move_x = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(payload, 32, 2)));
m.move_y = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(payload, 34, 2)));
// Target kind: 0 none, 1 patch intake, 2 engulf and 3 bud (v10 only, ADR-0124/0125).
if (payload[36] > (cellular_v10_family(wire_version) ? 3 : 1) || payload[37] != 0 ||
payload[38] != 0 || payload[39] != 0)
if (payload[36] > (cellular_v10_family(wire_version) ? 3 : 1) ||
payload[37] > (wire_version == session_protocol_v13 ? 1 : 0) || payload[38] != 0 ||
payload[39] != 0)
return std::unexpected(SessionCodecError::invalid_value);
m.has_intake_target = payload[36] == 1;
m.engulf = payload[36] == 2;
m.bud = payload[36] == 3;
m.brake = payload[37] == 1;
m.intake_x_um = static_cast<std::uint32_t>(get(payload, 40, 4));
m.intake_y_um = static_cast<std::uint32_t>(get(payload, 44, 4));
if (!m.session || !m.epoch || !m.action_id || !m.tick ||
@@ -778,16 +822,19 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
const bool without_bud_cost = wire_version == session_protocol_v10 &&
payload.size() == cellular_perception_v9_prefix_bytes +
count * cellular_perceived_patch_bytes;
const bool lit = wire_version == session_protocol_v12;
const auto prefix = lit ? cellular_perception_v12_prefix_bytes
const bool lit = cellular_light_version(wire_version);
const bool liquid = wire_version == session_protocol_v13;
const auto prefix = liquid ? cellular_perception_v13_prefix_bytes
: lit ? cellular_perception_v12_prefix_bytes
: cellular_v10_family(wire_version) && !without_bud_cost
? cellular_perception_v10_prefix_bytes
: wire_version == session_protocol_v9 || without_bud_cost
? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes;
const bool deposits = cellular_deposit_version(wire_version);
const auto entry =
deposits ? cellular_perceived_deposit_bytes : cellular_perceived_patch_bytes;
const auto entry = liquid ? cellular_perceived_liquid_deposit_bytes
: deposits ? cellular_perceived_deposit_bytes
: cellular_perceived_patch_bytes;
const auto producer_count = lit && payload.size() >= prefix
? static_cast<std::size_t>(get(
payload, cellular_perception_v10_prefix_bytes + 8, 2))
@@ -833,6 +880,14 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
}
if (lit)
d.light_pj = get(payload, cellular_perception_v10_prefix_bytes, 8);
if (liquid) {
constexpr auto at = cellular_perception_v12_prefix_bytes;
d.velocity_x_q10 =
static_cast<std::int32_t>(static_cast<std::uint32_t>(get(payload, at, 4)));
d.velocity_y_q10 = static_cast<std::int32_t>(
static_cast<std::uint32_t>(get(payload, at + 4, 4)));
d.heading = static_cast<std::uint16_t>(get(payload, at + 8, 2));
}
}
d.movement = static_cast<CellularMovementResult>(payload[74]);
d.intake = static_cast<CellularIntakeResult>(payload[75]);
@@ -847,7 +902,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
d.intake != CellularIntakeResult::not_reported ||
d.engulf != CellularEngulfResult::not_reported ||
d.bud != CellularBudOutcome::not_reported || d.bud_cost_energy_pj ||
d.light_pj ||
d.light_pj || d.velocity_x_q10 || d.velocity_y_q10 || d.heading ||
std::ranges::any_of(d.bud_cost_matter_fg,
[](std::uint64_t value) { return value != 0; }))
return std::unexpected(SessionCodecError::invalid_value);
@@ -857,6 +912,29 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
return std::unexpected(SessionCodecError::invalid_value);
if (m.diagnostics && !valid_diagnostics(*m.diagnostics))
return std::unexpected(SessionCodecError::invalid_value);
if (liquid) {
constexpr auto at = cellular_perception_v12_prefix_bytes + 10;
const auto flags = payload[at];
CellularCurrentsView c;
c.seed = get(payload, at + 2, 8);
std::array<std::uint32_t, 9> fields{};
for (std::size_t i = 0; i < fields.size(); ++i)
fields.at(i) = static_cast<std::uint32_t>(get(payload, at + 10 + i * 4, 4));
c.width_um = fields[0];
c.height_um = fields[1];
c.pitch_um = fields[2];
c.min_count = fields[3];
c.max_count = fields[4];
c.min_route_width_um = fields[5];
c.max_route_width_um = fields[6];
c.min_speed_um_per_s = fields[7];
c.max_speed_um_per_s = fields[8];
if (flags > 1 || payload[at + 1] != 0 || (flags == 1 && !m.life_identity) ||
(flags == 0 && c != CellularCurrentsView{}))
return std::unexpected(SessionCodecError::invalid_value);
if (flags == 1)
m.currents = c;
}
std::size_t offset = prefix;
if (deposits) {
m.deposits.reserve(count);
@@ -878,6 +956,12 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
for (std::size_t c = 0; c < d.amount_codes.size(); ++c)
d.amount_codes.at(c) =
static_cast<std::uint16_t>(get(payload, offset + 16 + c * 2, 2));
if (liquid) {
d.velocity_x_um_s = static_cast<std::int16_t>(
static_cast<std::uint16_t>(get(payload, offset + 26, 2)));
d.velocity_y_um_s = static_cast<std::int16_t>(
static_cast<std::uint16_t>(get(payload, offset + 28, 2)));
}
m.deposits.push_back(d);
}
if (!m.life_identity && producer_count)
@@ -1083,7 +1167,8 @@ encode_cellular_action_input(const CellularActionInput& input) {
: input.engulf ? 2
: input.bud ? 3
: 0);
put(bytes, 0, 3);
bytes.push_back(input.brake ? 1 : 0); // Flags (schema 58): bit 0 brake.
put(bytes, 0, 2);
put(bytes, input.intake_x_um, 4);
put(bytes, input.intake_y_um, 4);
std::array<std::uint8_t, cellular_action_input_bytes> out{};
@@ -1095,7 +1180,7 @@ std::expected<CellularActionInput, SessionCodecError>
decode_cellular_action_input(std::span<const std::uint8_t> bytes) {
if (bytes.size() != cellular_action_input_bytes)
return std::unexpected(SessionCodecError::wrong_length);
if (bytes[12] > 3 || bytes[13] != 0 || bytes[14] != 0 || bytes[15] != 0)
if (bytes[12] > 3 || bytes[13] > 1 || bytes[14] != 0 || bytes[15] != 0)
return std::unexpected(SessionCodecError::invalid_value);
CellularActionInput input;
input.tick = get(bytes, 0, 8);
@@ -1104,6 +1189,7 @@ decode_cellular_action_input(std::span<const std::uint8_t> bytes) {
input.has_intake_target = bytes[12] == 1;
input.engulf = bytes[12] == 2;
input.bud = bytes[12] == 3;
input.brake = bytes[13] == 1;
input.intake_x_um = static_cast<std::uint32_t>(get(bytes, 16, 4));
input.intake_y_um = static_cast<std::uint32_t>(get(bytes, 20, 4));
if (input.tick == 0 ||