feat(admin): take reserve, cull wildlife, wildlife cap, fresh bud costs (schema 67)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m34s
Foundation / postgres-tools (push) Successful in 26s
Foundation / server-image (push) Successful in 4m30s
Foundation / image (push) Successful in 5m46s

ADR-0182 section 16, from playtesting region 16 at its 256-life cap.

- Bud costs: the region host's cache of each genome's bud cost was keyed
  by genome only, so after a tuning adoption the client kept the old cost
  (or "cannot bud"). It now clears when the rules' encoding changes.
- Wildlife cap: reproduction.wildlife_cap (optional, 0..organism cap,
  0 = the organism cap) refuses buds of parents without an account at that
  many lives, keeping the slots above it for players. Bits 17-31 of the
  energy-cycle word, so older rules keep their bytes. DEV file: 200.
- Schema 67: admin command kinds take_reserve (8: up to the amounts from a
  life's reserve to the spent pool) and remove_wildlife (9: every life
  without an account, as remove_cell).
- Region view: caps; the portal shows lives against the cap.
- Portal: Take reserve in the inspector, Remove all wildlife, and marking
  cells on the map (shift+click, shift+drag) for bulk removal; the guided
  editor lists optional keys the base revision lacks.
- Client: a refused bud says the region may be full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-28 16:06:56 -04:00
co-authored by Claude Opus 5.5
parent 51aa08446d
commit 757304437e
24 changed files with 485 additions and 70 deletions
+54
View File
@@ -0,0 +1,54 @@
-- Admin take and cull (ADR-0182 section 16, 2026-10-28). Two more admin command kinds for
-- testing a live region: take_reserve (8) moves up to the given amounts from one life's
-- reserve to the spent pool, the inverse of grant_reserve; remove_wildlife (9) removes every
-- life without an account at once, as remove_cell does one.
ALTER TABLE evolution.admin_commands DROP CONSTRAINT admin_commands_kind_check;
ALTER TABLE evolution.admin_commands ADD CONSTRAINT admin_commands_kind_check
CHECK (kind BETWEEN 1 AND 9);
-- Queues a command (the same shapes the owner accepts). Spawning takes its identities from the
-- world's life allocator, so they never meet a player's.
CREATE OR REPLACE FUNCTION evolution.admin_enqueue_command_v1(p_world evolution.u64,
p_region evolution.u64, p_kind integer, p_count integer, p_target evolution.u64,
p_energy evolution.u64, p_carbon evolution.u64, p_nitrogen evolution.u64,
p_phosphorus evolution.u64, p_other evolution.u64, p_subject text, p_reason text)
RETURNS TABLE (command_id bigint, target evolution.u64)
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
#variable_conflict use_column
DECLARE
has_amount boolean := p_energy + p_carbon + p_nitrogen + p_phosphorus + p_other > 0;
first numeric := p_target;
BEGIN
IF NOT ((p_kind IN (1, 2, 8) AND p_target > 0 AND p_count = 0
AND has_amount = (p_kind IN (2, 8)))
OR (p_kind IN (3, 5) AND p_target = 0 AND p_count BETWEEN 1 AND 256 AND has_amount)
OR (p_kind = 4 AND p_target = 0 AND p_count = 0 AND has_amount)
OR (p_kind = 6 AND p_count BETWEEN 1 AND 64 AND NOT has_amount)
OR (p_kind = 9 AND p_target = 0 AND p_count = 0 AND NOT has_amount)) THEN
RAISE EXCEPTION 'invalid admin command' USING ERRCODE = '22023';
END IF;
IF NOT EXISTS (SELECT 1 FROM evolution.region_leases l
WHERE l.world_id = p_world AND l.region_id = p_region) THEN
RAISE EXCEPTION 'unknown region' USING ERRCODE = '22023';
END IF;
IF p_kind = 6 THEN
SELECT a.next_identity INTO first FROM evolution.life_allocators a
WHERE a.world_id = p_world FOR UPDATE;
IF first IS NULL OR first + p_count > 9223372036854775808 THEN
RAISE EXCEPTION 'no identities for wildlife' USING ERRCODE = '22023';
END IF;
UPDATE evolution.life_allocators SET next_identity = first + p_count
WHERE world_id = p_world;
END IF;
RETURN QUERY
WITH queued AS (
INSERT INTO evolution.admin_commands AS q(world_id, region_id, kind, cell_count, target,
energy, carbon, nitrogen, phosphorus, other, author_subject, reason)
VALUES (p_world, p_region, p_kind, p_count, first, p_energy, p_carbon, p_nitrogen,
p_phosphorus, p_other, p_subject, coalesce(p_reason, ''))
RETURNING q.command_id, q.target)
SELECT queued.command_id, queued.target FROM queued;
END $$;
INSERT INTO evolution.schema_migrations(version,sha256) VALUES(67,:'migration_sha_67');
+12 -3
View File
@@ -142,6 +142,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
SELECT :'history_v63' || ',64:' || :'migration_sha_64' AS history_v64 \gset
SELECT :'history_v64' || ',65:' || :'migration_sha_65' AS history_v65 \gset
SELECT :'history_v65' || ',66:' || :'migration_sha_66' AS history_v66 \gset
SELECT :'history_v66' || ',67:' || :'migration_sha_67' AS history_v67 \gset
SELECT :'history' = :'history_v22' AS at_v22,
:'history' = :'history_v23' AS at_v23,
:'history' = :'history_v24' AS at_v24,
@@ -186,8 +187,10 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
:'history' = :'history_v63' AS at_v63,
:'history' = :'history_v64' AS at_v64,
:'history' = :'history_v65' AS at_v65,
:'history' = :'history_v66' AS at_v66 \gset
\if :at_v66
:'history' = :'history_v66' AS at_v66,
:'history' = :'history_v67' AS at_v67 \gset
\if :at_v67
\elif :at_v66
\elif :at_v65
\elif :at_v64
\elif :at_v63
@@ -613,7 +616,8 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
coalesce(max(version), 0) = 63 AS at_v63,
coalesce(max(version), 0) = 64 AS at_v64,
coalesce(max(version), 0) = 65 AS at_v65,
coalesce(max(version), 0) = 66 AS at_v66
coalesce(max(version), 0) = 66 AS at_v66,
coalesce(max(version), 0) = 67 AS at_v67
FROM evolution.schema_migrations \gset
\if :at_v24
\ir 0025_cellular_v2_bundle.sql
@@ -848,6 +852,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
\elif :at_v64
\elif :at_v65
\elif :at_v66
\elif :at_v67
\else
\echo 'Unknown or changed migration history after v43'
DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$;
@@ -944,6 +949,10 @@ SELECT coalesce(max(version), 0) = 65 AS needs_v66 FROM evolution.schema_migrati
\if :needs_v66
\ir 0066_tuning_revisions.sql
\endif
SELECT coalesce(max(version), 0) = 66 AS needs_v67 FROM evolution.schema_migrations \gset
\if :needs_v67
\ir 0067_admin_take_and_cull.sql
\endif
-- Effective-privilege audit on every run, including no-ops (ADR-0060). Attributes
-- alone are insufficient: predefined roles such as pg_write_all_data, PUBLIC
-- grants or SET-able memberships would bypass the fenced functions. Checks the