feat(admin): live admin commands in trace 5 (schema 63)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 4m44s
Foundation / image (push) Successful in 5m33s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 4m44s
Foundation / image (push) Successful in 5m33s
The admin portal can now spawn wildlife, add bubbles, add to or release the spent pool, remove a cell and grant a cell's reserve on a running rules-13 region (ADR-0182 section 10). No new owner format or region opening. - Trace 5: trace 4 plus 64-byte command records counted in the tick header's last word; a batch without commands stays trace 4 (older builds replay it). Bundle 15 admits trace 5. - CellularLives::admin_candidate applies a tick's commands after its births, each on a copy kept only when it applies and closes: imports through the boundary ledger, removals into the spent pool with a new `removed` corpse cause, spawned roots via the ADR-0180 seed (now a shared helper) funded by an exact import. Refused commands change nothing. - Schema 63: the immutable admin_commands queue (spawn identities from the life allocator), pending/history reads, and binding of every recorded command exactly once inside both cellular publishers; the SQL trace parsers read trace 5 through its trace-4 normal form. - The region polls pending commands every 2 s and appends up to 16 per tick; the admin API and portal gain region actions, per-cell Remove/Grant and the command history. - Fixes an existing test that did not advance its head after a tick commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -1492,9 +1493,100 @@ void run_starting_wildlife_publication_tests() {
|
||||
auto tick = publish_cellular_batch(*runtime, **objects, *lease, head, batch, *recovered->state,
|
||||
identity(8), build, 5s);
|
||||
CHECK(tick);
|
||||
head = tick->committed;
|
||||
recovered = recover_cellular_checkpoint(*runtime, **objects, key, *lease, builds, 5s);
|
||||
CHECK(recovered && recovered->state->snapshot() == tick_bytes &&
|
||||
recovered->state->lives().size() == 32);
|
||||
|
||||
// ADR-0182 (schema 63): queued admin commands publish in trace 5 and bind once.
|
||||
CHECK(owner->query("INSERT INTO evolution.life_allocators(world_id, next_identity) "
|
||||
"VALUES ($1, 5000000) ON CONFLICT DO NOTHING",
|
||||
std::array{std::to_string(key.world)}, 5s));
|
||||
const auto enqueue = [&](int kind, int count, std::uint64_t target, std::uint64_t energy) {
|
||||
const auto rows = owner->query(
|
||||
"SELECT command_id, target FROM evolution.admin_enqueue_command_v1($1, $2, $3, $4, "
|
||||
"$5, $6, 0, 0, 0, 0, 'ops', 'test')",
|
||||
std::array{std::to_string(key.world), std::to_string(key.region), std::to_string(kind),
|
||||
std::to_string(count), std::to_string(target), std::to_string(energy)},
|
||||
5s);
|
||||
CHECK(rows && rows->size() == 1);
|
||||
return std::pair{std::stoull(*(*rows)[0][0]), std::stoull(*(*rows)[0][1])};
|
||||
};
|
||||
CHECK(!owner->query("SELECT * FROM evolution.admin_enqueue_command_v1($1, $2, 4, 0, 0, 0, 0, "
|
||||
"0, 0, 0, 'ops', '')",
|
||||
std::array{std::to_string(key.world), std::to_string(key.region)}, 5s));
|
||||
owner = connect_as(env("PGUSER"));
|
||||
const auto victim = recovered->state->lives().front().identity.life;
|
||||
const auto [pool_id, pool_target] = enqueue(4, 0, 0, 1'000'000'000);
|
||||
const auto [spawn_id, first_wild] = enqueue(6, 2, 0, 0);
|
||||
const auto [remove_id, remove_target] = enqueue(1, 0, victim, 0);
|
||||
CHECK(pool_target == 0 && first_wild == 5'000'000 && remove_target == victim);
|
||||
using Kind = evo::server::CellularAdminKind;
|
||||
const std::vector<evo::server::CellularAdminCommand> commands{
|
||||
{static_cast<std::uint64_t>(pool_id), Kind::add_pool, 0, 0, {{1'000'000'000}, {}}},
|
||||
{static_cast<std::uint64_t>(spawn_id), Kind::spawn_wildlife, 2, first_wild, {}},
|
||||
{static_cast<std::uint64_t>(remove_id), Kind::remove_cell, 0, victim, {}}};
|
||||
const auto pending = [&] {
|
||||
const auto rows =
|
||||
runtime->query("SELECT count(*) FROM evolution.load_pending_admin_commands_v1($1, $2)",
|
||||
std::array{std::to_string(key.world), std::to_string(key.region)}, 5s);
|
||||
CHECK(rows && rows->size() == 1);
|
||||
return std::stoull(*(*rows)[0][0]);
|
||||
};
|
||||
CHECK(pending() == 3);
|
||||
const auto admin_batch = [&](std::vector<evo::server::CellularAdminCommand> recorded) {
|
||||
CellularBatch made{{key.world, key.region, 1, head.head.commit, head.head.digest, 2, 3},
|
||||
{{}}};
|
||||
made.format_version = evo::server::cellular_batch_admin_format;
|
||||
made.ticks.front().lives = checked_value(wildlife_intents(*recovered->state, 3));
|
||||
made.ticks.front().admin = std::move(recorded);
|
||||
return made;
|
||||
};
|
||||
// A command that differs from its queue row is refused and the head stays.
|
||||
auto tampered = commands;
|
||||
tampered.front().amount.energy.value = 2'000'000'000;
|
||||
auto wrong = admin_batch(tampered);
|
||||
auto wrong_base = evo::fixture::restore(*recovered->state);
|
||||
CHECK(wrong_base->advance_tick(wrong.ticks.front().lives));
|
||||
auto wrong_state = wrong_base->admin_candidate(tampered);
|
||||
CHECK(wrong_state);
|
||||
CHECK(!publish_cellular_batch(*runtime, **objects, *lease, head, wrong, **wrong_state,
|
||||
identity(9), build, 5s));
|
||||
runtime = connect_as(env("EVO_PG_RUNTIME_USER"));
|
||||
CHECK(pending() == 3);
|
||||
// The exact commands publish, bind and recover.
|
||||
auto admin = admin_batch(commands);
|
||||
CHECK(recovered->state->advance_tick(admin.ticks.front().lives));
|
||||
std::vector<evo::server::CellularAdminResult> results;
|
||||
auto applied = recovered->state->admin_candidate(commands, &results);
|
||||
CHECK(applied && results.size() == 3 &&
|
||||
std::ranges::all_of(results, [](auto r) { return r.applied; }));
|
||||
const auto applied_bytes = (*applied)->snapshot();
|
||||
auto published = publish_cellular_batch(*runtime, **objects, *lease, head, admin, **applied,
|
||||
identity(10), build, 5s);
|
||||
CHECK(published);
|
||||
head = published->committed;
|
||||
CHECK(pending() == 0);
|
||||
const auto bound = owner->query(
|
||||
"SELECT count(*), min(tick), max(tick) FROM evolution.admin_command_applications "
|
||||
"WHERE command_id IN ($1, $2, $3)",
|
||||
std::array{std::to_string(pool_id), std::to_string(spawn_id), std::to_string(remove_id)},
|
||||
5s);
|
||||
CHECK(bound && (*bound)[0][0] == "3" && (*bound)[0][1] == "3" && (*bound)[0][2] == "3");
|
||||
recovered = recover_cellular_checkpoint(*runtime, **objects, key, *lease, builds, 5s);
|
||||
CHECK(recovered && recovered->state->snapshot() == applied_bytes &&
|
||||
recovered->state->lives().size() == 33);
|
||||
// The same commands cannot bind to another commit.
|
||||
auto again = admin_batch(commands);
|
||||
again.header = {key.world, key.region, 1, head.head.commit, head.head.digest, 3, 4};
|
||||
again.ticks.front().lives = checked_value(wildlife_intents(*recovered->state, 4));
|
||||
auto again_base = evo::fixture::restore(*recovered->state);
|
||||
CHECK(again_base->advance_tick(again.ticks.front().lives));
|
||||
auto again_state = again_base->admin_candidate(commands);
|
||||
CHECK(again_state);
|
||||
CHECK(!publish_cellular_batch(*runtime, **objects, *lease, head, again, **again_state,
|
||||
identity(11), build, 5s));
|
||||
runtime = connect_as(env("EVO_PG_RUNTIME_USER"));
|
||||
CHECK(release_region_lease(*runtime, key, *lease, 5s));
|
||||
std::puts("starting wildlife publication and replacement-owner replay passed");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user