ADR 0127
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 2m23s
Foundation / checks (tsan) (push) Successful in 10m11s
Foundation / checks (client) (push) Failing after 14m26s
Foundation / checks (network) (push) Successful in 18m54s
Foundation / checks (checks) (push) Successful in 42m9s
Foundation / checks (postgres) (push) Successful in 43m51s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-15 09:32:51 -04:00
parent 0a0f6c3bb1
commit 817a830a8a
20 changed files with 474 additions and 28 deletions
+21
View File
@@ -875,6 +875,27 @@ void cellular_death_is_final_and_account_restarts() {
// While the second life lives, a third request is an existing-life refusal.
CHECK(host->create_primitive_life(account, control->generation, 13).result ==
evo::network::PrimitiveLifeResult::existing_life);
// A fresh account still cannot create energy from an exhausted nursery. The
// expected refusal must not stall the living cell's tick or stay pending forever.
const auto newcomer = filled<16>(0x95);
const auto newcomer_control = claim_account_control(
*runtime, key, checked_value(host->authority()), newcomer, 1, 2, 60'000ms, 5s);
CHECK(newcomer_control);
CHECK(host->create_primitive_life(newcomer, newcomer_control->generation, 21).result ==
evo::network::PrimitiveLifeResult::pending);
const auto before_tick = host->state()->tick();
const std::array refusals{CellularBirthRefusal{host->queued_births().front(),
CellularLivesError::insufficient_funding}};
CellularBatch continued;
continued.header = header(1);
continued.ticks.push_back({{{second, {}}}, {}, {}});
CHECK(host->publish(continued));
host->refuse_births(refusals);
CHECK(host->state()->tick() == before_tick + 1 && host->queued_births().empty());
CHECK(host->query_primitive_life(newcomer, newcomer_control->generation, 21).result ==
evo::network::PrimitiveLifeResult::insufficient_funding);
CHECK(host->create_primitive_life(newcomer, newcomer_control->generation, 21).result ==
evo::network::PrimitiveLifeResult::insufficient_funding);
const auto snapshot = host->state()->snapshot();
host->drain();
host.reset();
+54
View File
@@ -310,12 +310,66 @@ void builder_batches_reserved_birth_after_empty_tick() {
CellularSessionBatchError::duplicate_birth);
CHECK(builder->candidate().snapshot() == snapshot && builder->batch().ticks.size() == 1);
}
void unavailable_birth_does_not_freeze_the_tick() {
for (const bool funded : {false, true}) {
auto primitive =
PrimitiveLives::create({94, 1, 1, 17, founder_price(funded ? 2 : 1), {{0, 0}}});
CHECK(primitive);
LifeRequest request{};
request.account.back() = 1;
request.action = 1;
CHECK((*primitive)->spawn(request, {101, 101, 101, 101, {1}}));
auto habitat = biology::CellularHabitat::create({94, 1, 1, 1000, 1000, {}});
CHECK(habitat);
auto state =
CellularLives::create(**primitive, std::move(*habitat), {{1000, 1000}, 1, 293150});
CHECK(state);
persistence::RegionHead head{};
head.frame = 1;
head.end_tick = 1;
head.commit.fill(1);
head.digest.fill(2);
CellularTickIntents::Birth birth{};
birth.account.back() = 2;
birth.request = 1;
birth.generation = 1;
birth.identity = 102;
const std::array births{birth};
// Movement vacates the nursery in the underfunded case, isolating each refusal.
const std::array baseline{
CellularLifeIntent{101, {{static_cast<std::int16_t>(funded ? 0 : 1000), 0}, {}}}};
// A founder moves only a few um per tick: first move it fully away from the site.
if (!funded) {
for (int i = 0; i < 100; ++i)
CHECK((*state)->advance_tick(baseline));
head.end_tick = (*state)->tick();
}
auto strict = CellularSessionBatchBuilder::create(**state, head);
CHECK(strict);
CHECK(strict->append(head.end_tick + 1, baseline, {}, births).error() ==
CellularSessionBatchError::invalid_birth);
CHECK(strict->candidate().tick() == head.end_tick);
auto builder = CellularSessionBatchBuilder::create(**state, head);
CHECK(builder &&
builder->append_with_birth_refusals(head.end_tick + 1, baseline, {}, births));
CHECK(builder->refused_births().size() == 1 && builder->refused_births()[0].birth == birth);
CHECK(
builder->refused_births()[0].reason ==
(funded ? CellularLivesError::no_placement : CellularLivesError::insufficient_funding));
CHECK(builder->candidate().tick() == head.end_tick + 1 &&
builder->candidate().lives().size() == 1);
CHECK(builder->batch().ticks.back().births.empty());
const auto replay = replay_cellular_batch(**state, builder->batch());
CHECK(replay && (*replay)->snapshot() == builder->candidate().snapshot());
}
}
} // namespace
int main() try {
actions_bind_to_owned_life_and_preserve_other_inputs();
durable_mutation_reservations_bind_to_the_exact_offer();
builder_batches_reserved_birth_after_empty_tick();
unavailable_birth_does_not_freeze_the_tick();
std::puts("cellular session batch: ok");
} catch (const std::exception& e) {
std::fprintf(stderr, "%s\n", e.what());
+44 -3
View File
@@ -378,7 +378,8 @@ void cellular_panels(const std::filesystem::path& review) {
camera->world_to_screen({static_cast<double>(x), static_cast<double>(y)});
const auto high = camera->world_to_screen({x + 1.0, y + 1.0});
CHECK(low && high);
patch_box(boxes, *low, *high, (x + y) % 4 != 0, x == 2 && y == 3, width, height);
patch_box(boxes, *low, *high, (x + y) % 4 != 0, (x + y) % 3 != 0, x == 2 && y == 3,
width, height);
}
OrganismCell organism;
organism.id = 901;
@@ -416,7 +417,10 @@ void cellular_panels(const std::filesystem::path& review) {
diagnostics.intake = network::CellularIntakeResult::acquired;
diagnostics.engulf = network::CellularEngulfResult::membrane_too_thick;
network::CellularPerception perception{
102, 901, {{1000, 2000, 50000, {100, 20, 10, 40}}}, diagnostics};
102,
901,
{{1000, 2000, 50000, {100, 20, 10, 40}}, {2000, 3000, 0, {90, 20, 8, 30}}},
diagnostics};
play.observe(perception);
play.observe_offer(network::CellularMutationOffer{
102,
@@ -450,16 +454,53 @@ void cellular_panels(const std::filesystem::path& review) {
};
for (int i = 0; i < 3; ++i)
draw();
const auto* journal = ImGui::FindWindowByName("Cellular field journal");
auto* journal = ImGui::FindWindowByName("Cellular field journal");
CHECK(journal && journal->Active && journal->ScrollMax.x == 0);
CHECK(journal->Pos.x >= 0 && journal->Pos.y >= 0 &&
journal->Pos.x + journal->Size.x <= static_cast<float>(width) &&
journal->Pos.y + journal->Size.y <= static_cast<float>(height));
if (!review.empty()) {
std::filesystem::create_directories(review);
auto later = perception;
++later.tick;
later.diagnostics->reserve_energy_pj -= 50;
play.observe(later);
view.cellular_feed_target = {{2000, 3000}};
CHECK(app->request_screenshot(
(review / ("cellular-" + std::to_string(width) + ".bmp")).string()));
draw();
auto* tabs = GImGui->TabBars.GetByKey(journal->GetID("cell-tabs"));
CHECK(tabs);
const auto choose_tab = [&](const char* name) {
for (auto& tab : tabs->Tabs)
if (std::string_view{ImGui::TabBarGetTabName(tabs, &tab)} == name) {
const float x = tabs->BarRect.Min.x + tab.Offset + tab.Width / 2;
const float y = tabs->BarRect.GetCenter().y;
mouse(id, SDL_EVENT_MOUSE_MOTION, x, y);
draw();
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
draw();
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
for (int i = 0; i < 3; ++i)
draw();
CHECK(tabs->SelectedTabId == tab.ID);
return;
}
CHECK(false);
};
choose_tab("Food");
CHECK(journal->ScrollMax.x == 0);
CHECK(app->request_screenshot(
(review / ("cellular-food-" + std::to_string(width) + ".bmp")).string()));
draw();
choose_tab("Cell");
play.disconnected();
play.connected();
++perception.tick;
play.observe(perception);
view.cellular_feed_target.reset();
for (int i = 0; i < 3; ++i)
draw();
}
if (width != 960)
continue;
+33
View File
@@ -502,6 +502,38 @@ void crossing_regions(const Files& f) {
CHECK(a.phase() == LaunchPhase::failed && world.probes.at(dana).owner == 2);
CHECK(db1.claims == region1_claims && db2.claims == region2_claims + 1);
}
void cellular_birth_without_view(const Files& files) {
test::WorldDb world;
test::RegionDb control{world, region};
const auto owner = account(0xD1);
std::vector<std::uint64_t> requests;
auto answer = PrimitiveLifeResult::pending;
Region r{files, [&](server::RegionSessionsConfig& config) {
config.ledger = &control;
config.accept_cellular_actions = true;
config.create_primitive_life = [&](const AccountId& a, std::uint64_t generation,
std::uint64_t id) {
CHECK(a == owner && generation != 0);
requests.push_back(id);
return PrimitiveLifeOutcome{id, answer, 901, 0};
};
config.query_primitive_life = config.create_primitive_life;
}};
Client c;
CHECK(c.host.connect(RemoteSession::open(r.material({r.grant(owner, 1)}), true)));
CHECK(c.until(r, [&] { return requests.size() >= 2; }));
auto& remote = *c.host.session();
CHECK(requests[0] == requests[1] && !remote.cellular_play().can_restart() &&
!remote.cellular_perception());
answer = PrimitiveLifeResult::insufficient_funding;
CHECK(c.until(r, [&] { return remote.cellular_play().can_restart(); }));
CHECK(!remote.cellular_play().fresh() &&
remote.status().cellular_action.find("nursery lacks resources") != std::string::npos);
CHECK(remote.restart_cellular() && !remote.restart_cellular());
answer = PrimitiveLifeResult::no_placement;
CHECK(c.until(r, [&] { return remote.cellular_play().can_restart(); }));
CHECK(requests.back() != requests.front() && !remote.cellular_perception());
}
// Real RemoteSession over QUIC; the fixture records authority answers without simulating biology.
void cellular_v10(const Files& files) {
using namespace evo::client_app;
@@ -680,6 +712,7 @@ int main() try {
}
crossing_regions(files);
cellular_v10(files);
cellular_birth_without_view(files);
std::filesystem::remove_all(files.dir);
std::puts("client remote session tests passed");
return 0;
+46 -1
View File
@@ -107,6 +107,12 @@ void cellular_assistance() {
CHECK(!steer_cellular(controls, {}, &view, &population, {}).patch);
view.patches[0].matter_fg[2] = 1;
CHECK(steer_cellular(controls, {}, &view, &population, {}).patch);
view.patches.push_back({0, 2000, 100, {}});
CHECK(steer_cellular(controls, {}, &view, &population, {}).patch ==
std::pair<std::uint32_t, std::uint32_t>{0, 2000});
view.patches.back().energy_pj = 0;
CHECK(steer_cellular(controls, {}, &view, &population, {}).patch ==
std::pair<std::uint32_t, std::uint32_t>{1000, 2000});
view.life_identity = 0;
CHECK(!steer_cellular(controls, {}, &view, &population, {}).patch);
network::CellularOfferedCandidate candidate;
@@ -122,7 +128,7 @@ void cellular_assistance() {
reserve.reserve_energy_pj = 9;
CHECK(!can_fund(candidate, reserve));
std::vector<render::Rectangle> scene;
patch_box(scene, {-10, 100}, {100, -10}, true, true, 80, 80);
patch_box(scene, {0, 80}, {80, 0}, true, true, true, 80, 80);
CHECK(scene.size() == patch_rectangles);
for (const auto& r : scene)
CHECK(r.x >= 0 && r.y >= 0 && r.x + r.width <= 80 && r.y + r.height <= 80);
@@ -465,6 +471,44 @@ void cellular_play() {
exhausted.initialize(std::numeric_limits<std::uint64_t>::max());
CHECK(exhausted.allocate_id() == 0 && exhausted.allocate_id() == 0);
}
void cellular_energy_and_birth_wait() {
using namespace evo::client_app;
using namespace evo::network;
CellularPlay play;
play.initialize(1);
play.connected();
CHECK(!play.can_restart());
play.birth({1, PrimitiveLifeResult::pending, 7, 0});
CHECK(!play.can_restart());
play.birth({1, PrimitiveLifeResult::insufficient_funding, 7, 0});
CHECK(!play.fresh() && play.can_restart()); // Refusal arrives without any world view.
CHECK(play.restart() && play.birth_request() == 2 && !play.restart());
play.birth({1, PrimitiveLifeResult::no_placement, 7, 0});
CHECK(play.birth_pending()); // Delayed answer to an older request is ignored.
play.birth({2, PrimitiveLifeResult::existing_life, 9, 0});
CHECK(!play.can_restart()); // Wait for that existing life instead of offering another birth.
CellularLifeDiagnostics d;
d.reserve_energy_pj = 200;
play.observe({10, 9, {}, d});
CHECK(!play.energy_change());
play.observe({11, 0, {}, {}}); // The bridge may clear a view before sending its replacement.
d.reserve_energy_pj = 150;
play.observe({11, 9, {}, d});
CHECK(required(play.energy_change()).falling && required(play.energy_change()).amount == 50);
play.observe({11, 9, {}, d});
CHECK(required(play.energy_change()).amount == 50); // Duplicate views retain the change.
d.reserve_energy_pj = 175;
play.observe({15, 9, {}, d});
CHECK(!required(play.energy_change()).falling && required(play.energy_change()).amount == 25 &&
required(play.energy_change()).from_tick == 11);
play.disconnected();
CHECK(!play.energy_change());
play.connected();
play.observe({16, 9, {}, d});
CHECK(!play.energy_change());
play.observe({17, 10, {}, d});
CHECK(!play.energy_change()); // A different life starts a new baseline.
}
} // namespace
int main() try {
@@ -474,6 +518,7 @@ int main() try {
outcome_log();
session_host();
cellular_play();
cellular_energy_and_birth_wait();
cellular_assistance();
std::puts("client UI model tests passed");
return 0;