diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index a0ba635..5bc7816 100644 --- a/deploy/kubernetes/region/dev-session-route/listener.yaml +++ b/deploy/kubernetes/region/dev-session-route/listener.yaml @@ -12,7 +12,7 @@ spec: env: - {name: REGION_SESSION, value: "dev"} - {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"} - - {name: REGION_SESSION_WINDOW, value: "dev-20261026T165529-3cf86700:1793048129"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261026T172353-ce652e19:1793049833"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/include/evo/server/lifecycle/cellular_lives.hpp b/include/evo/server/lifecycle/cellular_lives.hpp index 076743b..0a8a96c 100644 --- a/include/evo/server/lifecycle/cellular_lives.hpp +++ b/include/evo/server/lifecycle/cellular_lives.hpp @@ -290,6 +290,12 @@ enum class CellularLivesError : std::uint8_t { // as (the target size times its members); the genome itself for a single cell. [[nodiscard]] std::expected cellular_organism_genome(const biology::Genome& genome, std::uint32_t members); +class CellularLives; +// The root of a life's lineage: its parent's parent and so on, through living cells and +// corpses, up to the life without a parent (a player's birth). A player's life reservation +// names that root, even after control moved to an offspring, a bud or an organism. +[[nodiscard]] std::uint64_t cellular_lineage_root(const CellularLives& state, + std::uint64_t life_id); // In-memory authoritative cellular owner. It consumes funded profile-3 opening // state but never mutates or reinterprets that checkpoint. Each tick is applied diff --git a/src/server/cellular_region_host.cpp b/src/server/cellular_region_host.cpp index 300b25f..ca882f4 100644 --- a/src/server/cellular_region_host.cpp +++ b/src/server/cellular_region_host.cpp @@ -746,12 +746,17 @@ const HostStatus& CellularRegionHost::step() { void CellularRegionHost::note_endings(const CellularLives& before, const CellularLives& after, const persistence::Uuid& commit) { - for (const auto& life : before.lives()) - if (life.account != LifeAccount{} && - std::ranges::find(after.lives(), life.identity.life, [](const CellularOwnedLife& next) { - return next.identity.life; - }) == after.lives().end()) - pending_endings_.push_back({commit, life.identity.life}); + for (const auto& life : before.lives()) { + // Rules 13: control can move to another life (becoming a split's offspring or a bud, + // Adhesion's organism). The account's life ends only when no life holds it any more. + if (life.account == LifeAccount{} || + std::ranges::find(after.lives(), life.account, &CellularOwnedLife::account) != + after.lives().end()) + continue; + // The reservation names the life born from it, the root of the lineage control + // followed, so the ending is recorded against that root. + pending_endings_.push_back({commit, cellular_lineage_root(after, life.identity.life)}); + } } void CellularRegionHost::flush_endings() { diff --git a/src/server/lifecycle/cellular_lives.cpp b/src/server/lifecycle/cellular_lives.cpp index 6a6bffd..dfebe82 100644 --- a/src/server/lifecycle/cellular_lives.cpp +++ b/src/server/lifecycle/cellular_lives.cpp @@ -1028,6 +1028,26 @@ cellular_organism_genome(const biology::Genome& genome, std::uint32_t members) { return organism_genome(genome, members); } +std::uint64_t cellular_lineage_root(const CellularLives& state, std::uint64_t life_id) { + const auto parent_of = [&](std::uint64_t id) -> std::optional { + for (const auto& life : state.lives()) + if (life.identity.life == id) + return life.parent_life; + for (const auto& corpse : state.corpses()) + if (corpse.life_id == id) + return corpse.parent_life; + return std::nullopt; + }; + auto root = life_id; + auto parent = parent_of(life_id); + for (std::size_t step = 0; parent && *parent != 0 && step < biology::max_archived_organisms; + ++step) { + root = *parent; + parent = parent_of(root); + } + return root; +} + bool cellular_can_emerge(const CellularOwnedLife& life, const CellularRevampRules& rules) noexcept { std::uint64_t mass{}; for (std::size_t c = 0; c < life.body.matter.size(); ++c) diff --git a/tests/cellular_revamp_owner_tests.cpp b/tests/cellular_revamp_owner_tests.cpp index 4b9d499..48ad81f 100644 --- a/tests/cellular_revamp_owner_tests.cpp +++ b/tests/cellular_revamp_owner_tests.cpp @@ -429,6 +429,10 @@ void a_choice_splits_the_cell(bool become) { require(become ? child.account == account(2) && founder.account == LifeAccount{} : child.account == LifeAccount{} && founder.account == account(2), "control did not follow the choice"); + // The account's reservation names the founder it was born as, wherever control went. + require(cellular_lineage_root(*state, identity) == 101 && + cellular_lineage_root(*state, 101) == 101, + "the lineage root is not the founder born from the reservation"); require(state->habitat().patches().size() >= deposits + 1, "the paid cost was not reclaimed"); closed(*state); // A half-grown founder cannot split again, so its next offer waits until it has regrown. diff --git a/tools/ops/end-account-life.sql b/tools/ops/end-account-life.sql new file mode 100644 index 0000000..1b8fbb7 --- /dev/null +++ b/tools/ops/end-account-life.sql @@ -0,0 +1,87 @@ +-- End one account's active life reservation so the account can be born again. +-- +-- DEV operator tool, run as the database owner, for an account whose cell has died but whose +-- reservation was never ended. Before 2026-10-26 a region recorded a death under the dead +-- cell's own identity; after the player had become a split's offspring, a bud or an organism, +-- that identity was never reserved, so the founder's reservation stayed open and every new +-- birth was refused ("Existing cell is already bound to this account"). +-- +-- Check first that the account has no living cell (the client shows the end-of-life screen). +-- The reservation is ended at the region's latest commit, exactly as end_cellular_lives does; +-- the region's checkpoints and history are left unchanged. The founder named by the +-- reservation may still live on as wildlife; that is expected. +-- +-- `account` is the account id or its leading hex digits (the region logs show acct-xxxxxxxx). +-- It is a dry run unless confirm=yes, and refuses unless exactly one active reservation +-- matches. +-- +-- psql -X -v world=100 -v region=14 -v account=807813d1 -f end-account-life.sql +-- psql -X -v world=100 -v region=14 -v account=807813d1 -v confirm=yes -f end-account-life.sql +\set ON_ERROR_STOP on +\if :{?world} +\else + \echo 'usage: psql -v world=W -v region=R -v account=HEX [-v confirm=yes] -f end-account-life.sql' + \quit +\endif +\if :{?region} +\else + \echo 'usage: psql -v world=W -v region=R -v account=HEX [-v confirm=yes] -f end-account-life.sql' + \quit +\endif +\if :{?account} +\else + \echo 'usage: psql -v world=W -v region=R -v account=HEX [-v confirm=yes] -f end-account-life.sql' + \quit +\endif +\if :{?confirm} +\else + \set confirm no +\endif +BEGIN; +SELECT set_config('ending.world', :'world', true), set_config('ending.region', :'region', true), + set_config('ending.account', :'account', true); +DO $$ +DECLARE + w numeric := current_setting('ending.world')::numeric; + r numeric := current_setting('ending.region')::numeric; + prefix text := lower(replace(current_setting('ending.account'), '-', '')); + latest uuid; + matches integer; + reserved evolution.life_reservations%ROWTYPE; +BEGIN + IF w <= 0 OR r <= 0 OR prefix !~ '^[0-9a-f]{4,32}$' THEN + RAISE EXCEPTION 'world and region must be positive and account at least 4 hex digits'; + END IF; + SELECT count(*) INTO matches FROM evolution.life_reservations x + WHERE x.world_id = w AND x.region_id = r AND x.rejection = 0 AND x.ended_commit IS NULL + AND replace(x.account_id::text, '-', '') LIKE prefix || '%'; + IF matches <> 1 THEN + RAISE EXCEPTION '% active reservations match account % in region %; expected exactly one', + matches, prefix, r; + END IF; + SELECT * INTO reserved FROM evolution.life_reservations x + WHERE x.world_id = w AND x.region_id = r AND x.rejection = 0 AND x.ended_commit IS NULL + AND replace(x.account_id::text, '-', '') LIKE prefix || '%' FOR UPDATE; + SELECT c.commit_id INTO latest FROM evolution.region_commits c + WHERE c.world_id = w AND c.region_id = r ORDER BY c.commit_sequence DESC LIMIT 1; + IF latest IS NULL THEN + RAISE EXCEPTION 'region % of world % has no commit', r, w; + END IF; + IF NOT EXISTS (SELECT 1 FROM evolution.primitive_life_bindings b WHERE b.world_id = w + AND b.account_id = reserved.account_id AND b.request_id = reserved.request_id) THEN + UPDATE evolution.life_reservations x SET rejection = 3 + WHERE x.world_id = w AND x.account_id = reserved.account_id AND x.request_id = reserved.request_id; + RAISE NOTICE 'account %: unpublished reservation % cancelled', reserved.account_id, reserved.identity; + ELSE + UPDATE evolution.life_reservations x SET ended_commit = latest + WHERE x.world_id = w AND x.account_id = reserved.account_id AND x.request_id = reserved.request_id; + RAISE NOTICE 'account %: life % ended at commit %', reserved.account_id, reserved.identity, latest; + END IF; +END $$; +\if :confirm + COMMIT; + \echo 'committed' +\else + ROLLBACK; + \echo 'dry run: nothing changed (add -v confirm=yes to apply)' +\endif