Freeze offline cells, linger, suspend and resume them
Foundation / checks (ecs) (push) Successful in 2m15s
Foundation / checks (deploy) (push) Successful in 3m53s
Foundation / checks (tsan) (push) Successful in 9m46s
Foundation / checks (client) (push) Failing after 13m47s
Foundation / checks (network) (push) Successful in 19m5s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 19m34s
Foundation / checks (postgres) (push) Canceled after 19m28s

M11.7 (ADR-0128): a frozen step intent, set by the server for every owned life
whose account holds no session, leaves the cell unchanged but engulfable. Owner
format 6 / rules 5 track presence: lingering for 200 ticks, then suspended out of
the world without aging; an unfrozen intent resumes it in place or at the nearest
clear spot within three extents. Bundle v6, schema v38 and the cellular-v4
opening carry it. The server refuses an offline account's carried actions, ticks
while anyone lingers, and skips suspended cells in replication and perception.

Also fixes the TSan failure of CI run 374: the rules-4 owner test read the bud
through a reference into a replaced state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-14 07:50:45 -04:00
co-authored by Claude Opus 5.5
parent e71147f7a6
commit e74bdf286b
25 changed files with 741 additions and 69 deletions
+112 -2
View File
@@ -668,6 +668,11 @@ void rules_four_owner_buds_wildlife() {
feeding_bud.bud = true;
CHECK(owner.advance_tick(std::array{CellularLifeIntent{1, feeding_bud}}).error() ==
CellularLivesError::invalid_intents);
// Freezing is rules 5 (ADR-0128).
evo::biology::CellularStepIntent frozen{};
frozen.frozen = true;
CHECK(owner.advance_tick(std::array{CellularLifeIntent{1, frozen}}).error() ==
CellularLivesError::invalid_intents);
const auto parent_genome = owner.lives().front().identity.genome;
std::optional<CellularTickExecution> budded;
@@ -721,8 +726,10 @@ void rules_four_owner_buds_wildlife() {
CHECK(owner.advance_tick(std::array{CellularLifeIntent{1, feed}, controlled->front()}));
// Wildlife feeds like any cell but never earns a mutation offer.
const auto child_x = child.position.x_um / 1000;
const auto child_y = child.position.y_um / 1000;
// Read the bud from the current state: the tick above replaced the one `child` named.
const auto& wildlife = owner.lives()[1];
const auto child_x = wildlife.position.x_um / 1000 * 1000;
const auto child_y = wildlife.position.y_um / 1000 * 1000;
evo::biology::CellularStepIntent child_feed{};
child_feed.intake_target = evo::biology::CellularPatchAddress{
static_cast<std::uint32_t>(child_x), static_cast<std::uint32_t>(child_y)};
@@ -743,6 +750,108 @@ void rules_four_owner_buds_wildlife() {
refresh_checksum(rewound);
CHECK(!CellularLives::restore(rewound, 93, 1, 7, owner.tick()));
}
// ADR-0128: an offline owned life freezes, lingers 200 ticks, is suspended without aging,
// survives restore, and resumes; a newborn on its spot makes it resume nearby.
void rules_five_owner_freezes_lingers_suspends_and_resumes() {
auto primitive = PrimitiveLives::create({94, 1, 7, 17, founder_price(3), {{0, 0}, {1'500, 0}}});
CHECK(primitive);
LifeRequest request{};
request.account.back() = 1;
request.action = 1;
CHECK((*primitive)->spawn(request, {1, 101, 201, 301, {1}}));
request.account.back() = 2;
CHECK((*primitive)->spawn(request, {2, 102, 202, 302, {1}}));
auto habitat = evo::biology::CellularHabitat::create({94, 1, 7, 3'000, 2'000, {}});
CHECK(habitat);
auto created =
CellularLives::create(**primitive, std::move(*habitat), {{3'000, 2'000}, 1, 293'150},
CellularLivesProfile::presence);
CHECK(created);
auto owner = std::move(*created);
CHECK(owner->format_version() == cellular_lives_presence_format &&
owner->rules_version() == cellular_lives_presence_rules);
evo::biology::CellularStepIntent frozen{};
frozen.frozen = true;
// The trace keeps the flag (intent byte 13) and refuses it with anything else.
CellularBatch frozen_batch;
frozen_batch.header = {94, 1, 7, {}, {}, owner->tick(), owner->tick() + 1};
frozen_batch.header.predecessor.fill(1);
frozen_batch.header.predecessor_digest.fill(2);
frozen_batch.ticks.push_back({{{1, frozen}, {2, {}}}, {}, {}});
const auto frozen_bytes = encode_cellular_batch(frozen_batch);
CHECK(frozen_bytes);
CHECK(decode_cellular_batch(*frozen_bytes) == frozen_batch);
auto flag_two = *frozen_bytes;
flag_two[cellular_batch_header_bytes + cellular_batch_tick_header_bytes + 13] = 2;
CHECK(!decode_cellular_batch(flag_two));
// A frozen intent carries nothing else.
auto moving = frozen;
moving.movement = {100, 0};
CHECK(owner->advance_tick(std::array{CellularLifeIntent{1, moving}, CellularLifeIntent{2, {}}})
.error() == CellularLivesError::invalid_intents);
const auto before = owner->lives()[0];
CHECK(
owner->advance_tick(std::array{CellularLifeIntent{1, frozen}, CellularLifeIntent{2, {}}}));
const auto first_frozen = owner->tick();
CHECK(owner->lives()[0].presence == CellularPresence::lingering &&
owner->lives()[0].frozen_since == first_frozen &&
owner->lives()[0].reserve == before.reserve &&
owner->lives()[0].position == before.position &&
owner->lives()[1].reserve.energy.value < before.reserve.energy.value);
// Back within the linger: active again in place.
CHECK(owner->advance_tick(std::array{CellularLifeIntent{1, {}}, CellularLifeIntent{2, {}}}));
CHECK(owner->lives()[0].presence == CellularPresence::active &&
owner->lives()[0].frozen_since == 0);
// Frozen through the whole linger: suspended after 200 ticks, without aging.
CHECK(
owner->advance_tick(std::array{CellularLifeIntent{1, frozen}, CellularLifeIntent{2, {}}}));
const auto parked = owner->lives()[0];
for (std::uint64_t tick = 1; tick <= cellular_linger_ticks; ++tick) {
CHECK(owner->lives()[0].presence == CellularPresence::lingering);
CHECK(owner->advance_tick(
std::array{CellularLifeIntent{1, frozen}, CellularLifeIntent{2, {}}}));
CHECK(owner->current_total() == owner->opening_total());
}
CHECK(owner->lives()[0].presence == CellularPresence::suspended &&
owner->lives()[0].reserve == parked.reserve &&
owner->lives()[0].position == parked.position &&
owner->last_tick_feedback()[0].presence == CellularPresence::suspended);
// Suspended lives stay out of the step while frozen.
for (int tick = 0; tick < 5; ++tick)
CHECK(owner->advance_tick(
std::array{CellularLifeIntent{1, frozen}, CellularLifeIntent{2, {}}}));
CHECK(owner->lives()[0].reserve == parked.reserve);
const auto saved = owner->snapshot();
auto recovered = CellularLives::restore(saved, 94, 1, 7, owner->tick());
CHECK(recovered && (*recovered)->snapshot() == saved &&
std::ranges::equal((*recovered)->lives(), owner->lives()));
// A lingering presence older than the linger is refused on restore.
auto stale = saved;
const auto presence_at = std::size_t{220} + std::size_t{2} * 8 + 480 + 8;
stale[presence_at] = static_cast<std::uint8_t>(CellularPresence::lingering);
refresh_checksum(stale);
CHECK(!CellularLives::restore(stale, 94, 1, 7, owner->tick()));
// A newborn takes the suspended cell's spot (placement ignores suspended cells)...
LifeRequest third{};
third.account.back() = 3;
third.action = 1;
auto born = owner->birth_candidate(third, {50, 50, 50, 50, {owner->tick()}});
CHECK(born);
owner = std::move(*born);
CHECK(owner->lives().size() == 3 && owner->lives()[2].position == parked.position);
// ...so the resume relocates within three extents, clear of everyone.
CHECK(owner->advance_tick(std::array{CellularLifeIntent{1, {}}, CellularLifeIntent{2, {}},
CellularLifeIntent{50, {}}}));
const auto& resumed = owner->lives()[0];
CHECK(resumed.presence == CellularPresence::active && resumed.frozen_since == 0 &&
resumed.position != parked.position && !owner->last_tick_feedback()[0].resume_blocked);
CHECK(owner->current_total() == owner->opening_total());
}
} // namespace
int main() {
@@ -753,6 +862,7 @@ int main() {
owner_advances_and_closes_death_atomically();
rules_three_owner_resolves_engulf_and_detritus();
rules_four_owner_buds_wildlife();
rules_five_owner_freezes_lingers_suspends_and_resumes();
std::puts(
"PASS cellular lives: feeding, tick ownership, terminal closure, rules 3, budding");
} catch (const std::exception& error) {