Files
aevolution/tools/ops/end-account-life.sql
dingoandClaude Opus 5.5 736bf98aaa
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m27s
Foundation / postgres-tools (push) Successful in 26s
Foundation / server-image (push) Successful in 4m18s
Foundation / image (push) Successful in 5m4s
fix(server): end a player's life under the reservation's root identity
Playtest: after becoming a split's offspring and being engulfed, every new
birth was refused ("Existing cell is already bound to this account"). The
region recorded the ending under the dead cell's own identity, which was never
reserved, so the database ignored it and the founder's reservation stayed
open. After Adhesion the opposite happened: the merged founder's ending closed
the reservation while the player lived on as the organism.

An account's life now ends only when no life holds the account, and the ending
names the lineage root (cellular_lineage_root): the life born from the
reservation, reached through parent links in lives and corpses.

tools/ops/end-account-life.sql lets the operator end one stranded account's
reservation (dry run unless confirm=yes; exactly one match required).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 13:24:06 -04:00

88 lines
4.0 KiB
PL/PgSQL

-- 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