-- Admin: end a stranded life (ADR-0182 section 18, 2026-10-29). A published life whose -- reservation was never ended refuses every new birth for the account ("Existing cell is -- already bound to this account"). The admin API first checks that no cell in the life's -- region holds the account; this function then ends the reservation at the region's latest -- commit, exactly as end_cellular_lives does, and records who did it and why. Unpublished -- reservations are left to the region, which still holds them as queued births. The region's -- checkpoints and history are unchanged. CREATE TABLE evolution.admin_life_endings ( sequence bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, world_id evolution.u64 NOT NULL, account_id uuid NOT NULL, request_id evolution.u64 NOT NULL, ended_commit uuid NOT NULL, author_subject text NOT NULL CHECK (octet_length(author_subject) BETWEEN 1 AND 255), reason text NOT NULL DEFAULT '' CHECK (octet_length(reason) <= 500), created_at timestamptz NOT NULL DEFAULT clock_timestamp() ); CREATE TRIGGER admin_life_endings_immutable BEFORE UPDATE OR DELETE ON evolution.admin_life_endings FOR EACH ROW EXECUTE FUNCTION evolution.refuse_history_rewrite(); -- Returns true when this call ended the life, false when it was not open (already ended, -- refused or cancelled). Raises EVL21 for an unknown or unpublished request. CREATE FUNCTION evolution.admin_end_account_life_v1(p_world evolution.u64, p_account uuid, p_request evolution.u64, p_subject text, p_reason text) RETURNS boolean LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$ DECLARE r evolution.life_reservations%ROWTYPE; latest uuid; BEGIN IF p_world IS NULL OR p_world = 0 OR p_account IS NULL OR p_request IS NULL OR p_request = 0 THEN RAISE EXCEPTION 'invalid life ending' USING ERRCODE = '22023'; END IF; SELECT * INTO r FROM evolution.life_reservations x WHERE x.world_id = p_world AND x.account_id = p_account AND x.request_id = p_request FOR UPDATE; IF NOT FOUND OR NOT EXISTS (SELECT 1 FROM evolution.primitive_life_bindings b WHERE b.world_id = p_world AND b.account_id = p_account AND b.request_id = p_request) THEN RAISE EXCEPTION 'no published life for this request' USING ERRCODE = 'EVL21'; END IF; IF r.rejection <> 0 OR r.ended_commit IS NOT NULL THEN RETURN false; END IF; SELECT c.commit_id INTO latest FROM evolution.region_commits c WHERE c.world_id = p_world AND c.region_id = r.region_id ORDER BY c.commit_sequence DESC LIMIT 1; IF latest IS NULL THEN RAISE EXCEPTION 'region has no commit' USING ERRCODE = 'EVL21'; END IF; UPDATE evolution.life_reservations x SET ended_commit = latest WHERE x.world_id = p_world AND x.account_id = p_account AND x.request_id = p_request; INSERT INTO evolution.admin_life_endings(world_id, account_id, request_id, ended_commit, author_subject, reason) VALUES (p_world, p_account, p_request, latest, p_subject, coalesce(p_reason, '')); RETURN true; END $$; REVOKE ALL ON FUNCTION evolution.admin_end_account_life_v1(evolution.u64, uuid, evolution.u64, text, text) FROM PUBLIC; -- A region refuses a birth whose account still holds a cell in its state (life_exists) and -- records that refusal as existing_life (4). Schema 15 accepted only reasons 1..3, so the -- refusal was never recorded: the reservation stayed open and unpublished, and refused every -- later birth for the account. Schema 17 already let the column hold 4. CREATE OR REPLACE FUNCTION evolution.reject_primitive_life(p_world evolution.u64, p_region evolution.u64, p_holder uuid, p_epoch evolution.u64, p_account uuid, p_generation evolution.u64, p_request evolution.u64, p_reason smallint) RETURNS smallint LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$ DECLARE r evolution.life_reservations%ROWTYPE; BEGIN IF p_request IS NULL OR p_request = 0 OR p_reason IS NULL OR p_reason NOT BETWEEN 1 AND 4 THEN RAISE EXCEPTION 'invalid life rejection' USING ERRCODE = '22023'; END IF; PERFORM evolution.check_life_control(p_world, p_region, p_holder, p_epoch, p_account, p_generation); SELECT * INTO r FROM evolution.life_reservations x WHERE x.world_id = p_world AND x.account_id = p_account AND x.request_id = p_request FOR UPDATE; IF NOT FOUND OR r.region_id <> p_region THEN RAISE EXCEPTION 'life reservation not owned' USING ERRCODE = 'EVL04'; END IF; IF r.rejection <> 0 THEN RETURN r.rejection; END IF; UPDATE evolution.life_reservations SET rejection = p_reason WHERE world_id = p_world AND account_id = p_account AND request_id = p_request; RETURN p_reason; END $$; INSERT INTO evolution.schema_migrations(version,sha256) VALUES(69,:'migration_sha_69');