M12.4: keep cellular wildlife ticking and retain scheduling debt
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m35s
Foundation / checks (tsan) (push) Failing after 17m51s
Foundation / checks (network) (push) Successful in 21m13s
Foundation / checks (client) (push) Successful in 22m19s
Foundation / checks (postgres) (push) Successful in 48m25s
Foundation / checks (checks) (push) Failing after 50m8s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-17 12:24:19 -04:00
parent 5decaa0326
commit aff35863ce
12 changed files with 434 additions and 20 deletions
+99
View File
@@ -0,0 +1,99 @@
#include "evo/server/lifecycle/cellular_schedule.hpp"
#include "fixtures/cellular_ecology.hpp"
#include <limits>
namespace {
using namespace evo;
using namespace evo::server;
using namespace evo::fixture;
void pacing() {
CellularTickSchedule schedule;
auto sample = checked(schedule.observe(0, 1, 100, true, true), "schedule start");
require(!sample.due && sample.debt == 0, "first tick was free");
require(!checked(schedule.observe(49'999, 1, 100, true, true), "before boundary").due,
"early tick");
sample = checked(schedule.observe(50'000, 1, 100, true, true), "first due tick");
require(sample.due && sample.debt == 1, "tick boundary missed");
sample = checked(schedule.observe(500'000, 1, 100, true, true), "slow publication");
require(sample.due && sample.debt == 10, "publication latency discarded debt");
require(sample.head_age_us == 500'000, "stalled head appeared fresh");
schedule.defer(500'000);
sample = checked(schedule.observe(549'999, 1, 100, true, true), "bounded retry");
require(!sample.due && sample.debt == 10, "retry consumed debt");
sample = checked(schedule.observe(550'000, 1, 100, true, true), "retry due");
require(sample.due && sample.debt == 11, "retry lost ticks");
for (std::uint64_t tick = 101; tick <= 111; ++tick) {
sample = checked(schedule.observe(550'000, 1, tick, true, true), "committed catchup");
require(sample.debt == 111 - tick, "confirmed head did not consume exact debt");
require(sample.head_age_us == 0, "new confirmed head age was not reset");
}
require(!sample.due && sample.max_debt == 11, "catchup failed");
require(!schedule.observe(549'999, 1, 111, true, true), "regressing clock accepted");
require(!schedule.observe(550'000, 1, 110, true, true), "regressing committed head accepted");
require(!schedule.observe(550'000, 0, 111, true, true), "unfenced origin accepted");
sample = checked(schedule.observe(600'000, 1, 111, false, true), "no ecology demand");
require(!sample.due && sample.debt == 0, "suspended-only region accumulated ticks");
sample = checked(schedule.observe(60'000'000, 1, 111, true, true), "new demand");
require(!sample.due && sample.debt == 0, "pause caught up wall time");
checked(schedule.observe(60'050'000, 1, 111, true, false), "authority loss");
sample = checked(schedule.observe(90'000'000, 2, 112, true, true), "new fenced owner");
require(!sample.due && sample.debt == 0, "new epoch inherited unadmitted wall time");
CellularTickSchedule exhausted;
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
checked(exhausted.observe(0, 3, maximum - 1, true, true), "last tick origin");
require(
checked(exhausted.observe(maximum - 1, 3, maximum - 1, true, true), "large monotonic range")
.debt == 1,
"tick overflow");
sample = checked(exhausted.observe(maximum, 3, maximum, true, true), "terminal tick");
require(!sample.due && sample.debt == 0, "tick wrapped");
exhausted.defer(maximum);
}
void offline_demand() {
auto state = opening(0, true);
require(cellular_unattended_tick_needed(*state), "active offline life cannot start freeze");
for (std::uint64_t tick = 0; tick <= cellular_linger_ticks; ++tick) {
std::vector<CellularLifeIntent> frozen;
for (const auto& life : state->lives()) {
CellularLifeIntent intent{life.identity.life, {}};
intent.intent.frozen = true;
frozen.push_back(intent);
}
checked(state->advance_tick(frozen), "offline demand step");
require(cellular_unattended_tick_needed(*state) == (tick < cellular_linger_ticks),
"linger/suspend demand mismatch");
}
const auto before = state->snapshot();
auto resumed = restore(*state);
require(resumed->snapshot() == before && !cellular_unattended_tick_needed(*resumed),
"restore woke suspended lives");
}
void historical_profile_is_not_opted_in() {
const auto endowment = checked(biology::primitive_endowment(), "legacy endowment");
auto funding = endowment.body;
funding.energy.value = endowment.reserve.energy.value + endowment.construction.value;
auto primitive =
checked(PrimitiveLives::create({7, 1, 1, 1, funding, {{100, 100}}}), "legacy nursery");
LifeRequest request{};
request.account.back() = 1;
request.action = 1;
checked(primitive->spawn(request, {1, 1, 1, 1, {1}}), "legacy funded life");
auto habitat =
checked(biology::CellularHabitat::create({7, 1, 1, 6000, 6000, {}}), "legacy habitat");
auto state =
checked(CellularLives::create(*primitive, std::move(habitat), {{6000, 6000}, 1, 293150}),
"legacy owner");
require(!state->lives().empty() && !cellular_unattended_tick_needed(*state),
"legacy profile without offline freeze was enabled");
}
} // namespace
int main() try {
pacing();
offline_demand();
historical_profile_is_not_opted_in();
return 0;
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}