feat(cellular): region ticks of up to 4,096 lives for testing (schema 68)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / postgres-tools (push) Successful in 31s
Foundation / server-image (push) Successful in 4m29s
Foundation / image (push) Successful in 5m43s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / postgres-tools (push) Successful in 31s
Foundation / server-image (push) Successful in 4m29s
Foundation / image (push) Successful in 5m43s
ADR-0182 section 17. The plan's 2,000-organism cap became the rules-12 key region.organism_cap, which was parsed but never enforced; the real bound was max_cellular_tick_lives = 256 (ADR-0106), which rules 13's organism cap could not exceed. The bound is now 4,096, for testing limits only; the DEV tuning file keeps 256. - max_cellular_tick_lives (4,096) bounds the raw region path: step, owner state, batch trace (cellular_batch_bytes_for) and current checkpoint traces. max_cellular_frozen_lives (256) keeps cohort populations, population batches, migration traces and pre-v3 cellular traces, whose database checks are fixed. - Tuning: reproduction.organism_cap and wildlife_cap accept up to 4,096. - Schema 68: the trace checker under the current publishers (cellular_births_v45) accepts 4,096 intents, births and mutations per tick; spawn_wildlife takes up to 256 cells a command. - Region view and portal: the lineage archive's fill (births of 65,536, genomes of 4,096), at which a region stops ticking. - PostgreSQL suite: 256 wildlife spawned in one command, then a 289-life tick published and recovered exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
-- Larger region ticks (ADR-0182 section 17, 2026-10-28). A region tick may hold up to 4,096
|
||||
-- lives, a bound for testing (regions run far fewer). The cellular trace checker under the
|
||||
-- current publishers (schema 43's, renamed cellular_births_v45 by schema 46) accepts up to
|
||||
-- 4,096 intents, births and mutation choices per tick; nothing else in it changes. Cohort
|
||||
-- populations and migration traces keep their 256 bounds. Spawning takes up to 256 wildlife
|
||||
-- per command.
|
||||
|
||||
CREATE OR REPLACE FUNCTION evolution.cellular_births_v45(p_trace bytea, p_manifest bytea)
|
||||
RETURNS TABLE(account_id uuid, request_id evolution.u64, generation evolution.u64,
|
||||
identity evolution.u64, born evolution.u64)
|
||||
LANGUAGE plpgsql IMMUTABLE SECURITY INVOKER SET search_path = pg_catalog, pg_temp AS $$
|
||||
DECLARE
|
||||
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
|
||||
revision boolean;
|
||||
ticks numeric;
|
||||
tick_index integer;
|
||||
trace_format numeric;
|
||||
tick_header_size integer;
|
||||
intent_count numeric;
|
||||
birth_count numeric;
|
||||
mutation_count numeric;
|
||||
off integer := 112;
|
||||
account bytea;
|
||||
previous_account bytea;
|
||||
previous_request numeric;
|
||||
BEGIN
|
||||
revision := c.versions IN (
|
||||
'\x020000000300000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x030000000400000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x040000000500000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x050000000600000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x060000000600000001000000010000000100000003000000020000000200000001000000'::bytea,
|
||||
'\x070000000600000001000000010000000100000004000000030000000200000001000000'::bytea,
|
||||
'\x080000000600000002000000010000000100000004000000030000000200000001000000'::bytea);
|
||||
trace_format := evolution.manifest_uint(p_trace, 8, 4);
|
||||
tick_header_size := CASE trace_format WHEN 2 THEN 8 WHEN 3 THEN 16 ELSE 0 END;
|
||||
IF c.profile <> 4 OR c.commit_sequence = 0 OR p_trace IS NULL
|
||||
OR octet_length(p_trace) <> c.trace_bytes OR sha256(p_trace) <> c.trace_sha256
|
||||
OR substring(p_trace FROM 1 FOR 8) <> '\x45564c4342543031'
|
||||
OR tick_header_size = 0
|
||||
OR (revision AND trace_format <> 3)
|
||||
OR (NOT revision AND trace_format <> 2)
|
||||
OR evolution.manifest_uint(p_trace, 12, 4) <> 4
|
||||
OR evolution.manifest_uint(p_trace, 16, 8) <> c.world_id
|
||||
OR evolution.manifest_uint(p_trace, 24, 8) <> c.region_id
|
||||
OR evolution.manifest_uint(p_trace, 32, 8) <> c.frame_id
|
||||
OR encode(substring(p_trace FROM 41 FOR 16), 'hex')::uuid <> c.predecessor_commit
|
||||
OR substring(p_trace FROM 57 FOR 32) <> c.predecessor_digest
|
||||
OR evolution.manifest_uint(p_trace, 88, 8) <> c.begin_tick
|
||||
OR evolution.manifest_uint(p_trace, 96, 8) <> c.end_tick THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth trace binding' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
ticks := c.end_tick - c.begin_tick;
|
||||
IF ticks < 1 OR ticks > 64 OR evolution.manifest_uint(p_trace, 104, 4) <> ticks
|
||||
OR evolution.manifest_uint(p_trace, 108, 4) <> 0 THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth trace range' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
FOR tick_index IN 0 .. ticks::integer - 1 LOOP
|
||||
IF off + tick_header_size > octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'truncated cellular tick header' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
intent_count := evolution.manifest_uint(p_trace, off, 4);
|
||||
birth_count := evolution.manifest_uint(p_trace, off + 4, 4);
|
||||
mutation_count := 0;
|
||||
IF trace_format = 3 THEN
|
||||
mutation_count := evolution.manifest_uint(p_trace, off + 8, 4);
|
||||
IF evolution.manifest_uint(p_trace, off + 12, 4) <> 0 THEN
|
||||
RAISE EXCEPTION 'invalid cellular tick reserved word' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
END IF;
|
||||
IF intent_count > 4096 OR birth_count > 4096 OR mutation_count > 4096
|
||||
OR off + tick_header_size + intent_count * 24 + birth_count * 40
|
||||
+ mutation_count * 40 > octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'invalid cellular tick counts' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
off := off + tick_header_size + intent_count::integer * 24;
|
||||
previous_account := ''::bytea;
|
||||
previous_request := -1;
|
||||
FOR birth_index IN 0 .. birth_count::integer - 1 LOOP
|
||||
account := substring(p_trace FROM off + 1 FOR 16);
|
||||
account_id := encode(account, 'hex')::uuid;
|
||||
request_id := evolution.manifest_uint(p_trace, off + 16, 8);
|
||||
generation := evolution.manifest_uint(p_trace, off + 24, 8);
|
||||
identity := evolution.manifest_uint(p_trace, off + 32, 8);
|
||||
born := c.begin_tick + tick_index + 1;
|
||||
IF account_id = '00000000-0000-0000-0000-000000000000' OR request_id = 0
|
||||
OR generation = 0 OR identity = 0
|
||||
OR (account, request_id) <= (previous_account, previous_request) THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth record' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
previous_account := account;
|
||||
previous_request := request_id;
|
||||
off := off + 40;
|
||||
RETURN NEXT;
|
||||
END LOOP;
|
||||
off := off + mutation_count::integer * 40;
|
||||
END LOOP;
|
||||
IF off <> octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'trailing cellular trace bytes' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
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 256 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(68,:'migration_sha_68');
|
||||
+12
-3
@@ -143,6 +143,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
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_v67' || ',68:' || :'migration_sha_68' AS history_v68 \gset
|
||||
SELECT :'history' = :'history_v22' AS at_v22,
|
||||
:'history' = :'history_v23' AS at_v23,
|
||||
:'history' = :'history_v24' AS at_v24,
|
||||
@@ -188,8 +189,10 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
:'history' = :'history_v64' AS at_v64,
|
||||
:'history' = :'history_v65' AS at_v65,
|
||||
:'history' = :'history_v66' AS at_v66,
|
||||
:'history' = :'history_v67' AS at_v67 \gset
|
||||
\if :at_v67
|
||||
:'history' = :'history_v67' AS at_v67,
|
||||
:'history' = :'history_v68' AS at_v68 \gset
|
||||
\if :at_v68
|
||||
\elif :at_v67
|
||||
\elif :at_v66
|
||||
\elif :at_v65
|
||||
\elif :at_v64
|
||||
@@ -617,7 +620,8 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
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) = 67 AS at_v67
|
||||
coalesce(max(version), 0) = 67 AS at_v67,
|
||||
coalesce(max(version), 0) = 68 AS at_v68
|
||||
FROM evolution.schema_migrations \gset
|
||||
\if :at_v24
|
||||
\ir 0025_cellular_v2_bundle.sql
|
||||
@@ -853,6 +857,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\elif :at_v65
|
||||
\elif :at_v66
|
||||
\elif :at_v67
|
||||
\elif :at_v68
|
||||
\else
|
||||
\echo 'Unknown or changed migration history after v43'
|
||||
DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$;
|
||||
@@ -953,6 +958,10 @@ SELECT coalesce(max(version), 0) = 66 AS needs_v67 FROM evolution.schema_migrati
|
||||
\if :needs_v67
|
||||
\ir 0067_admin_take_and_cull.sql
|
||||
\endif
|
||||
SELECT coalesce(max(version), 0) = 67 AS needs_v68 FROM evolution.schema_migrations \gset
|
||||
\if :needs_v68
|
||||
\ir 0068_larger_region_ticks.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
|
||||
|
||||
Reference in New Issue
Block a user