From 703758c45c848920128d62100a94f342e58bd3d8 Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 11 Oct 2026 21:28:21 -0400 Subject: [PATCH] Allow cellular births to bind published commits --- .../0114-cellular-first-life-publication.md | 8 +++ docs/engineering/VALIDATION.md | 11 ++++ ...030_cellular_birth_publication_binding.sql | 50 +++++++++++++++++++ migrations/apply.sql | 16 ++++-- tests/region_migration_tests.cpp | 17 ++++++- tools/migrate-postgres.sh | 3 ++ 6 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 migrations/0030_cellular_birth_publication_binding.sql diff --git a/docs/adr/0114-cellular-first-life-publication.md b/docs/adr/0114-cellular-first-life-publication.md index d289c19..24fc1cc 100644 --- a/docs/adr/0114-cellular-first-life-publication.md +++ b/docs/adr/0114-cellular-first-life-publication.md @@ -93,6 +93,14 @@ Recovery compares those bindings to the tail trace. The previous action-only profile-4 SQL entry point is revoked from the runtime role, so deployments must run a publisher version that supplies the trace before cellular commits resume. +The shared life-binding table accepts commits from either primitive profile 3 +or cellular profile 4. Its commit foreign key is deferred to the common region +commit record, and a deferred constraint trigger requires matching, private +profile-specific publication evidence and an un-rejected reservation in the +same region. This lets the cellular publisher insert its binding before its +checkpoint core inserts publication evidence while preserving transaction +atomicity. + ## Consequences `evo-world-clone` creates empty profile-4 genesis only. The M11.3e gate remains diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index f54c1b9..6169bf3 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -7026,3 +7026,14 @@ CI run #311 passed client, deploy, ECS, network and TSan, and compiled the Postg CI run #312 passed client, deploy, ECS and network, but the PostgreSQL-enabled test build found that the new `checked_value` helper only accepted `std::optional`, while the SHA-256 helper returns `std::expected`. The test now provides the same explicit engagement check for `std::expected`; run #312 did not reach PostgreSQL tools or server-image/Harbor publication. CI run #313 passed client, deploy, ECS, network and TSan; both PostgreSQL compilation configurations completed. The PostgreSQL integration run then failed its final runtime-role audit because the cellular profile-migration publisher and lookup are explicitly granted to the runtime role but were missing from the audit's fenced-function set. Those two lease-fenced functions are now listed, and the online migration test now expects the current schema version 29 after upgrading its v7 fixture. PostgreSQL tools and Harbor publication did not start. + +CI run #314 passed client, deploy, ECS, network, TSan, PostgreSQL compilation, +and the runtime-role audit, then failed the first cellular birth publication +integration assertion. The shared life-binding table still had its original +foreign key to primitive-only publication evidence, so a profile-4 birth could +not reference its cellular publication. Schema migration 30 retargets that +foreign key to the common region commit and adds a deferred guard requiring +profile-specific publication evidence, matching region and a live reservation. +The migration test checks the deferred constraints; the cellular publication +integration exercises an actual birth. Run #314 did not start the PostgreSQL +tools or Harbor image jobs; CI validation of migration 30 is pending. diff --git a/migrations/0030_cellular_birth_publication_binding.sql b/migrations/0030_cellular_birth_publication_binding.sql new file mode 100644 index 0000000..e20450d --- /dev/null +++ b/migrations/0030_cellular_birth_publication_binding.sql @@ -0,0 +1,50 @@ +-- M11.4c playtest gate: player-life bindings may belong to primitive or +-- cellular publications. Both still reference one committed region head. +ALTER TABLE evolution.primitive_life_bindings + DROP CONSTRAINT primitive_life_bindings_commit_id_fkey; +ALTER TABLE evolution.primitive_life_bindings + ADD CONSTRAINT primitive_life_bindings_commit_id_fkey + FOREIGN KEY (commit_id) REFERENCES evolution.region_commits(commit_id) + DEFERRABLE INITIALLY DEFERRED; + +-- The binding is inserted before the cellular publication core creates its +-- commit evidence, so validate the polymorphic publication link at transaction +-- end. Profile-specific publishers still validate the trace and birth record. +CREATE FUNCTION evolution.check_life_binding_publication() +RETURNS trigger LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$ +DECLARE + profile integer; + valid_publication boolean; +BEGIN + SELECT evolution.manifest_uint(c.manifest, 12, 4) INTO profile + FROM evolution.region_commits c + JOIN evolution.life_reservations r ON r.world_id = NEW.world_id + AND r.account_id = NEW.account_id AND r.request_id = NEW.request_id + AND r.region_id = c.region_id AND r.rejection = 0 AND r.rules = 1 + WHERE c.commit_id = NEW.commit_id AND c.world_id = NEW.world_id + AND c.commit_sequence > 0 + AND NEW.born = evolution.manifest_uint(c.manifest, 120, 8); + IF NOT FOUND THEN + RAISE EXCEPTION 'life binding commit or reservation missing' USING ERRCODE = 'EVL06'; + END IF; + IF profile = 3 THEN + SELECT EXISTS (SELECT 1 FROM evolution.primitive_publications p + WHERE p.commit_id = NEW.commit_id) INTO valid_publication; + ELSIF profile = 4 THEN + SELECT EXISTS (SELECT 1 FROM evolution.cellular_publications p + WHERE p.commit_id = NEW.commit_id) INTO valid_publication; + ELSE + valid_publication := false; + END IF; + IF NOT valid_publication THEN + RAISE EXCEPTION 'life binding publication evidence missing' USING ERRCODE = 'EVL06'; + END IF; + RETURN NULL; +END $$; +REVOKE ALL ON FUNCTION evolution.check_life_binding_publication() FROM PUBLIC; +CREATE CONSTRAINT TRIGGER life_binding_publication_evidence + AFTER INSERT ON evolution.primitive_life_bindings + DEFERRABLE INITIALLY DEFERRED FOR EACH ROW + EXECUTE FUNCTION evolution.check_life_binding_publication(); + +INSERT INTO evolution.schema_migrations(version, sha256) VALUES (30, :'migration_sha_30'); diff --git a/migrations/apply.sql b/migrations/apply.sql index bff7ed8..c43646b 100644 --- a/migrations/apply.sql +++ b/migrations/apply.sql @@ -103,7 +103,9 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution') SELECT right(:'history', length(',27:' || :'migration_sha_27')) = ',27:' || :'migration_sha_27' AS at_v27 \gset SELECT right(:'history', length(',28:' || :'migration_sha_28')) = ',28:' || :'migration_sha_28' AS at_v28 \gset SELECT right(:'history', length(',29:' || :'migration_sha_29')) = ',29:' || :'migration_sha_29' AS at_v29 \gset - \if :at_v29 + SELECT right(:'history', length(',30:' || :'migration_sha_30')) = ',30:' || :'migration_sha_30' AS at_v30 \gset + \if :at_v30 + \elif :at_v29 \elif :at_v28 \ir 0029_cellular_mutation_reservations.sql \elif :at_v27 @@ -453,7 +455,8 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24, coalesce(max(version), 0) = 26 AS at_v26, coalesce(max(version), 0) = 27 AS at_v27, coalesce(max(version), 0) = 28 AS at_v28, - coalesce(max(version), 0) = 29 AS at_v29 + coalesce(max(version), 0) = 29 AS at_v29, + coalesce(max(version), 0) = 30 AS at_v30 FROM evolution.schema_migrations \gset \if :at_v24 \ir 0025_cellular_v2_bundle.sql @@ -461,23 +464,30 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24, \ir 0027_cellular_v3_migration.sql \ir 0028_cellular_v3_trace_bounds.sql \ir 0029_cellular_mutation_reservations.sql + \ir 0030_cellular_birth_publication_binding.sql \elif :at_v25 \ir 0026_cellular_profile_migration.sql \ir 0027_cellular_v3_migration.sql \ir 0028_cellular_v3_trace_bounds.sql \ir 0029_cellular_mutation_reservations.sql + \ir 0030_cellular_birth_publication_binding.sql \elif :at_v26 \ir 0027_cellular_v3_migration.sql \ir 0028_cellular_v3_trace_bounds.sql \ir 0029_cellular_mutation_reservations.sql + \ir 0030_cellular_birth_publication_binding.sql \elif :at_v27 \ir 0028_cellular_v3_trace_bounds.sql \ir 0029_cellular_mutation_reservations.sql + \ir 0030_cellular_birth_publication_binding.sql \elif :at_v28 \ir 0029_cellular_mutation_reservations.sql + \ir 0030_cellular_birth_publication_binding.sql \elif :at_v29 + \ir 0030_cellular_birth_publication_binding.sql +\elif :at_v30 \else - \echo 'Unknown or changed migration history after v29' + \echo 'Unknown or changed migration history after v30' DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$; \endif -- Effective-privilege audit on every run, including no-ops (ADR-0060). Attributes diff --git a/tests/region_migration_tests.cpp b/tests/region_migration_tests.cpp index 0977cbe..4343dd4 100644 --- a/tests/region_migration_tests.cpp +++ b/tests/region_migration_tests.cpp @@ -192,6 +192,10 @@ void upgrade_across_migration_and_barrier() { " -v migration_sha_24=$(s 0024_primitive_life_owner_lookup.sql)" " -v migration_sha_25=$(s 0025_cellular_v2_bundle.sql)" " -v migration_sha_26=$(s 0026_cellular_profile_migration.sql)" + " -v migration_sha_27=$(s 0027_cellular_v3_migration.sql)" + " -v migration_sha_28=$(s 0028_cellular_v3_trace_bounds.sql)" + " -v migration_sha_29=$(s 0029_cellular_mutation_reservations.sql)" + " -v migration_sha_30=$(s 0030_cellular_birth_publication_binding.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"); @@ -208,7 +212,18 @@ void upgrade_across_migration_and_barrier() { " 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,20,21,22,23,24,25,26,27,28,29"); + "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30"); + CHECK(scalar(*owner_db, + "SELECT c.condeferrable AND c.condeferred AND " + "c.confrelid = 'evolution.region_commits'::regclass " + "FROM pg_catalog.pg_constraint c WHERE c.conrelid = " + "'evolution.primitive_life_bindings'::regclass AND " + "c.conname = 'primitive_life_bindings_commit_id_fkey'") == "true"); + CHECK(scalar(*owner_db, + "SELECT t.tgdeferrable AND t.tginitdeferred FROM pg_catalog.pg_trigger t " + "WHERE t.tgrelid = 'evolution.primitive_life_bindings'::regclass AND " + "t.tgname = 'life_binding_publication_evidence' AND NOT t.tgisinternal") == + "true"); CHECK(scalar(*owner_db, "SELECT (to_regprocedure('evolution.primitive_life_owner(" "evolution.u64,evolution.u64,uuid,evolution.u64,uuid)') IS NOT NULL)::text") == diff --git a/tools/migrate-postgres.sh b/tools/migrate-postgres.sh index b55d73c..5d99f7b 100644 --- a/tools/migrate-postgres.sh +++ b/tools/migrate-postgres.sh @@ -70,6 +70,8 @@ digest_28="$(sha256sum "$root/migrations/0028_cellular_v3_trace_bounds.sql")" digest_28="${digest_28%% *}" digest_29="$(sha256sum "$root/migrations/0029_cellular_mutation_reservations.sql")" digest_29="${digest_29%% *}" +digest_30="$(sha256sum "$root/migrations/0030_cellular_birth_publication_binding.sql")" +digest_30="${digest_30%% *}" 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" \ @@ -92,5 +94,6 @@ psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \ --set="migration_sha_27=$digest_27" \ --set="migration_sha_28=$digest_28" \ --set="migration_sha_29=$digest_29" \ + --set="migration_sha_30=$digest_30" \ --set="runtime_role=$runtime_role" \ --file="$root/migrations/apply.sql"