Add isolated cellular checkpoint publisher
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (checks) (push) Failing after 38s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 43s
Foundation / checks (ecs) (push) Canceled after 54s
Foundation / checks (tsan) (push) Canceled after 24s

This commit is contained in:
dingo
2026-10-10 23:11:27 -04:00
parent db466618a6
commit e83a6393b9
9 changed files with 288 additions and 10 deletions
@@ -38,7 +38,17 @@ ADR-0111 even if the checkpoint itself were durable.
records before replay. Cellular committed outcomes use `ActionResult::committed`
and include the tick and commit sequence; clients inspect the authoritative
cellular view for state. Probe rows continue to use
`committed_no_effect`.
`committed_no_effect`.
## Publisher representation amendment (2026-10-10)
The profile-4 action block is a sequence of 48-byte records: account UUID bytes
(16), action id (u64 little-endian), and canonical cellular input (24). Records
are strictly ordered by `(intended tick, account bytes, action id)`, contain no
duplicate `(account, action id)`, and are bounded to 1,024 records. PostgreSQL
validates these constraints and binds result rows to the same input bytes. The
private commit-block row is immutable and is required by the progressing
profile-4 commit trigger; only the profile-4 publication wrapper can create it.
## Consequences
+10
View File
@@ -206,6 +206,16 @@ scoped change before starting the next segment.
a reused id while the action is pending or final in memory. Debug and
Release/NDEBUG focused tests pass. RegionSessions still refuses v7 until
publication and restart recovery are complete.
- 11.3d-6a: migration 20 adds the isolated profile-4 publisher and ambiguous
commit resolver. It moves the shared checkpoint transaction into a private
helper while preserving the existing profile-1/2/3 wrapper. A private
immutable row gates progressing profile-4 commits; canonical 48-byte action
records and result rows are inserted atomically with the checkpoint, and
exact retries must match their original block. Runtime grants expose only
the public wrappers, not the private helper, evidence table, or parser.
Migration-chain, privilege-audit, and parser tests are added. PostgreSQL CI is
pending; the C++ writer, full process recovery, and RegionSessions v7 enablement
remain open.
## Exit boundary
+18
View File
@@ -6196,3 +6196,21 @@ Executed locally: warning-as-error MSVC 19.44 direct Debug and Release/NDEBUG
compile/run of `cellular_intent_admission_tests` (authority, scheduling,
canonical bytes, pending/final exact retries and changed-input refusal passed),
plus `git diff --check`. The full network suite and CI are pending.
## 2026-10-10 — M11.3d-6a profile-4 publication SQL (CI pending)
Migration 20 adds a dedicated profile-4 publisher and ambiguous-commit resolver.
It validates canonical 48-byte cellular action records, retains the complete
action block as immutable commit identity, writes per-action canonical input and
the committed-cellular result in the same transaction as checkpoint publication,
and replaces the temporary profile-4 refusal gate with a private-evidence check.
The former checkpoint transaction is now a private helper behind the unchanged
profile-1/2/3 wrapper and the new cellular wrapper. The runtime grant audit
includes both public publisher entry points while excluding the private helper,
evidence table, and internal parser.
Added migration coverage for the canonical action-block parser, function grants,
and lack of runtime insert or private-helper access. `git diff --check` passes.
PostgreSQL migration and integration tests were not run locally because `psql` is
not installed in this Windows environment; Linux/PostgreSQL CI qualification
remains pending. The C++ writer, replay verification, crash/restart process tests,
and RegionSessions v7 enablement remain open.
+194
View File
@@ -0,0 +1,194 @@
-- M11.3d-6a, ADR-0112: isolated profile-4 checkpoint and action publication.
-- The private action block is inserted in the same transaction as the checkpoint;
-- direct calls to the generic writer cannot pass the profile-4 commit trigger.
CREATE TABLE evolution.cellular_publications (
commit_id uuid PRIMARY KEY REFERENCES evolution.region_commits(commit_id)
DEFERRABLE INITIALLY DEFERRED,
actions bytea NOT NULL CHECK (octet_length(actions) <= 49152)
);
REVOKE ALL ON evolution.cellular_publications FROM PUBLIC;
CREATE TRIGGER cellular_publications_immutable BEFORE UPDATE OR DELETE
ON evolution.cellular_publications FOR EACH ROW
EXECUTE FUNCTION evolution.refuse_history_rewrite();
CREATE TRIGGER cellular_publications_no_truncate BEFORE TRUNCATE
ON evolution.cellular_publications FOR EACH STATEMENT
EXECUTE FUNCTION evolution.refuse_history_rewrite();
CREATE FUNCTION evolution.check_cellular_action_block(p_actions bytea,
p_begin numeric, p_end numeric)
RETURNS integer LANGUAGE plpgsql IMMUTABLE SECURITY INVOKER
SET search_path = pg_catalog, pg_temp AS $$
DECLARE
n integer := coalesce(octet_length(p_actions), -1);
account bytea;
action_id numeric;
input_bytes bytea;
tick numeric;
prev_tick numeric := -1;
prev_account bytea := ''::bytea;
prev_id numeric := -1;
seen text[] := '{}';
BEGIN
-- Each record: account UUID (16), action id (u64 LE), canonical input (24).
IF n < 0 OR n % 48 <> 0 OR n / 48 > 1024 THEN
RAISE EXCEPTION 'invalid cellular action block' USING ERRCODE = '22023';
END IF;
FOR i IN 0 .. n / 48 - 1 LOOP
account := substring(p_actions FROM 48 * i + 1 FOR 16);
action_id := evolution.manifest_uint(p_actions, 48 * i + 16, 8);
input_bytes := substring(p_actions FROM 48 * i + 25 FOR 24);
tick := evolution.manifest_uint(input_bytes, 0, 8);
IF account = decode(repeat('00', 16), 'hex') OR action_id = 0
OR tick <= p_begin OR tick > p_end
OR NOT evolution.valid_cellular_action_input(input_bytes, tick)
OR (tick, account, action_id) <= (prev_tick, prev_account, prev_id) THEN
RAISE EXCEPTION 'invalid cellular action record' USING ERRCODE = '22023';
END IF;
IF encode(account, 'hex') || ':' || action_id::text = ANY (seen) THEN
RAISE EXCEPTION 'duplicate cellular action id' USING ERRCODE = '22023';
END IF;
seen := seen || (encode(account, 'hex') || ':' || action_id::text);
prev_tick := tick;
prev_account := account;
prev_id := action_id;
END LOOP;
RETURN n / 48;
END $$;
-- Replace the temporary M11.3 profile-4 refusal gate. Evidence can only be
-- inserted by publish_cellular_checkpoint; the runtime role has no table grant.
CREATE OR REPLACE FUNCTION evolution.refuse_unpublished_cellular() RETURNS trigger
LANGUAGE plpgsql SECURITY INVOKER SET search_path = pg_catalog, pg_temp AS $$
BEGIN
IF evolution.manifest_uint(NEW.manifest, 12, 4) = 4 AND NEW.commit_sequence > 0
AND NOT EXISTS (SELECT 1 FROM evolution.cellular_publications p
WHERE p.commit_id = NEW.commit_id) THEN
RAISE EXCEPTION 'cellular publication evidence required' USING ERRCODE = 'EVL06';
END IF;
RETURN NEW;
END $$;
-- The former two-argument function becomes a private transaction core. Its
-- public name remains a frozen profile-1/2/3 wrapper, while profile 4 can enter
-- the core only through publish_cellular_checkpoint below.
ALTER FUNCTION evolution.publish_region_checkpoint(bytea,bytea)
RENAME TO publish_region_checkpoint_core;
REVOKE ALL ON FUNCTION evolution.publish_region_checkpoint_core(bytea,bytea)
FROM PUBLIC, :"runtime_role";
CREATE FUNCTION evolution.publish_region_checkpoint(p_manifest bytea, p_decisions bytea)
RETURNS TABLE(region_frame evolution.u64, head_sequence evolution.u64, head_commit uuid,
head_digest text, head_tick evolution.u64)
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
DECLARE
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
BEGIN
IF c.profile = 4 THEN
RAISE EXCEPTION 'profile-4 requires cellular publisher' USING ERRCODE = 'EVL06';
END IF;
RETURN QUERY SELECT * FROM evolution.publish_region_checkpoint_core(p_manifest, p_decisions);
END $$;
REVOKE ALL ON FUNCTION evolution.publish_region_checkpoint(bytea,bytea) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION evolution.publish_region_checkpoint(bytea,bytea) TO :"runtime_role";
CREATE FUNCTION evolution.publish_cellular_checkpoint(p_manifest bytea,
p_decisions bytea, p_actions bytea)
RETURNS TABLE(region_frame evolution.u64, head_sequence evolution.u64, head_commit uuid,
head_digest text, head_tick evolution.u64)
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
DECLARE
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
n integer;
old_actions bytea;
r record;
BEGIN
IF c.profile <> 4 OR c.commit_sequence = 0 OR p_actions IS NULL THEN
RAISE EXCEPTION 'invalid cellular publication' USING ERRCODE = '22023';
END IF;
n := evolution.check_cellular_action_block(p_actions, c.begin_tick, c.end_tick);
SELECT p.actions INTO old_actions FROM evolution.cellular_publications p
WHERE p.commit_id = c.commit_id;
IF FOUND THEN
IF old_actions <> p_actions THEN
RAISE EXCEPTION 'cellular commit identity reused' USING ERRCODE = 'EVL07';
END IF;
RETURN QUERY SELECT * FROM evolution.publish_region_checkpoint_core(p_manifest, p_decisions);
RETURN;
END IF;
PERFORM evolution.check_region_lease(c.world_id, c.region_id, c.holder, c.epoch);
-- Recheck after the lease lock: an uncertain first attempt may have completed.
SELECT p.actions INTO old_actions FROM evolution.cellular_publications p
WHERE p.commit_id = c.commit_id;
IF FOUND THEN
IF old_actions <> p_actions THEN
RAISE EXCEPTION 'cellular commit identity reused' USING ERRCODE = 'EVL07';
END IF;
RETURN QUERY SELECT * FROM evolution.publish_region_checkpoint_core(p_manifest, p_decisions);
RETURN;
END IF;
INSERT INTO evolution.cellular_publications(commit_id, actions)
VALUES (c.commit_id, p_actions);
FOR i IN 0 .. n - 1 LOOP
INSERT INTO evolution.region_actions(world_id, account_id, action_id, region_id, tick,
kind, commit_sequence, input_bytes, result)
VALUES (c.world_id,
encode(substring(p_actions FROM 48 * i + 1 FOR 16), 'hex')::uuid,
evolution.manifest_uint(p_actions, 48 * i + 16, 8), c.region_id,
evolution.manifest_uint(p_actions, 48 * i + 25, 8), 2, c.commit_sequence,
substring(p_actions FROM 48 * i + 25 FOR 24), 5)
ON CONFLICT (world_id, account_id, action_id) DO NOTHING;
IF NOT EXISTS (SELECT 1 FROM evolution.region_actions a
WHERE a.world_id = c.world_id
AND a.account_id = encode(substring(p_actions FROM 48 * i + 1 FOR 16), 'hex')::uuid
AND a.action_id = evolution.manifest_uint(p_actions, 48 * i + 16, 8)
AND a.kind = 2 AND a.result = 5
AND a.input_bytes = substring(p_actions FROM 48 * i + 25 FOR 24)) THEN
RAISE EXCEPTION 'cellular action identity reused' USING ERRCODE = 'EVL07';
END IF;
END LOOP;
-- The trigger on region_commits requires the private action-block row above.
-- A failure here rolls back the block and all outcome rows with the head advance.
SELECT * INTO r FROM evolution.publish_region_checkpoint_core(p_manifest, p_decisions);
IF NOT FOUND THEN
RAISE EXCEPTION 'publication returned no head' USING ERRCODE = 'XX000';
END IF;
RETURN QUERY SELECT r.region_frame, r.head_sequence, r.head_commit, r.head_digest,
r.head_tick;
END $$;
CREATE FUNCTION evolution.resolve_cellular_region_commit(p_world evolution.u64,
p_region evolution.u64, p_commit uuid, p_manifest bytea, p_decisions bytea,
p_actions bytea)
RETURNS TABLE(status text, region_frame evolution.u64, head_sequence evolution.u64,
head_commit uuid, head_digest text, head_tick evolution.u64)
LANGUAGE plpgsql STABLE SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
DECLARE
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
old_actions bytea;
BEGIN
IF c.profile <> 4 OR c.commit_sequence = 0 OR c.world_id <> p_world
OR c.region_id <> p_region OR c.commit_id <> p_commit OR p_actions IS NULL THEN
RAISE EXCEPTION 'invalid cellular resolution request' USING ERRCODE = '22023';
END IF;
PERFORM evolution.check_cellular_action_block(p_actions, c.begin_tick, c.end_tick);
SELECT p.actions INTO old_actions FROM evolution.cellular_publications p
WHERE p.commit_id = p_commit;
IF EXISTS (SELECT 1 FROM evolution.region_commits x WHERE x.commit_id = p_commit)
AND (old_actions IS NULL OR old_actions <> p_actions) THEN
RETURN QUERY SELECT 'conflict'::text, NULL::evolution.u64, NULL::evolution.u64,
NULL::uuid, NULL::text, NULL::evolution.u64;
RETURN;
END IF;
RETURN QUERY SELECT * FROM evolution.resolve_region_commit(p_world, p_region, p_commit,
p_manifest, p_decisions);
END $$;
REVOKE ALL ON FUNCTION evolution.check_cellular_action_block(bytea,numeric,numeric),
evolution.publish_cellular_checkpoint(bytea,bytea,bytea),
evolution.resolve_cellular_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea)
FROM PUBLIC;
GRANT EXECUTE ON FUNCTION evolution.publish_cellular_checkpoint(bytea,bytea,bytea),
evolution.resolve_cellular_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea)
TO :"runtime_role";
INSERT INTO evolution.schema_migrations(version, sha256) VALUES (20, :'migration_sha_20');
+26 -2
View File
@@ -92,28 +92,36 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|| ',15:' || :'migration_sha_15' || ',16:' || :'migration_sha_16' AS at_v16,
:'history' = '1:' || :'migration_sha' || ',2:' || :'migration_sha_2' || ',3:' || :'migration_sha_3' || ',4:' || :'migration_sha_4' || ',5:' || :'migration_sha_5' || ',6:' || :'migration_sha_6' || ',7:' || :'migration_sha_7' || ',8:' || :'migration_sha_8' || ',9:' || :'migration_sha_9' || ',10:' || :'migration_sha_10' || ',11:' || :'migration_sha_11' || ',12:' || :'migration_sha_12' || ',13:' || :'migration_sha_13' || ',14:' || :'migration_sha_14' || ',15:' || :'migration_sha_15' || ',16:' || :'migration_sha_16' || ',17:' || :'migration_sha_17' AS at_v17,
:'history' = '1:' || :'migration_sha' || ',2:' || :'migration_sha_2' || ',3:' || :'migration_sha_3' || ',4:' || :'migration_sha_4' || ',5:' || :'migration_sha_5' || ',6:' || :'migration_sha_6' || ',7:' || :'migration_sha_7' || ',8:' || :'migration_sha_8' || ',9:' || :'migration_sha_9' || ',10:' || :'migration_sha_10' || ',11:' || :'migration_sha_11' || ',12:' || :'migration_sha_12' || ',13:' || :'migration_sha_13' || ',14:' || :'migration_sha_14' || ',15:' || :'migration_sha_15' || ',16:' || :'migration_sha_16' || ',17:' || :'migration_sha_17' || ',18:' || :'migration_sha_18' AS at_v18,
:'history' = '1:' || :'migration_sha' || ',2:' || :'migration_sha_2' || ',3:' || :'migration_sha_3' || ',4:' || :'migration_sha_4' || ',5:' || :'migration_sha_5' || ',6:' || :'migration_sha_6' || ',7:' || :'migration_sha_7' || ',8:' || :'migration_sha_8' || ',9:' || :'migration_sha_9' || ',10:' || :'migration_sha_10' || ',11:' || :'migration_sha_11' || ',12:' || :'migration_sha_12' || ',13:' || :'migration_sha_13' || ',14:' || :'migration_sha_14' || ',15:' || :'migration_sha_15' || ',16:' || :'migration_sha_16' || ',17:' || :'migration_sha_17' || ',18:' || :'migration_sha_18' || ',19:' || :'migration_sha_19' AS at_v19 \gset
\if :at_v19
:'history' = '1:' || :'migration_sha' || ',2:' || :'migration_sha_2' || ',3:' || :'migration_sha_3' || ',4:' || :'migration_sha_4' || ',5:' || :'migration_sha_5' || ',6:' || :'migration_sha_6' || ',7:' || :'migration_sha_7' || ',8:' || :'migration_sha_8' || ',9:' || :'migration_sha_9' || ',10:' || :'migration_sha_10' || ',11:' || :'migration_sha_11' || ',12:' || :'migration_sha_12' || ',13:' || :'migration_sha_13' || ',14:' || :'migration_sha_14' || ',15:' || :'migration_sha_15' || ',16:' || :'migration_sha_16' || ',17:' || :'migration_sha_17' || ',18:' || :'migration_sha_18' || ',19:' || :'migration_sha_19' AS at_v19,
:'history' = '1:' || :'migration_sha' || ',2:' || :'migration_sha_2' || ',3:' || :'migration_sha_3' || ',4:' || :'migration_sha_4' || ',5:' || :'migration_sha_5' || ',6:' || :'migration_sha_6' || ',7:' || :'migration_sha_7' || ',8:' || :'migration_sha_8' || ',9:' || :'migration_sha_9' || ',10:' || :'migration_sha_10' || ',11:' || :'migration_sha_11' || ',12:' || :'migration_sha_12' || ',13:' || :'migration_sha_13' || ',14:' || :'migration_sha_14' || ',15:' || :'migration_sha_15' || ',16:' || :'migration_sha_16' || ',17:' || :'migration_sha_17' || ',18:' || :'migration_sha_18' || ',19:' || :'migration_sha_19' || ',20:' || :'migration_sha_20' AS at_v20 \gset
\if :at_v20
\elif :at_v19
\ir 0020_cellular_publication.sql
\elif :at_v18
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v17
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v16
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v15
\ir 0016_primitive_publication.sql
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v14
\ir 0015_life_reservations.sql
\ir 0016_primitive_publication.sql
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v13
\ir 0014_probe_overdue.sql
\ir 0015_life_reservations.sql
@@ -121,6 +129,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v12
\ir 0013_probe_incoming.sql
\ir 0014_probe_overdue.sql
@@ -129,6 +138,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v11
\ir 0012_probe_handoff.sql
\ir 0013_probe_incoming.sql
@@ -138,6 +148,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v10
\ir 0011_region_actions.sql
\ir 0012_probe_handoff.sql
@@ -148,6 +159,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v9
\ir 0010_account_control.sql
\ir 0011_region_actions.sql
@@ -159,6 +171,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v8
\ir 0009_serialized_authority.sql
\ir 0010_account_control.sql
@@ -171,6 +184,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v7
\ir 0008_upgrade_barrier.sql
\ir 0009_serialized_authority.sql
@@ -184,6 +198,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v6
\ir 0007_region_clones.sql
\ir 0008_upgrade_barrier.sql
@@ -198,6 +213,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v5
\ir 0006_commit_lookup.sql
\ir 0007_region_clones.sql
@@ -213,6 +229,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v4
\ir pre_v5_guard.sql
\ir 0005_batch_decisions.sql
@@ -230,6 +247,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v3
\ir 0004_lineage_profile.sql
\ir pre_v5_guard.sql
@@ -248,6 +266,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v2
\ir 0003_region_checkpoints.sql
\ir 0004_lineage_profile.sql
@@ -267,6 +286,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\elif :at_v1
\ir 0002_region_fencing.sql
\ir 0003_region_checkpoints.sql
@@ -287,6 +307,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.sql
\else
\echo 'Unknown or changed migration history'
DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$;
@@ -312,6 +333,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
\ir 0017_life_request_outcomes.sql
\ir 0018_cellular_profile_admission.sql
\ir 0019_cellular_action_records.sql
\ir 0020_cellular_publication.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
@@ -356,6 +378,8 @@ BEGIN
('evolution.resolve_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea)'::regprocedure::oid),
('evolution.find_region_action(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,evolution.u64)'::regprocedure::oid),
('evolution.find_region_action_record(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,evolution.u64)'::regprocedure::oid),
('evolution.publish_cellular_checkpoint(bytea,bytea,bytea)'::regprocedure::oid),
('evolution.resolve_cellular_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea)'::regprocedure::oid),
('evolution.open_probe(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,bigint,bigint,bigint,evolution.u64)'::regprocedure::oid),
('evolution.save_probe(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,evolution.u64,bigint,bigint,bigint)'::regprocedure::oid),
('evolution.prepare_probe_transfer(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,evolution.u64,uuid,evolution.u64,bigint,bigint,bigint)'::regprocedure::oid),
+20 -1
View File
@@ -185,6 +185,7 @@ void upgrade_across_migration_and_barrier() {
" -v migration_sha_17=$(s 0017_life_request_outcomes.sql)"
" -v migration_sha_18=$(s 0018_cellular_profile_admission.sql)"
" -v migration_sha_19=$(s 0019_cellular_action_records.sql)"
" -v migration_sha_20=$(s 0020_cellular_publication.sql)"
" -v runtime_role=evo_runtime_test -f migrations/apply.sql"
" > /dev/null 2>&1") != 0);
CHECK(history(*owner_db) == "1,2,3,4,5,6,7");
@@ -200,7 +201,7 @@ void upgrade_across_migration_and_barrier() {
CHECK(shell("PGDATABASE=" + database +
" EVO_PG_RUNTIME_ROLE=evo_runtime_test bash \"$EVO_SOURCE_ROOT/"
"tools/migrate-postgres.sh\" > /dev/null") == 0);
CHECK(history(*owner_db) == "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19");
CHECK(history(*owner_db) == "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20");
CHECK(scalar(*owner_db, "SELECT count(*) FROM information_schema.columns WHERE "
"table_schema = 'evolution' AND table_name = 'region_actions' AND "
"column_name IN ('input_bytes', 'result')") == "2");
@@ -214,6 +215,24 @@ void upgrade_across_migration_and_barrier() {
CHECK(scalar(*owner_db,
"SELECT evolution.valid_cellular_action_input(decode(repeat('00', 24), "
"'hex'), 1)::text") == "false");
CHECK(scalar(*owner_db,
"SELECT evolution.check_cellular_action_block(decode(repeat('01', 16) || "
"'0100000000000000' || '0100000000000000' || repeat('00', 16), 'hex'), "
"0, 1)::text") == "1");
CHECK(scalar(*owner_db,
"SELECT (to_regprocedure('evolution.publish_cellular_checkpoint(bytea,bytea,bytea)') "
"IS NOT NULL)::text") == "true");
CHECK(scalar(*owner_db,
"SELECT has_function_privilege('evo_runtime_login', "
"'evolution.publish_cellular_checkpoint(bytea,bytea,bytea)', 'EXECUTE')::text") ==
"true");
CHECK(scalar(*owner_db,
"SELECT has_table_privilege('evo_runtime_login', "
"'evolution.cellular_publications', 'INSERT')::text") == "false");
CHECK(scalar(*owner_db,
"SELECT has_function_privilege('evo_runtime_login', "
"'evolution.publish_region_checkpoint_core(bytea,bytea)', 'EXECUTE')::text") ==
"false");
CHECK(renew_region_lease(*runtime, r.key, *lease, 20000ms, 5s));
confirm(publish_next(20)); // 41..60, now v8.
CHECK(head.head.end_tick == 60);
+5 -5
View File
@@ -69,7 +69,7 @@ PGDATABASE=upgrade_path psql -X -v ON_ERROR_STOP=1 -1 -v "migration_sha=$v1_sha"
-f "$root/migrations/0001_region_bootstrap.sql" > /dev/null
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',') FROM evolution.schema_migrations")" = 1
PGDATABASE=upgrade_path bash "$root/tools/migrate-postgres.sh"
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
# v2 heads have no payload binding: v2->v3 fails closed and leaves history at v2.
v2_sha="$(sha256sum "$root/migrations/0002_region_fencing.sql")"
v2_sha="${v2_sha%% *}"
@@ -90,7 +90,7 @@ PGDATABASE=v3_commits psql -X -v ON_ERROR_STOP=1 \
-c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \
-c "SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '01000000' || '01000000' || '0100000000000000' || '0100000000000000' || '0900000000000000' || repeat('11', 16) || repeat('00', 8) || repeat('00', 16) || repeat('00', 32) || repeat('00', 16) || repeat('00', 16) || repeat('00', 8) || '50c3000000000000' || '020000000200000001000000010000000100000001000000010000000100000001000000' || repeat('b1', 32) || '00000000' || '00000000' || '01000000' || '6400000000000000' || repeat('a0', 32), 'hex'))" > /dev/null
PGDATABASE=v3_commits bash "$root/tools/migrate-postgres.sh"
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 19:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 20:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) FROM evolution.region_commits")" = 1
# Review P1: a v4 database holding a published (possibly terminal) checkpoint has
# no durable decisions for it. The v5 upgrade must refuse before changing anything.
@@ -144,7 +144,7 @@ PGDATABASE=v6_populated psql -X -v ON_ERROR_STOP=1 \
-c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \
-c "SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '02000000' || '01000000' || '0100000000000000' || '0100000000000000' || '0900000000000000' || repeat('11', 16) || repeat('00', 8) || repeat('00', 16) || repeat('00', 32) || repeat('00', 16) || repeat('00', 16) || repeat('00', 8) || '50c3000000000000' || '020000000200000001000000010000000100000001000000010000000100000001000000' || repeat('b1', 32) || '00000000' || '00000000' || '01000000' || '6400000000000000' || repeat('a0', 32) || repeat('00', 80), 'hex'))" > /dev/null
PGDATABASE=v6_populated bash "$root/tools/migrate-postgres.sh"
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT count(*) FROM evolution.region_commits c, LATERAL evolution.parse_checkpoint_manifest(c.manifest) m WHERE m.commit_sequence = 0 AND m.predecessor_commit IS NULL")" = 1
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(conname, ',') FROM pg_constraint WHERE conrelid = 'evolution.region_heads'::regclass AND contype = 'c' AND pg_get_constraintdef(oid) LIKE '%end_tick%'")" = region_heads_published_tick
# Inherited privileges bypass fencing, so every migrate run audits effective rights.
@@ -190,9 +190,9 @@ expect_audit_failure 'GRANT SELECT ON evolution.account_controls TO evo_runtime_
expect_audit_failure 'REVOKE EXECUTE ON FUNCTION evolution.claim_account_control(evolution.u64, evolution.u64, uuid, evolution.u64, uuid, evolution.u64, evolution.u64, integer) FROM evo_runtime_test' 'GRANT EXECUTE ON FUNCTION evolution.claim_account_control(evolution.u64, evolution.u64, uuid, evolution.u64, uuid, evolution.u64, evolution.u64, integer) TO evo_runtime_test'
bash "$root/tools/migrate-postgres.sh" # Restored configuration passes the audit again.
# Unknown future versions and checksum drift must not be repaired silently.
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=20 WHERE version=19'
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=21 WHERE version=20'
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=19 WHERE version=20"
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=20 WHERE version=21"
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=14"
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=13"
+1 -1
View File
@@ -61,7 +61,7 @@ SQL
[ "$code" != 0 ] && grep -q 'division by zero' "$work/migration.log" || fail "the rehearsal migration did not fail"
[ "$(q -c "SELECT count(*) FROM information_schema.columns WHERE table_name = 'region_commits' AND column_name = 'rehearsal_column'")" = 0 ] ||
fail "the failed migration left a column"
[ "$(q -c 'SELECT max(version) FROM evolution.schema_migrations')" = 19 ] || fail "schema version moved"
[ "$(q -c 'SELECT max(version) FROM evolution.schema_migrations')" = 20 ] || fail "schema version moved"
wait_ack "$work/b1.log" $((before + 40)) || fail "b1 did not resume after the failed migration"
kill -0 "$b1_pid" 2> /dev/null || fail "b1 exited during the failed migration"
bash "$root/tools/migrate-postgres.sh" > /dev/null || fail "migrate after the failure"
+3
View File
@@ -50,6 +50,8 @@ digest_18="$(sha256sum "$root/migrations/0018_cellular_profile_admission.sql")"
digest_18="${digest_18%% *}"
digest_19="$(sha256sum "$root/migrations/0019_cellular_action_records.sql")"
digest_19="${digest_19%% *}"
digest_20="$(sha256sum "$root/migrations/0020_cellular_publication.sql")"
digest_20="${digest_20%% *}"
psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \
--set="migration_sha_2=$digest_2" --set="migration_sha_3=$digest_3" \
--set="migration_sha_4=$digest_4" --set="migration_sha_5=$digest_5" \
@@ -62,5 +64,6 @@ psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \
--set="migration_sha_17=$digest_17" \
--set="migration_sha_18=$digest_18" \
--set="migration_sha_19=$digest_19" \
--set="migration_sha_20=$digest_20" \
--set="runtime_role=$runtime_role" \
--file="$root/migrations/apply.sql"