Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(security): split the derivation guard: BEFORE ROW invoker drop as on master, AFTER ROW definer refuses a stored purged row (closes the gated-BEFORE oracle, GBRA-108 option 3)
garrytana5de6bcda688
diff --git a/docs/ENGINES.md b/docs/ENGINES.mdindex 6c5bc9f98d..1b855bb454 100644--- a/docs/ENGINES.md+++ b/docs/ENGINES.md@@ -398,11 +398,14 @@ them, which ran the migrations: they are `SECURITY DEFINER` withunder the writing role's RLS, so a write role with no policy on a ledger saw no purgeand no withdrawal and stored the claim again. Nothing changes for an owner or a rolethat bypasses RLS, and `anon` / `authenticated` gain nothing: EXECUTE on the guards is-revoked from them and from PUBLIC, the three raising guards fire `AFTER ROW` (after RLS-has accepted the row), and the derivation guard fires only when the writing role can-see the page (`gbrain_caller_sees_page`). A scoped write role is now refused where it-was let through, and learns whether content it supplies itself is purged or withdrawn-in a source it can already write; the guards also perform two fixed side effects for+revoked from them and from PUBLIC, and every guard that refuses a write fires `AFTER ROW`,+after RLS has accepted the row. The derivation guard is split: its `BEFORE ROW` half+still runs as the writing role and silently drops a row the role can see a running purge+sweep would delete, as before, and an `AFTER ROW` definer+(`gbrain_refuse_stored_purging_derivation`) refuses such a row that was stored anyway+with `derivation_purge_pending`. A scoped write role with no policy on a ledger is now+refused, with an error, where it was let through, and learns whether content it supplies+itself is purged or withdrawn in a source it can already write; the guards also perform two fixed side effects forit as the owner (expiring the facts its own statement just inserted when they arewithdrawn, and adding its page to a running derivation purge's page list). Every othergbrain function that pins a search_path now ends it with `pg_temp`. Where the migratingdiff --git a/llms-full.txt b/llms-full.txtindex 7c0bf678e6..cd56849eac 100644--- a/llms-full.txt+++ b/llms-full.txt@@ -5844,11 +5844,14 @@ them, which ran the migrations: they are `SECURITY DEFINER` withunder the writing role's RLS, so a write role with no policy on a ledger saw no purgeand no withdrawal and stored the claim again. Nothing changes for an owner or a rolethat bypasses RLS, and `anon` / `authenticated` gain nothing: EXECUTE on the guards is-revoked from them and from PUBLIC, the three raising guards fire `AFTER ROW` (after RLS-has accepted the row), and the derivation guard fires only when the writing role can-see the page (`gbrain_caller_sees_page`). A scoped write role is now refused where it-was let through, and learns whether content it supplies itself is purged or withdrawn-in a source it can already write; the guards also perform two fixed side effects for+revoked from them and from PUBLIC, and every guard that refuses a write fires `AFTER ROW`,+after RLS has accepted the row. The derivation guard is split: its `BEFORE ROW` half+still runs as the writing role and silently drops a row the role can see a running purge+sweep would delete, as before, and an `AFTER ROW` definer+(`gbrain_refuse_stored_purging_derivation`) refuses such a row that was stored anyway+with `derivation_purge_pending`. A scoped write role with no policy on a ledger is now+refused, with an error, where it was let through, and learns whether content it supplies+itself is purged or withdrawn in a source it can already write; the guards also perform two fixed side effects forit as the owner (expiring the facts its own statement just inserted when they arewithdrawn, and adding its page to a running derivation purge's page list). Every othergbrain function that pins a search_path now ends it with `pg_temp`. Where the migratingdiff --git a/src/commands/doctor/checks/guard-functions.ts b/src/commands/doctor/checks/guard-functions.tsindex c7a808b664..ba0b14d0b3 100644--- a/src/commands/doctor/checks/guard-functions.ts+++ b/src/commands/doctor/checks/guard-functions.ts@@ -4,7 +4,7 @@* Postgres only (PGLite has one role). Fails when one of the seven guards is not SECURITY DEFINER with search_path* `pg_catalog, public, pg_temp`, is executable by PUBLIC/anon/authenticated, or is owned by a role that does not* bypass RLS on a table it reads; when a raising guard's trigger still fires BEFORE ROW or the derivation guard's- * trigger lacks its gbrain_caller_sees_page gate; or when any gbrain function's search_path still ends without pg_temp.+ * AFTER ROW check is missing; or when any gbrain function's search_path still ends without pg_temp.* Migration v276 makes every change the migrating role owns and names the rest on stderr: this check carries the SQL* for them, to run as the owning role. Read-only.*/@@ -14,7 +14,7 @@ import type { Check } from '../../doctor.ts';import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';import { checkError } from '../check-fix.ts';import { AFTER_ROW_PURGE_TRIGGERS, DEFINER_GUARDS, GUARD_SEARCH_PATH, LEGACY_SEARCH_PATH_SETTINGS } from '../../../core/guard-definer.ts';-import { DERIVATION_GUARD_GATE_SQL, DERIVATION_GUARD_TRIGGER_SQL } from '../../../core/page-body/schema.ts';+import { DERIVATION_STORED_GUARD_SQL } from '../../../core/page-body/schema.ts';interface GuardRow { fn: string; secdef: boolean; pinned: boolean; executable_by: string[]; owner: string; reads_under_rls: string[] }@@ -49,18 +49,18 @@ export async function guardFunctionProblems(engine: BrainEngine): Promise<{ probfix.push(`-- give ${g.fn}() an owner that bypasses RLS (ALTER FUNCTION ${g.fn}() OWNER TO <owner of the tables>), or ALTER ROLE ${g.owner} BYPASSRLS;`);}}- const triggers = await engine.executeRaw<{ trigger: string; before: boolean; gated: boolean }>(- `SELECT t.tgname AS trigger, (t.tgtype & 2) <> 0 AS before, pg_get_triggerdef(t.oid) LIKE '%gbrain_caller_sees_page(%' AS gated- FROM pg_trigger t WHERE NOT t.tgisinternal AND t.tgname = ANY($1::text[])`,- [[...AFTER_ROW_PURGE_TRIGGERS.map(t => t.trigger), 'page_segment_derivations_refuse_purging']]);+ const triggers = await engine.executeRaw<{ trigger: string; before: boolean }>(+ `SELECT t.tgname AS trigger, (t.tgtype & 2) <> 0 AS before FROM pg_trigger t WHERE NOT t.tgisinternal AND t.tgname = ANY($1::text[])`,+ [[...AFTER_ROW_PURGE_TRIGGERS.map(t => t.trigger), 'page_segment_derivations_refuse_stored_purging']]);for (const t of AFTER_ROW_PURGE_TRIGGERS) {if (!triggers.some(row => row.trigger === t.trigger && row.before)) continue;problems.push(`${t.trigger} on ${t.table} still fires BEFORE ROW`);fix.push(t.sql);}- if (triggers.some(row => row.trigger === 'page_segment_derivations_refuse_purging' && !row.gated)) {- problems.push('page_segment_derivations_refuse_purging has no gbrain_caller_sees_page gate');- fix.push(DERIVATION_GUARD_GATE_SQL, DERIVATION_GUARD_TRIGGER_SQL);+ const [derivations] = await engine.executeRaw<{ present: boolean }>(`SELECT to_regclass('page_segment_derivations') IS NOT NULL AS present`);+ if (derivations?.present && !triggers.some(row => row.trigger === 'page_segment_derivations_refuse_stored_purging' && !row.before)) {+ problems.push('page_segment_derivations has no page_segment_derivations_refuse_stored_purging AFTER ROW check');+ fix.push(DERIVATION_STORED_GUARD_SQL);}const unpinned = await engine.executeRaw<{ sig: string; path: string }>(`SELECT p.oid::regprocedure::text AS sig, substr(c.setting, 13) AS pathdiff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex b3dffd7b72..c249e52a25 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1308,7 +1308,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.464.0', text: 'Security: `gbrain serve --access=read-only` (the `=` form) now sets the read-only ceiling. It passed flag validation before but started the serve with full write access, because only `--access read-only` was read. A config that used the `=` form now gets the read-only tool set and refused mutations it asked for; a repeated `--access` never widens a read-only value, and an invalid value in either form refuses. `--surface=<v>` likewise now sets the serve surface (it was ignored, leaving the full surface), and a repeated `--surface` takes the narrowest value.' },{ since: '0.60.464.0', text: 'A managed sync pass whose process was killed or crashed now reads `resumable` / `pass_interrupted` in `gbrain sync status` (with an `interrupted` block naming the pass and the dead holder) instead of `pass_unfinished`, and a second killed pass reads `blocked` / `pass_abandoned` at once. `gbrain doctor` `managed_sync_blocked` lists both (warn, fail after an hour). A live pass still committing is no longer counted abandoned because its row is old.' },// #7632 guard definers. `since` is stamped at the merge slot.- { since: 'TBD', id: 'guard_triggers_security_definer', text: 'On Postgres, the seven triggers that refuse purged content and keep withdrawn facts withdrawn now read the purge and withdrawal ledgers as the role that owns them (`SECURITY DEFINER`, `search_path = pg_catalog, public, pg_temp`). Before, they read under the writing role\'s row-level security, so a write role with no policy on a ledger saw no purge and no withdrawal: a purged claim, page, take or derivation was stored again and a withdrawn fact was saved active. Owners and roles that bypass RLS see no change, and `anon` and `authenticated` gain nothing: EXECUTE on the guards is revoked from PUBLIC, `anon` and `authenticated`, the guards that refuse a write (`facts_refuse_purged`, `takes_refuse_purged`, `pages_refuse_purged`) now fire AFTER ROW so RLS refuses a row first, and the derivation guard fires only when the writing role can see the page. A scoped write role is now refused where it was let through; it learns whether content it supplies itself is purged or withdrawn in a source it can already write; and the guards perform two fixed side effects for it as the owner (expiring the facts its own statement just inserted when they are withdrawn, and adding its page to a running derivation purge\'s page list). Every other gbrain function that pins a search_path now ends it with `pg_temp` (ALTER only, no body changes). Where the migrating role does not own a guard or its table, the migration names it on stderr and leaves it, and `gbrain doctor` (`guard_functions`) prints the SQL to run as the owner.' },+ { since: 'TBD', id: 'guard_triggers_security_definer', text: 'On Postgres, the seven triggers that refuse purged content and keep withdrawn facts withdrawn now read the purge and withdrawal ledgers as the role that owns them (`SECURITY DEFINER`, `search_path = pg_catalog, public, pg_temp`). Before, they read under the writing role\'s row-level security, so a write role with no policy on a ledger saw no purge and no withdrawal: a purged claim, page, take or derivation was stored again and a withdrawn fact was saved active. Owners, roles that bypass RLS and write roles with policies on the ledgers see no change, and `anon` and `authenticated` gain nothing: EXECUTE on the guards is revoked from PUBLIC, `anon` and `authenticated`, and every guard that refuses a write (`facts_refuse_purged`, `takes_refuse_purged`, `pages_refuse_purged` and the new `page_segment_derivations_refuse_stored_purging`) fires AFTER ROW, so RLS refuses a row before any guard reads a ledger. The derivation guard that silently drops a row a purge sweep would delete still runs as the writing role, BEFORE ROW, as before; a row it cannot see is purged and that RLS accepts is then refused by the new AFTER ROW guard with `derivation_purge_pending`. A scoped write role with no policy on a ledger is now refused, with an error, where it was let through; it learns whether content it supplies itself is purged or withdrawn in a source it can already write; and the guards perform two fixed side effects for it as the owner (expiring the facts its own statement just inserted when they are withdrawn, and adding its page to a running derivation purge\'s page list). Every other gbrain function that pins a search_path now ends it with `pg_temp` (ALTER only, no body changes). Where the migrating role does not own a guard or its table, the migration names it on stderr and leaves it, and `gbrain doctor` (`guard_functions`) prints the SQL to run as the owner.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/guard-definer.ts b/src/core/guard-definer.tsindex 559a25b30d..62a0799b18 100644--- a/src/core/guard-definer.ts+++ b/src/core/guard-definer.ts@@ -17,14 +17,18 @@* trigger fires whatever the EXECUTE grants are.* - A definer never answers before RLS has accepted the row. BEFORE ROW triggers run before RLS WITH CHECK, so a* raising definer BEFORE guard would tell a role with a bare INSERT grant (Supabase anon) purged content from any- * other content. The raising guards fire AFTER ROW; the derivation guard must stay BEFORE (its callers count the- * rows it drops), so its trigger runs only WHEN the writing role can see the page (gbrain_caller_sees_page, an- * invoker helper). gbrain_preserve_fact_withdrawal stays BEFORE: it never raises, and its stamp is visible only on- * a row RLS accepted.+ * other content. The raising guards fire AFTER ROW. The derivation guard is split: its BEFORE ROW half+ * (gbrain_refuse_purging_derivation) stays SECURITY INVOKER and silently drops a row the writer can see a sweep+ * would delete, as before, so its callers still count the rows it drops; its AFTER ROW half+ * (gbrain_refuse_stored_purging_derivation) is the definer and raises derivation_purge_pending for such a row that+ * was stored anyway, which only a writer RLS accepted and that has no policy on the sweep records reaches.+ * gbrain_preserve_fact_withdrawal stays BEFORE: it never raises, and its stamp is visible only on a row RLS accepted.** What a writer gains: the two fixed side effects the definer bodies perform as the owner (expiring the facts its own* statement just inserted, adding its page to a running derivation purge's page list) and knowing whether content it- * supplies is purged or withdrawn in a source it can already write.+ * supplies is purged or withdrawn in a source it can already write. anon and authenticated gain nothing: RLS refuses+ * their row before any definer reads a ledger. A writer RLS accepts but with no policy on a ledger is refused where it+ * used to fail open, with an error (derivation_purge_pending for a derivation) instead of a silent drop.*//** The seven guards and the tables each reads, besides the one its trigger is on. */@@ -34,7 +38,7 @@ export const DEFINER_GUARDS = [{ fn: 'gbrain_refuse_purged_fact', reads: ['fact_purges', 'sources'] },{ fn: 'gbrain_refuse_purged_page', reads: ['page_purges'] },{ fn: 'gbrain_refuse_purged_take', reads: ['take_purges', 'pages'] },- { fn: 'gbrain_refuse_purging_derivation', reads: ['page_segment_derivation_purges', 'pages', 'page_body_manifest'] },+ { fn: 'gbrain_refuse_stored_purging_derivation', reads: ['page_segment_derivation_purges', 'pages', 'page_body_manifest'] },{ fn: 'gbrain_mark_derivation_scope_entry', reads: ['page_segment_derivation_purges', 'page_segment_derivation_purge_pages'] },] as const;diff --git a/src/core/page-body/schema.ts b/src/core/page-body/schema.tsindex 51cc8dec07..c37fd2d2c7 100644--- a/src/core/page-body/schema.ts+++ b/src/core/page-body/schema.ts@@ -239,17 +239,29 @@ export function derivationScopeLockSql(sourceId: string): string {return `hashtextextended('gbrain:derivation-scope:' || ${sourceId}, 0)`;}-/** Whether the calling role can see a page, under its own row-level security: the derivation guard's trigger gate. */-export const DERIVATION_GUARD_GATE_SQL = `CREATE OR REPLACE FUNCTION gbrain_caller_sees_page(page INTEGER) RETURNS boolean LANGUAGE sql STABLE SECURITY INVOKER- SET search_path = ${GUARD_SEARCH_PATH} AS $func$ SELECT EXISTS (SELECT 1 FROM pages WHERE id = page) $func$;`;-/**- * The derivation guard stays BEFORE (it drops the row and its callers count stored rows), so its trigger fires only- * when the writer can see the page: the definer then never answers a role RLS will refuse.+ * The derivation guard's AFTER ROW half (#7632): raises derivation_purge_pending for a stored row that a fact purge's+ * sweep would delete. The BEFORE ROW half (gbrain_refuse_purging_derivation) runs as the writer and drops such a row+ * silently, so this one fires only for a row that passed it unseen and that RLS then accepted: a writer with no policy+ * on the sweep records. It reads them as its owner, so that writer is refused instead of storing the row; a role RLS+ * refuses never reaches it, so it learns nothing about a sweep.*/-export const DERIVATION_GUARD_TRIGGER_SQL = `DROP TRIGGER IF EXISTS page_segment_derivations_refuse_purging ON page_segment_derivations;-CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON page_segment_derivations- FOR EACH ROW WHEN (gbrain_caller_sees_page(NEW.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation();`;+export const DERIVATION_STORED_GUARD_SQL = `CREATE OR REPLACE FUNCTION gbrain_refuse_stored_purging_derivation() RETURNS trigger SECURITY DEFINER SET search_path = ${GUARD_SEARCH_PATH} AS $func$+BEGIN+ IF EXISTS (SELECT 1 FROM page_segment_derivation_purges x JOIN pages p ON p.source_id = x.source_id+ WHERE p.id = NEW.page_id AND ${derivationSweepScopeSql('NEW', 'p', 'x.page_ids')}+ AND ${derivationHoldsClaimSql('NEW', 'x.needles', 'x.patterns')}) THEN+ RAISE EXCEPTION USING ERRCODE = 'P0001',+ MESSAGE = 'derivation_purge_pending: a fact purge''s sweep of stored derivation results is still running and this row holds its claim',+ DETAIL = json_build_object('table', 'page_segment_derivations')::text;+ END IF;+ RETURN NULL;+END+$func$ LANGUAGE plpgsql;+${revokeExecuteSql('gbrain_refuse_stored_purging_derivation')}+DROP TRIGGER IF EXISTS page_segment_derivations_refuse_stored_purging ON page_segment_derivations;+CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON page_segment_derivations+ FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation();`;/*** Per-segment derivation watermarks (migration v273): one row per page, pipeline and manifest occurrence, recording@@ -271,9 +283,10 @@ CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE O* before the purge committed is refused by its own generation guard instead. A row can also enter the scope without a* write, when its occurrence is retired or its page soft-deleted: the triggers on page_body_manifest and pages note the* page in page_segment_derivation_purge_pages for every sweep of the source, and the sweep checks those pages again- * before it ends. Both trigger functions read the sweep records as their owner (SECURITY DEFINER, ../guard-definer.ts),- * so a writer without a policy on them still meets the guard; the dropping trigger fires only when the writer can see- * the page (gbrain_caller_sees_page runs as the writer), so a role RLS refuses learns nothing about a sweep.+ * before it ends. The dropping trigger reads the sweep records as the writer, as RLS lets it; a row it passes unseen+ * that RLS accepts meets DERIVATION_STORED_GUARD_SQL, which reads them as its owner and refuses the write+ * (derivation_purge_pending). The scope-entry trigger reads and notes them as its owner (SECURITY DEFINER,+ * ../guard-definer.ts). A role RLS refuses meets neither definer, so it learns nothing about a sweep.** PR 4 (Wave B incremental derivation, transcripts): page_derivation_spend is the per-page lifetime spend ledger of each* paid derivation family (`facts`, `synopsis`; page-spend.ts), each capped by `derive.max_usd_per_page` on its own,@@ -355,8 +368,7 @@ CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON page_bDROP TRIGGER IF EXISTS pages_derivation_scope_delete ON pages;CREATE TRIGGER pages_derivation_scope_delete AFTER UPDATE OF deleted_at ON pagesFOR EACH ROW WHEN (OLD.deleted_at IS NULL AND NEW.deleted_at IS NOT NULL) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry();-${DERIVATION_GUARD_GATE_SQL}-CREATE OR REPLACE FUNCTION gbrain_refuse_purging_derivation() RETURNS trigger SECURITY DEFINER SET search_path = ${GUARD_SEARCH_PATH} AS $func$+CREATE OR REPLACE FUNCTION gbrain_refuse_purging_derivation() RETURNS trigger SET search_path = pg_catalog, public AS $func$BEGINIF EXISTS (SELECT 1 FROM page_segment_derivation_purges x JOIN pages p ON p.source_id = x.source_idWHERE p.id = NEW.page_id AND ${derivationSweepScopeSql('NEW', 'p', 'x.page_ids')}@@ -366,8 +378,10 @@ BEGINRETURN NEW;END$func$ LANGUAGE plpgsql;-${revokeExecuteSql('gbrain_refuse_purging_derivation')}-${DERIVATION_GUARD_TRIGGER_SQL}`;+DROP TRIGGER IF EXISTS page_segment_derivations_refuse_purging ON page_segment_derivations;+CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON page_segment_derivations+ FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation();+${DERIVATION_STORED_GUARD_SQL}`;/*** The segment tables hold page text (`page_segment_texts`, `page_body_staging_parts`) or a page's shape anddiff --git a/src/core/pglite-schema.generated.ts b/src/core/pglite-schema.generated.tsindex c07370db1b..0b5d9ff4e1 100644--- a/src/core/pglite-schema.generated.ts+++ b/src/core/pglite-schema.generated.ts@@ -1547,9 +1547,7 @@ CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON page_bDROP TRIGGER IF EXISTS pages_derivation_scope_delete ON pages;CREATE TRIGGER pages_derivation_scope_delete AFTER UPDATE OF deleted_at ON pagesFOR EACH ROW WHEN (OLD.deleted_at IS NULL AND NEW.deleted_at IS NOT NULL) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry();-CREATE OR REPLACE FUNCTION gbrain_caller_sees_page(page INTEGER) RETURNS boolean LANGUAGE sql STABLE SECURITY INVOKER- SET search_path = pg_catalog, public, pg_temp AS \$func\$ SELECT EXISTS (SELECT 1 FROM pages WHERE id = page) \$func\$;-CREATE OR REPLACE FUNCTION gbrain_refuse_purging_derivation() RETURNS trigger SECURITY DEFINER SET search_path = pg_catalog, public, pg_temp AS \$func\$+CREATE OR REPLACE FUNCTION gbrain_refuse_purging_derivation() RETURNS trigger SET search_path = pg_catalog, public AS \$func\$BEGINIF EXISTS (SELECT 1 FROM page_segment_derivation_purges x JOIN pages p ON p.source_id = x.source_idWHERE p.id = NEW.page_id AND (NEW.page_id = ANY(x.page_ids::int[]) OR p.deleted_at IS NOT NULL OR NOT EXISTS (SELECT 1 FROM page_body_manifest m@@ -1564,14 +1562,34 @@ BEGINRETURN NEW;END\$func\$ LANGUAGE plpgsql;-REVOKE EXECUTE ON FUNCTION gbrain_refuse_purging_derivation() FROM PUBLIC;-DO \$revoke\$ BEGIN- IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'anon') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_purging_derivation() FROM anon; END IF;- IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'authenticated') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_purging_derivation() FROM authenticated; END IF;-END \$revoke\$;DROP TRIGGER IF EXISTS page_segment_derivations_refuse_purging ON page_segment_derivations;CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON page_segment_derivations- FOR EACH ROW WHEN (gbrain_caller_sees_page(NEW.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation();+ FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation();+CREATE OR REPLACE FUNCTION gbrain_refuse_stored_purging_derivation() RETURNS trigger SECURITY DEFINER SET search_path = pg_catalog, public, pg_temp AS \$func\$+BEGIN+ IF EXISTS (SELECT 1 FROM page_segment_derivation_purges x JOIN pages p ON p.source_id = x.source_id+ WHERE p.id = NEW.page_id AND (NEW.page_id = ANY(x.page_ids::int[]) OR p.deleted_at IS NOT NULL OR NOT EXISTS (SELECT 1 FROM page_body_manifest m+ WHERE m.page_id = NEW.page_id AND m.occurrence_id = NEW.occurrence_id AND m.gen_to IS NULL AND m.staging_id IS NULL AND m.sha256 = NEW.segment_sha256))+ AND CASE WHEN replace(translate(lower(COALESCE(NEW.output::text, '') || ' ' || COALESCE(NEW.receipt::text, '')), 'ς', 'σ'), 'i̇', 'i') LIKE ANY (x.patterns::text[]) THEN EXISTS (SELECT 1 FROM (VALUES (NEW.output), (NEW.receipt)) doc(j),+ LATERAL (SELECT jsonb_path_query(doc.j, 'strict \$.** ? (@.type() == "string")') #>> '{}' AS t+ UNION ALL SELECT jsonb_path_query(doc.j, 'strict \$.** ? (@.type() == "object").keyvalue().key') #>> '{}') s+ WHERE CASE WHEN replace(translate(lower(s.t), 'ς', 'σ'), 'i̇', 'i') LIKE ANY (x.patterns::text[]) THEN EXISTS (SELECT 1 FROM unnest(x.needles::text[]) k(n)+ WHERE strpos(' ' || replace(translate(gbrain_fact_normalize(s.t), 'ς', 'σ'), 'i̇', 'i') || ' ', k.n) > 0) ELSE false END) ELSE false END) THEN+ RAISE EXCEPTION USING ERRCODE = 'P0001',+ MESSAGE = 'derivation_purge_pending: a fact purge''s sweep of stored derivation results is still running and this row holds its claim',+ DETAIL = json_build_object('table', 'page_segment_derivations')::text;+ END IF;+ RETURN NULL;+END+\$func\$ LANGUAGE plpgsql;+REVOKE EXECUTE ON FUNCTION gbrain_refuse_stored_purging_derivation() FROM PUBLIC;+DO \$revoke\$ BEGIN+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'anon') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_stored_purging_derivation() FROM anon; END IF;+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'authenticated') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_stored_purging_derivation() FROM authenticated; END IF;+END \$revoke\$;+DROP TRIGGER IF EXISTS page_segment_derivations_refuse_stored_purging ON page_segment_derivations;+CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON page_segment_derivations+ FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation();diff --git a/src/core/schema-embedded.generated.ts b/src/core/schema-embedded.generated.tsindex c0d8d7a53d..48da63565e 100644--- a/src/core/schema-embedded.generated.ts+++ b/src/core/schema-embedded.generated.ts@@ -2293,9 +2293,7 @@ CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON page_bDROP TRIGGER IF EXISTS pages_derivation_scope_delete ON pages;CREATE TRIGGER pages_derivation_scope_delete AFTER UPDATE OF deleted_at ON pagesFOR EACH ROW WHEN (OLD.deleted_at IS NULL AND NEW.deleted_at IS NOT NULL) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry();-CREATE OR REPLACE FUNCTION gbrain_caller_sees_page(page INTEGER) RETURNS boolean LANGUAGE sql STABLE SECURITY INVOKER- SET search_path = pg_catalog, public, pg_temp AS \$func\$ SELECT EXISTS (SELECT 1 FROM pages WHERE id = page) \$func\$;-CREATE OR REPLACE FUNCTION gbrain_refuse_purging_derivation() RETURNS trigger SECURITY DEFINER SET search_path = pg_catalog, public, pg_temp AS \$func\$+CREATE OR REPLACE FUNCTION gbrain_refuse_purging_derivation() RETURNS trigger SET search_path = pg_catalog, public AS \$func\$BEGINIF EXISTS (SELECT 1 FROM page_segment_derivation_purges x JOIN pages p ON p.source_id = x.source_idWHERE p.id = NEW.page_id AND (NEW.page_id = ANY(x.page_ids::int[]) OR p.deleted_at IS NOT NULL OR NOT EXISTS (SELECT 1 FROM page_body_manifest m@@ -2310,14 +2308,34 @@ BEGINRETURN NEW;END\$func\$ LANGUAGE plpgsql;-REVOKE EXECUTE ON FUNCTION gbrain_refuse_purging_derivation() FROM PUBLIC;-DO \$revoke\$ BEGIN- IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'anon') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_purging_derivation() FROM anon; END IF;- IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'authenticated') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_purging_derivation() FROM authenticated; END IF;-END \$revoke\$;DROP TRIGGER IF EXISTS page_segment_derivations_refuse_purging ON page_segment_derivations;CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON page_segment_derivations- FOR EACH ROW WHEN (gbrain_caller_sees_page(NEW.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation();+ FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation();+CREATE OR REPLACE FUNCTION gbrain_refuse_stored_purging_derivation() RETURNS trigger SECURITY DEFINER SET search_path = pg_catalog, public, pg_temp AS \$func\$+BEGIN+ IF EXISTS (SELECT 1 FROM page_segment_derivation_purges x JOIN pages p ON p.source_id = x.source_id+ WHERE p.id = NEW.page_id AND (NEW.page_id = ANY(x.page_ids::int[]) OR p.deleted_at IS NOT NULL OR NOT EXISTS (SELECT 1 FROM page_body_manifest m+ WHERE m.page_id = NEW.page_id AND m.occurrence_id = NEW.occurrence_id AND m.gen_to IS NULL AND m.staging_id IS NULL AND m.sha256 = NEW.segment_sha256))+ AND CASE WHEN replace(translate(lower(COALESCE(NEW.output::text, '') || ' ' || COALESCE(NEW.receipt::text, '')), 'ς', 'σ'), 'i̇', 'i') LIKE ANY (x.patterns::text[]) THEN EXISTS (SELECT 1 FROM (VALUES (NEW.output), (NEW.receipt)) doc(j),+ LATERAL (SELECT jsonb_path_query(doc.j, 'strict \$.** ? (@.type() == "string")') #>> '{}' AS t+ UNION ALL SELECT jsonb_path_query(doc.j, 'strict \$.** ? (@.type() == "object").keyvalue().key') #>> '{}') s+ WHERE CASE WHEN replace(translate(lower(s.t), 'ς', 'σ'), 'i̇', 'i') LIKE ANY (x.patterns::text[]) THEN EXISTS (SELECT 1 FROM unnest(x.needles::text[]) k(n)+ WHERE strpos(' ' || replace(translate(gbrain_fact_normalize(s.t), 'ς', 'σ'), 'i̇', 'i') || ' ', k.n) > 0) ELSE false END) ELSE false END) THEN+ RAISE EXCEPTION USING ERRCODE = 'P0001',+ MESSAGE = 'derivation_purge_pending: a fact purge''s sweep of stored derivation results is still running and this row holds its claim',+ DETAIL = json_build_object('table', 'page_segment_derivations')::text;+ END IF;+ RETURN NULL;+END+\$func\$ LANGUAGE plpgsql;+REVOKE EXECUTE ON FUNCTION gbrain_refuse_stored_purging_derivation() FROM PUBLIC;+DO \$revoke\$ BEGIN+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'anon') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_stored_purging_derivation() FROM anon; END IF;+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'authenticated') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_stored_purging_derivation() FROM authenticated; END IF;+END \$revoke\$;+DROP TRIGGER IF EXISTS page_segment_derivations_refuse_stored_purging ON page_segment_derivations;+CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON page_segment_derivations+ FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation();-- END GENERATED from src/core/page-body/schema.ts (PAGE_SEGMENT_DERIVATIONS_SQL)-- BEGIN GENERATED from src/core/page-body/schema.ts (PAGE_BODY_RLS_SQL). Edit that file, then run: bun run build:schemadiff --git a/src/core/schema-migrations/v276-guard-triggers-security-definer.ts b/src/core/schema-migrations/v276-guard-triggers-security-definer.tsindex 43dfa047b2..311fd62418 100644--- a/src/core/schema-migrations/v276-guard-triggers-security-definer.ts+++ b/src/core/schema-migrations/v276-guard-triggers-security-definer.ts@@ -6,7 +6,7 @@ import { resolveSchemaLockTimeoutMs, schemaLockBlockedError } from '../postgres-import {AFTER_ROW_PURGE_TRIGGERS, DEFINER_GUARDS, FUNCTION_SEARCH_PATH_HARDENING_SQL, LEGACY_SEARCH_PATH_SETTINGS, definerGuardSql,} from '../guard-definer.ts';-import { DERIVATION_GUARD_GATE_SQL, DERIVATION_GUARD_TRIGGER_SQL } from '../page-body/schema.ts';+import { DERIVATION_STORED_GUARD_SQL } from '../page-body/schema.ts';// Applied by src/core/migrate.ts on the next initSchema(); see docs/ENGINES.md// ("Canonical schema sources") for when schema.sql or a TS fragment also changes.@@ -15,15 +15,15 @@ import { DERIVATION_GUARD_GATE_SQL, DERIVATION_GUARD_TRIGGER_SQL } from '../page// a policy on a ledger no longer slips a purged claim, page, take or derivation, or a withdrawn fact, past them. The// rest of the change keeps that from widening anyone's reach (src/core/guard-definer.ts): search_path pinned with// pg_temp last on every gbrain function, EXECUTE revoked from PUBLIC/anon/authenticated, the raising guards moved to-// AFTER ROW and the BEFORE derivation guard gated on the writer seeing the page, so a definer never answers a role-// RLS refuses. ALTER and trigger DDL need the owner: a function or table the role does not own is skipped and named+// AFTER ROW, and the derivation guard split into its BEFORE ROW invoker drop (unchanged) and an AFTER ROW definer that+// raises for a row stored anyway, so a definer never answers a role RLS refuses. ALTER and trigger DDL need the owner: a function or table the role does not own is skipped and named// on stderr, as v275 does, and doctor's guard_functions check keeps failing with the fix until it is done. Each// function and each table is its own short transaction with the migration's statement and lock timeouts.const TRIGGERS: ReadonlyArray<{ table: string; trigger: string; fn: string; sql: string }> = [...AFTER_ROW_PURGE_TRIGGERS,{- table: 'page_segment_derivations', trigger: 'page_segment_derivations_refuse_purging', fn: 'gbrain_refuse_purging_derivation',- sql: `${DERIVATION_GUARD_GATE_SQL}\n${DERIVATION_GUARD_TRIGGER_SQL}`,+ table: 'page_segment_derivations', trigger: 'page_segment_derivations_refuse_stored_purging', fn: 'gbrain_refuse_stored_purging_derivation',+ sql: DERIVATION_STORED_GUARD_SQL,},];@@ -45,8 +45,8 @@ async function inShortTransaction(engine: BrainEngine, step: string, sql: string/*** Moves the guards' triggers, then makes the purge and withdrawal guards definers, and appends pg_temp to every gbrain- * function's search_path, for what the role owns. A raising guard whose trigger still fires BEFORE ROW ungated stays- * an invoker, so a definer never answers before RLS. Names on stderr what it could not change and returns those names.+ * function's search_path, for what the role owns. A raising guard whose trigger still fires BEFORE ROW stays an+ * invoker, so a definer never answers before RLS; a guard whose table step was skipped is absent and named. Names on stderr what it could not change and returns those names.*/export async function hardenGuards(engine: BrainEngine, label: string): Promise<string[]> {const skipped: string[] = [];@@ -62,12 +62,11 @@ export async function hardenGuards(engine: BrainEngine, label: string): Promise<}const exposed = new Set((await engine.executeRaw<{ fn: string }>(`SELECT DISTINCT p.proname AS fn FROM pg_trigger t JOIN pg_proc p ON p.oid = t.tgfoid- WHERE NOT t.tgisinternal AND p.proname = ANY($1::text[]) AND (t.tgtype & 2) <> 0- AND pg_get_triggerdef(t.oid) NOT LIKE '%gbrain_caller_sees_page(%'`,+ WHERE NOT t.tgisinternal AND p.proname = ANY($1::text[]) AND (t.tgtype & 2) <> 0`,[TRIGGERS.map(t => t.fn)])).map(r => r.fn));const functions = await engine.executeRaw<{ fn: string; owned: boolean | null }>(`SELECT f.fn, pg_has_role(current_user, p.proowner, 'USAGE') AS owned- FROM unnest($1::text[]) AS f(fn) JOIN pg_proc p ON p.oid = to_regprocedure(f.fn || '()') ORDER BY f.fn`,+ FROM unnest($1::text[]) AS f(fn) LEFT JOIN pg_proc p ON p.oid = to_regprocedure(f.fn || '()') ORDER BY f.fn`,[DEFINER_GUARDS.map(g => g.fn)]);for (const { fn, owned } of functions) {if (owned && !exposed.has(fn)) await inShortTransaction(engine, `${label} on ${fn}()`, definerGuardSql(fn));diff --git a/src/schema.sql b/src/schema.sqlindex 8eb6fed68c..fc2d8ffcc8 100644--- a/src/schema.sql+++ b/src/schema.sql@@ -2289,9 +2289,7 @@ CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON page_bDROP TRIGGER IF EXISTS pages_derivation_scope_delete ON pages;CREATE TRIGGER pages_derivation_scope_delete AFTER UPDATE OF deleted_at ON pagesFOR EACH ROW WHEN (OLD.deleted_at IS NULL AND NEW.deleted_at IS NOT NULL) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry();-CREATE OR REPLACE FUNCTION gbrain_caller_sees_page(page INTEGER) RETURNS boolean LANGUAGE sql STABLE SECURITY INVOKER- SET search_path = pg_catalog, public, pg_temp AS $func$ SELECT EXISTS (SELECT 1 FROM pages WHERE id = page) $func$;-CREATE OR REPLACE FUNCTION gbrain_refuse_purging_derivation() RETURNS trigger SECURITY DEFINER SET search_path = pg_catalog, public, pg_temp AS $func$+CREATE OR REPLACE FUNCTION gbrain_refuse_purging_derivation() RETURNS trigger SET search_path = pg_catalog, public AS $func$BEGINIF EXISTS (SELECT 1 FROM page_segment_derivation_purges x JOIN pages p ON p.source_id = x.source_idWHERE p.id = NEW.page_id AND (NEW.page_id = ANY(x.page_ids::int[]) OR p.deleted_at IS NOT NULL OR NOT EXISTS (SELECT 1 FROM page_body_manifest m@@ -2306,14 +2304,34 @@ BEGINRETURN NEW;END$func$ LANGUAGE plpgsql;-REVOKE EXECUTE ON FUNCTION gbrain_refuse_purging_derivation() FROM PUBLIC;-DO $revoke$ BEGIN- IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'anon') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_purging_derivation() FROM anon; END IF;- IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'authenticated') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_purging_derivation() FROM authenticated; END IF;-END $revoke$;DROP TRIGGER IF EXISTS page_segment_derivations_refuse_purging ON page_segment_derivations;CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON page_segment_derivations- FOR EACH ROW WHEN (gbrain_caller_sees_page(NEW.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation();+ FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation();+CREATE OR REPLACE FUNCTION gbrain_refuse_stored_purging_derivation() RETURNS trigger SECURITY DEFINER SET search_path = pg_catalog, public, pg_temp AS $func$+BEGIN+ IF EXISTS (SELECT 1 FROM page_segment_derivation_purges x JOIN pages p ON p.source_id = x.source_id+ WHERE p.id = NEW.page_id AND (NEW.page_id = ANY(x.page_ids::int[]) OR p.deleted_at IS NOT NULL OR NOT EXISTS (SELECT 1 FROM page_body_manifest m+ WHERE m.page_id = NEW.page_id AND m.occurrence_id = NEW.occurrence_id AND m.gen_to IS NULL AND m.staging_id IS NULL AND m.sha256 = NEW.segment_sha256))+ AND CASE WHEN replace(translate(lower(COALESCE(NEW.output::text, '') || ' ' || COALESCE(NEW.receipt::text, '')), 'ς', 'σ'), 'i̇', 'i') LIKE ANY (x.patterns::text[]) THEN EXISTS (SELECT 1 FROM (VALUES (NEW.output), (NEW.receipt)) doc(j),+ LATERAL (SELECT jsonb_path_query(doc.j, 'strict $.** ? (@.type() == "string")') #>> '{}' AS t+ UNION ALL SELECT jsonb_path_query(doc.j, 'strict $.** ? (@.type() == "object").keyvalue().key') #>> '{}') s+ WHERE CASE WHEN replace(translate(lower(s.t), 'ς', 'σ'), 'i̇', 'i') LIKE ANY (x.patterns::text[]) THEN EXISTS (SELECT 1 FROM unnest(x.needles::text[]) k(n)+ WHERE strpos(' ' || replace(translate(gbrain_fact_normalize(s.t), 'ς', 'σ'), 'i̇', 'i') || ' ', k.n) > 0) ELSE false END) ELSE false END) THEN+ RAISE EXCEPTION USING ERRCODE = 'P0001',+ MESSAGE = 'derivation_purge_pending: a fact purge''s sweep of stored derivation results is still running and this row holds its claim',+ DETAIL = json_build_object('table', 'page_segment_derivations')::text;+ END IF;+ RETURN NULL;+END+$func$ LANGUAGE plpgsql;+REVOKE EXECUTE ON FUNCTION gbrain_refuse_stored_purging_derivation() FROM PUBLIC;+DO $revoke$ BEGIN+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'anon') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_stored_purging_derivation() FROM anon; END IF;+ IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'authenticated') THEN REVOKE EXECUTE ON FUNCTION gbrain_refuse_stored_purging_derivation() FROM authenticated; END IF;+END $revoke$;+DROP TRIGGER IF EXISTS page_segment_derivations_refuse_stored_purging ON page_segment_derivations;+CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON page_segment_derivations+ FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation();-- END GENERATED from src/core/page-body/schema.ts (PAGE_SEGMENT_DERIVATIONS_SQL)-- BEGIN GENERATED from src/core/page-body/schema.ts (PAGE_BODY_RLS_SQL). Edit that file, then run: bun run build:schemadiff --git a/test/doctor-guard-functions.test.ts b/test/doctor-guard-functions.test.tsindex 200a9f2cbf..ceb138fc02 100644--- a/test/doctor-guard-functions.test.ts+++ b/test/doctor-guard-functions.test.ts@@ -24,16 +24,14 @@ describe('guard_functions doctor check (#7632)', () => {GRANT EXECUTE ON FUNCTION gbrain_refuse_purged_take() TO PUBLIC;DROP TRIGGER pages_refuse_purged ON pages;CREATE TRIGGER pages_refuse_purged BEFORE INSERT OR UPDATE ON pages FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purged_page();- DROP TRIGGER page_segment_derivations_refuse_purging ON page_segment_derivations;- CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON page_segment_derivations- FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation();+ DROP TRIGGER page_segment_derivations_refuse_stored_purging ON page_segment_derivations;ALTER FUNCTION gbrain_try_jsonb(text) SET search_path = pg_catalog, public;`);const { problems, fix } = await guardFunctionProblems(engine);expect(problems).toEqual(['gbrain_refuse_purged_page() is not SECURITY DEFINER with search_path pg_catalog, public, pg_temp','gbrain_refuse_purged_take() is executable by PUBLIC','pages_refuse_purged on pages still fires BEFORE ROW',- 'page_segment_derivations_refuse_purging has no gbrain_caller_sees_page gate',+ 'page_segment_derivations has no page_segment_derivations_refuse_stored_purging AFTER ROW check','2 function(s) pin search_path without pg_temp last (gbrain_refuse_purged_page(), gbrain_try_jsonb(text))',]);await engine.runMigration(0, fix.join('\n'));diff --git a/test/e2e/guard-definer-postgres.test.ts b/test/e2e/guard-definer-postgres.test.tsindex d3ff991573..4e2755479e 100644--- a/test/e2e/guard-definer-postgres.test.ts+++ b/test/e2e/guard-definer-postgres.test.ts@@ -7,7 +7,8 @@* Before #7632 the guards were SECURITY INVOKER: under that role a ledger read returned no row, so a purged claim,* page, take or derivation was stored again and a withdrawn fact was saved active. Cases 6-9 pin the holes a definer* could open: a temp table or view named like a ledger (the caller's temp schema is searched first unless pg_temp is- * named last), a BEFORE ROW definer answering a role RLS refuses, and direct calls.+ * named last), a BEFORE ROW definer answering a role RLS refuses (case 17: a role that can read the page but whose+ * derivation row RLS refuses), and direct calls.* Run: DATABASE_URL=... bun test test/e2e/guard-definer-postgres.test.ts*/import { afterAll, beforeAll, describe, expect, test } from 'bun:test';@@ -18,6 +19,7 @@ import { PostgresEngine } from '../../src/core/postgres-engine.ts';import { LATEST_VERSION, runMigrations } from '../../src/core/migrate.ts';import { guardFunctionProblems } from '../../src/commands/doctor/checks/guard-functions.ts';import { derivationNeedles } from '../../src/core/page-body/segment-derive.ts';+import { DerivationWriteRefused } from '../../src/core/page-body/derivations.ts';import { v276 } from '../../src/core/schema-migrations/v276-guard-triggers-security-definer.ts';import { withEnv } from '../helpers/with-env.ts';@@ -28,7 +30,8 @@ type Sql = ReturnType<typeof postgres>;type Outcome = { rows: Array<Record<string, unknown>> } | { code: string; message: string };const GUARDS = ['gbrain_guard_inserted_facts', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_refuse_purged_fact',- 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation'];+ 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_stored_purging_derivation'];+const STORED_GUARD = 'gbrain_refuse_stored_purging_derivation';const LEDGERS = ['fact_purges', 'fact_withdrawals', 'take_purges', 'page_purges', 'page_segment_derivation_purges', 'page_segment_derivation_purge_pages'];const API_ROLES = ['anon', 'authenticated'];@@ -185,10 +188,10 @@ describeE2E('purge and withdrawal guards under a scoped write role (#7632)', ()});});- test('4. a derivation holding a purged claim during its sweep is dropped; an unrelated one is stored', async () => {+ test('4. a derivation holding a purged claim during its sweep is refused for a writer that cannot read the sweep; an unrelated one is stored', async () => {await as(conn, WRITER, async run => {const [held, heldOutput] = insertDerivation(JSON.stringify({ text: PURGED_CLAIM }));- expect(rowsOf(await run(held, [ids.derived, 1, heldOutput]))).toEqual([]);+ expect(failure(await run(held, [ids.derived, 1, heldOutput]))).toMatchObject({ code: 'P0001', message: expect.stringContaining('derivation_purge_pending:') });const [other, otherOutput] = insertDerivation(JSON.stringify({ text: 'an unrelated link context' }));expect(rowsOf(await run(other, [ids.derived, 2, otherOutput]))).toEqual([{ stored: 1 }]);});@@ -211,7 +214,7 @@ describeE2E('purge and withdrawal guards under a scoped write role (#7632)', ()expect(failure(await run(`INSERT INTO pages (slug, type, title, compiled_truth, content_hash) VALUES ('notes/again-example', 'note', 't', 'x', $1)`, [PURGED_HASH])).code).toBe('P0001');expect(failure(await run(`INSERT INTO takes (page_id, row_num, claim, kind, holder) VALUES ($1, 1, $2, 'take', 'alice-example')`, [ids.takes, PURGED_TAKE])).code).toBe('P0001');const [held, heldOutput] = insertDerivation(JSON.stringify({ text: PURGED_CLAIM }));- expect(rowsOf(await run(held, [ids.derived, 1, heldOutput]))).toEqual([]);+ expect(failure(await run(held, [ids.derived, 1, heldOutput])).code).toBe('P0001');});});@@ -265,15 +268,15 @@ describeE2E('purge and withdrawal guards under a scoped write role (#7632)', ()ARRAY(SELECT 'PUBLIC' WHERE EXISTS (SELECT 1 FROM aclexplode(COALESCE(p.proacl, acldefault('f', p.proowner))) a WHERE a.grantee = 0 AND a.privilege_type = 'EXECUTE')UNION ALL SELECT r.rolname::text FROM pg_roles r WHERE r.rolname = ANY($2::text[]) AND has_function_privilege(r.oid, p.oid, 'EXECUTE')) AS executable_byFROM pg_proc p WHERE p.oid = ANY(SELECT to_regprocedure(g || '()') FROM unnest($1::text[]) g) ORDER BY 1`, [GUARDS, API_ROLES]);- const triggers = await c.unsafe<Array<{ trigger: string; timing: string; gated: boolean }>>(- `SELECT tgname AS trigger, CASE WHEN (tgtype & 2) <> 0 THEN 'BEFORE' ELSE 'AFTER' END AS timing, pg_get_triggerdef(oid) LIKE '%WHEN (gbrain_caller_sees_page(new.page_id))%' AS gated- FROM pg_trigger WHERE NOT tgisinternal AND tgname IN ('facts_refuse_purged', 'takes_refuse_purged', 'pages_refuse_purged', 'page_segment_derivations_refuse_purging') ORDER BY 1`);+ const triggers = await c.unsafe<Array<{ trigger: string; timing: string }>>(+ `SELECT tgname AS trigger, CASE WHEN (tgtype & 2) <> 0 THEN 'BEFORE' ELSE 'AFTER' END AS timing FROM pg_trigger WHERE NOT tgisinternal+ AND tgname IN ('facts_refuse_purged', 'takes_refuse_purged', 'pages_refuse_purged', 'page_segment_derivations_refuse_purging', 'page_segment_derivations_refuse_stored_purging') ORDER BY 1`);const pathsWithoutTemp = await c.unsafe<Array<{ sig: string }>>(`SELECT p.oid::regprocedure::text AS sig FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS s(setting)WHERE n.nspname = 'public' AND s.setting LIKE 'search_path=%' AND s.setting NOT LIKE '%, pg_temp' ORDER BY 1`);return {guards: guards.map(g => ({ fn: g.fn, secdef: g.secdef, config: g.config, executable_by: g.executable_by })),- triggers: triggers.map(t => ({ trigger: t.trigger, timing: t.timing, gated: t.gated })),+ triggers: triggers.map(t => ({ trigger: t.trigger, timing: t.timing })),pathsWithoutTemp: pathsWithoutTemp.map(p => p.sig),};}@@ -281,10 +284,11 @@ describeE2E('purge and withdrawal guards under a scoped write role (#7632)', ()const EXPECTED = {guards: GUARDS.map(fn => ({ fn, secdef: true, config: ['search_path=pg_catalog, public, pg_temp'], executable_by: [] })),triggers: [- { trigger: 'facts_refuse_purged', timing: 'AFTER', gated: false },- { trigger: 'page_segment_derivations_refuse_purging', timing: 'BEFORE', gated: true },- { trigger: 'pages_refuse_purged', timing: 'AFTER', gated: false },- { trigger: 'takes_refuse_purged', timing: 'AFTER', gated: false },+ { trigger: 'facts_refuse_purged', timing: 'AFTER' },+ { trigger: 'page_segment_derivations_refuse_purging', timing: 'BEFORE' },+ { trigger: 'page_segment_derivations_refuse_stored_purging', timing: 'AFTER' },+ { trigger: 'pages_refuse_purged', timing: 'AFTER' },+ { trigger: 'takes_refuse_purged', timing: 'AFTER' },],pathsWithoutTemp: [],};@@ -296,7 +300,9 @@ describeE2E('purge and withdrawal guards under a scoped write role (#7632)', ()/** Puts a brain back in the shape every brain had before #7632, at the version before it. */async function rewind(c: Sql): Promise<void> {await c.unsafe(`- ${GUARDS.map(fn => `ALTER FUNCTION ${fn}() SECURITY INVOKER; GRANT EXECUTE ON FUNCTION ${fn}() TO PUBLIC, anon, authenticated;`).join('\n')}+ ${GUARDS.filter(fn => fn !== STORED_GUARD).map(fn => `ALTER FUNCTION ${fn}() SECURITY INVOKER; GRANT EXECUTE ON FUNCTION ${fn}() TO PUBLIC, anon, authenticated;`).join('\n')}+ DROP TRIGGER page_segment_derivations_refuse_stored_purging ON page_segment_derivations;+ DROP FUNCTION ${STORED_GUARD}();DROP TRIGGER facts_refuse_purged ON facts;CREATE TRIGGER facts_refuse_purged BEFORE UPDATE OF fact, source_id, visibility, entity_slug ON facts FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purged_fact();DROP TRIGGER takes_refuse_purged ON takes;@@ -306,7 +312,6 @@ describeE2E('purge and withdrawal guards under a scoped write role (#7632)', ()DROP TRIGGER page_segment_derivations_refuse_purging ON page_segment_derivations;CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON page_segment_derivationsFOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation();- DROP FUNCTION IF EXISTS gbrain_caller_sees_page(integer);DO $$ DECLARE f RECORD; BEGINFOR f IN SELECT p.oid::regprocedure AS sig, substr(s.setting, 13) AS path FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespaceCROSS JOIN LATERAL unnest(p.proconfig) AS s(setting) WHERE n.nspname = 'public' AND s.setting LIKE 'search_path=%, pg_temp' LOOP@@ -358,7 +363,7 @@ describeE2E('purge and withdrawal guards under a scoped write role (#7632)', ()const { value, stderr } = await capturingStderr(() => runMigrations(notOwner));expect(value.current).toBe(LATEST_VERSION);for (const fn of GUARDS) expect(stderr).toContain(`${fn}()`);- for (const trigger of ['facts_refuse_purged', 'takes_refuse_purged', 'pages_refuse_purged', 'page_segment_derivations_refuse_purging']) expect(stderr).toContain(trigger);+ for (const trigger of ['facts_refuse_purged', 'takes_refuse_purged', 'pages_refuse_purged', 'page_segment_derivations_refuse_stored_purging']) expect(stderr).toContain(trigger);expect(stderr).toContain('left as they were');// Generated by gstack /ship coverage audit (#7642).// Value: protects=v276 names on stderr every non-guard function whose search_path it could not finish with pg_temp;@@ -470,24 +475,76 @@ describeE2E('purge and withdrawal guards under a scoped write role (#7632)', ()await admin!.unsafe(`CREATE ROLE ${migrator} LOGIN PASSWORD 'migrator' NOSUPERUSER BYPASSRLS`);createdRoles.push(migrator);const engine = new PostgresEngine();- const exposed = ['gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation'];+ const exposed = ['gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take'];try {await rewind(brain.conn);await brain.conn.unsafe(`GRANT USAGE, CREATE ON SCHEMA public TO ${migrator}; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO ${migrator};- ${GUARDS.map(fn => `ALTER FUNCTION ${fn}() OWNER TO ${migrator};`).join('\n')}`);+ ${GUARDS.filter(fn => fn !== STORED_GUARD).map(fn => `ALTER FUNCTION ${fn}() OWNER TO ${migrator};`).join('\n')}`);const asMigrator = new URL(brain.url);asMigrator.username = migrator;asMigrator.password = 'migrator';await engine.connect({ database_url: asMigrator.toString() });const { value, stderr } = await capturingStderr(() => runMigrations(engine));expect(value.current).toBe(LATEST_VERSION);- for (const fn of exposed) expect(stderr).toContain(`${fn}()`);+ for (const fn of [...exposed, STORED_GUARD]) expect(stderr).toContain(`${fn}()`);const after = await catalog(brain.conn);- expect(after.guards.map(g => [g.fn, g.secdef])).toEqual(GUARDS.map(fn => [fn, !exposed.includes(fn)]));- expect(after.triggers.every(t => t.timing === 'BEFORE' && !t.gated)).toBe(true);+ expect(after.guards.map(g => [g.fn, g.secdef])).toEqual(GUARDS.filter(fn => fn !== STORED_GUARD).map(fn => [fn, !exposed.includes(fn)]));+ expect(after.triggers.map(t => [t.trigger, t.timing])).toEqual([+ ['facts_refuse_purged', 'BEFORE'], ['page_segment_derivations_refuse_purging', 'BEFORE'], ['pages_refuse_purged', 'BEFORE'], ['takes_refuse_purged', 'BEFORE'],+ ]);} finally {await engine.disconnect().catch(() => {});await brain.conn.end();}}, 300_000);++ test('16. owners, roles that bypass RLS and writers with policies on the sweep records still have the row dropped silently', async () => {+ const bypass = `gbrain_test_guard_bypass_${suffix}`;+ const reader = `gbrain_test_guard_reader_${suffix}`;+ await admin!.unsafe(`CREATE ROLE ${bypass} NOLOGIN NOSUPERUSER BYPASSRLS; CREATE ROLE ${reader} NOLOGIN NOSUPERUSER NOBYPASSRLS`);+ createdRoles.push(bypass, reader);+ await conn.unsafe(`GRANT USAGE ON SCHEMA public TO ${bypass}, ${reader};+ GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO ${bypass}, ${reader};+ DO $$ DECLARE t RECORD; BEGIN+ FOR t IN SELECT c.oid::regclass AS rel FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace+ WHERE n.nspname = 'public' AND c.relkind IN ('r', 'p') AND c.relrowsecurity LOOP+ EXECUTE format('CREATE POLICY gbrain_test_reader ON %s TO ${reader} USING (true) WITH CHECK (true)', t.rel);+ END LOOP; END $$`);+ const [held, heldOutput] = insertDerivation(JSON.stringify({ text: PURGED_CLAIM }));+ for (const role of ['postgres', bypass, reader]) {+ await as(conn, role, async run => {+ expect({ role, rows: rowsOf(await run(held, [ids.derived, 1, heldOutput])) }).toEqual({ role, rows: [] });+ });+ }+ const engine = new PostgresEngine();+ try {+ await engine.connect({ database_url: url });+ const row = (occurrenceId: number, text: string) => ({ pageId: ids.derived!, kind: 'links' as const, occurrenceId, version: 1,+ segmentSha256: new Uint8Array(32).fill(0xab), contextHash: new Uint8Array(32).fill(0xab), state: 'done' as const, output: { text }, receipt: null });+ const refused = await engine.upsertSegmentDerivations([row(31, PURGED_CLAIM), row(32, 'an unrelated link context')]).then(() => null, (e: unknown) => e);+ expect(refused).toBeInstanceOf(DerivationWriteRefused);+ expect((refused as DerivationWriteRefused).refused).toBe(1);+ expect((await conn.unsafe('SELECT occurrence_id::int AS o FROM page_segment_derivations WHERE page_id = $1 AND occurrence_id IN (31, 32) ORDER BY 1', [ids.derived]))+ .map(r => r.o)).toEqual([32]);+ } finally {+ await conn.unsafe('DELETE FROM page_segment_derivations WHERE page_id = $1 AND occurrence_id IN (31, 32)', [ids.derived]);+ await engine.disconnect();+ }+ });++ test('17. a role that can read the page but whose derivation row RLS refuses gets the same 42501 for a purged claim and unrelated text', async () => {+ await conn.unsafe('CREATE POLICY gbrain_test_read_pages ON pages FOR SELECT TO authenticated USING (true)');+ try {+ await as(conn, 'authenticated', async run => {+ expect(rowsOf(await run('SELECT id FROM pages WHERE id = $1', [ids.derived]))).toEqual([{ id: ids.derived }]);+ const [sql] = insertDerivation('{}');+ const derivation = (text: string) => run(sql, [ids.derived, 9, JSON.stringify({ text })]);+ const purged = failure(await derivation(PURGED_CLAIM));+ expect(purged).toEqual(failure(await derivation('an unrelated link context')));+ expect(purged.code).toBe('42501');+ });+ } finally {+ await conn.unsafe('DROP POLICY gbrain_test_read_pages ON pages');+ }+ });});diff --git a/test/e2e/rls-every-table-postgres.test.ts b/test/e2e/rls-every-table-postgres.test.tsindex 3406d53b4f..c79e9759a6 100644--- a/test/e2e/rls-every-table-postgres.test.ts+++ b/test/e2e/rls-every-table-postgres.test.ts@@ -122,6 +122,7 @@ describeE2E('RLS on every public table (Postgres, no auto-RLS event trigger)', (DROP TRIGGER IF EXISTS pages_derivation_scope_delete ON pages;DROP FUNCTION IF EXISTS gbrain_mark_derivation_scope_entry();DROP FUNCTION IF EXISTS gbrain_refuse_purging_derivation();+ DROP FUNCTION IF EXISTS gbrain_refuse_stored_purging_derivation();ALTER TABLE facts DROP CONSTRAINT IF EXISTS facts_source_window_chk, DROP COLUMN IF EXISTS source_window;ALTER TABLE pages DROP COLUMN IF EXISTS withheld_source_path;`);await conn.unsafe(`UPDATE config SET value = '272' WHERE key = 'version'`);diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.jsonindex b629e97511..56f5f23962 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json@@ -542,7 +542,6 @@"gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5","gbrain_bump_trust_generation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4708a89d166ac0999a8922ad8ee8f69fea3213c59e0782d96220f93b0c001a62",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_clear_atom_page_state()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7db0ef05d1220a579e64428b2dd7cf5183191da186fbe64b6496433a7a713d11","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_count_modifications()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=9518c925621def19cafb2918da4d41e602ce94619af872eafa3c11b46c66296f",@@ -564,7 +563,8 @@"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=d1d584b91ceea7f4e63c235b790ef89c958c578e635f77ddd644918bc36d33f1","gbrain_refuse_purged_page()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=8aaaf7c22fc9acb4b1e84fe75f11ae6c889949b78de1ef6bdba1db54ef43844e","gbrain_refuse_purged_take()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=4a291b0448ab7a31926aa482b5222e0595d31a6bfad81b851b13e4bf581a0d83",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7452350236ed4c68a6cd1f4d78a1381a4ef44cc70e8a032141f01bba4a704702",@@ -4331,7 +4331,8 @@"page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_purges.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.page_purges DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_versions.page_versions_trust_snapshot": "CREATE TRIGGER page_versions_trust_snapshot BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_snapshot_version_trust()","page_versions.page_versions_write_attribution": "CREATE TRIGGER page_versions_write_attribution BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_version_attribution()",diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.jsonindex adb8ada882..517057c3df 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json@@ -542,7 +542,6 @@"gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5","gbrain_bump_trust_generation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4708a89d166ac0999a8922ad8ee8f69fea3213c59e0782d96220f93b0c001a62",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_clear_atom_page_state()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7db0ef05d1220a579e64428b2dd7cf5183191da186fbe64b6496433a7a713d11","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_count_modifications()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=9518c925621def19cafb2918da4d41e602ce94619af872eafa3c11b46c66296f",@@ -564,7 +563,8 @@"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=d1d584b91ceea7f4e63c235b790ef89c958c578e635f77ddd644918bc36d33f1","gbrain_refuse_purged_page()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=8aaaf7c22fc9acb4b1e84fe75f11ae6c889949b78de1ef6bdba1db54ef43844e","gbrain_refuse_purged_take()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=4a291b0448ab7a31926aa482b5222e0595d31a6bfad81b851b13e4bf581a0d83",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7452350236ed4c68a6cd1f4d78a1381a4ef44cc70e8a032141f01bba4a704702",@@ -4331,7 +4331,8 @@"page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_purges.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.page_purges DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_versions.page_versions_trust_snapshot": "CREATE TRIGGER page_versions_trust_snapshot BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_snapshot_version_trust()","page_versions.page_versions_write_attribution": "CREATE TRIGGER page_versions_write_attribution BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_version_attribution()",diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.jsonindex 8d7682da6a..888ab14e7d 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json@@ -542,7 +542,6 @@"gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5","gbrain_bump_trust_generation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4708a89d166ac0999a8922ad8ee8f69fea3213c59e0782d96220f93b0c001a62",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_clear_atom_page_state()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7db0ef05d1220a579e64428b2dd7cf5183191da186fbe64b6496433a7a713d11","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_count_modifications()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=9518c925621def19cafb2918da4d41e602ce94619af872eafa3c11b46c66296f",@@ -564,7 +563,8 @@"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=d1d584b91ceea7f4e63c235b790ef89c958c578e635f77ddd644918bc36d33f1","gbrain_refuse_purged_page()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=8aaaf7c22fc9acb4b1e84fe75f11ae6c889949b78de1ef6bdba1db54ef43844e","gbrain_refuse_purged_take()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=4a291b0448ab7a31926aa482b5222e0595d31a6bfad81b851b13e4bf581a0d83",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7452350236ed4c68a6cd1f4d78a1381a4ef44cc70e8a032141f01bba4a704702",@@ -4327,7 +4327,8 @@"page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_purges.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.page_purges DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_versions.page_versions_trust_snapshot": "CREATE TRIGGER page_versions_trust_snapshot BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_snapshot_version_trust()","page_versions.page_versions_write_attribution": "CREATE TRIGGER page_versions_write_attribution BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_version_attribution()",diff --git a/test/fixtures/goldens/catalog/pglite-schema-blob-default.json b/test/fixtures/goldens/catalog/pglite-schema-blob-default.jsonindex e8ebde391f..04f81d619d 100644--- a/test/fixtures/goldens/catalog/pglite-schema-blob-default.json+++ b/test/fixtures/goldens/catalog/pglite-schema-blob-default.json@@ -411,7 +411,6 @@"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784","gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_forget_page_retrievals()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0f053c08f9d5a4512d10406f7b20b9c60ec43d9bbea48b28b7e4cf7187ee191b","gbrain_fts_input(t text)": "RETURNS text kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=c73d0dbc333c6dccc9714a6b8d1b7785f48170556b9024002ddca1c80b25d87d",@@ -422,7 +421,8 @@"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf","gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=72ac0027fd37ecc4c72ad2e294ae3a98564736339b9ac917ea5d4112ec3cd35f","gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=6c544b9c129b6a17dcabeb5ee8d44a2b0e0af9d02ca3fe47c7d7f22ec313042c",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -3293,7 +3293,8 @@"page_body_manifest.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_body_manifest FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","pages.bump_page_generation_clock_trg": "CREATE TRIGGER bump_page_generation_clock_trg AFTER INSERT OR DELETE OR UPDATE ON public.pages FOR EACH STATEMENT EXECUTE FUNCTION bump_page_generation_clock_fn()","pages.bump_page_generation_trg": "CREATE TRIGGER bump_page_generation_trg BEFORE INSERT OR UPDATE ON public.pages FOR EACH ROW EXECUTE FUNCTION bump_page_generation_fn()",diff --git a/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.jsonindex c3273e348c..addd05b8b9 100644--- a/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json@@ -411,7 +411,6 @@"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784","gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_forget_page_retrievals()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0f053c08f9d5a4512d10406f7b20b9c60ec43d9bbea48b28b7e4cf7187ee191b","gbrain_fts_input(t text)": "RETURNS text kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=c73d0dbc333c6dccc9714a6b8d1b7785f48170556b9024002ddca1c80b25d87d",@@ -422,7 +421,8 @@"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf","gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=72ac0027fd37ecc4c72ad2e294ae3a98564736339b9ac917ea5d4112ec3cd35f","gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=6c544b9c129b6a17dcabeb5ee8d44a2b0e0af9d02ca3fe47c7d7f22ec313042c",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -3293,7 +3293,8 @@"page_body_manifest.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_body_manifest FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","pages.bump_page_generation_clock_trg": "CREATE TRIGGER bump_page_generation_clock_trg AFTER INSERT OR DELETE OR UPDATE ON public.pages FOR EACH STATEMENT EXECUTE FUNCTION bump_page_generation_clock_fn()","pages.bump_page_generation_trg": "CREATE TRIGGER bump_page_generation_trg BEFORE INSERT OR UPDATE ON public.pages FOR EACH ROW EXECUTE FUNCTION bump_page_generation_fn()",diff --git a/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json b/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.jsonindex 67aeeb8b38..e201adb752 100644--- a/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json+++ b/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json@@ -411,7 +411,6 @@"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784","gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_forget_page_retrievals()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0f053c08f9d5a4512d10406f7b20b9c60ec43d9bbea48b28b7e4cf7187ee191b","gbrain_fts_input(t text)": "RETURNS text kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=c73d0dbc333c6dccc9714a6b8d1b7785f48170556b9024002ddca1c80b25d87d",@@ -422,7 +421,8 @@"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf","gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=72ac0027fd37ecc4c72ad2e294ae3a98564736339b9ac917ea5d4112ec3cd35f","gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=6c544b9c129b6a17dcabeb5ee8d44a2b0e0af9d02ca3fe47c7d7f22ec313042c",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -3292,7 +3292,8 @@"page_body_manifest.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_body_manifest FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","pages.bump_page_generation_clock_trg": "CREATE TRIGGER bump_page_generation_clock_trg AFTER INSERT OR DELETE OR UPDATE ON public.pages FOR EACH STATEMENT EXECUTE FUNCTION bump_page_generation_clock_fn()","pages.bump_page_generation_trg": "CREATE TRIGGER bump_page_generation_trg BEFORE INSERT OR UPDATE ON public.pages FOR EACH ROW EXECUTE FUNCTION bump_page_generation_fn()",diff --git a/test/fixtures/goldens/catalog/postgres-db-initschema.json b/test/fixtures/goldens/catalog/postgres-db-initschema.jsonindex 965b7f7800..58f3842188 100644--- a/test/fixtures/goldens/catalog/postgres-db-initschema.json+++ b/test/fixtures/goldens/catalog/postgres-db-initschema.json@@ -420,7 +420,6 @@"enforce_minion_queue_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=be82640d1979fc81dc812efb78bb3596ef536f656d20750e5e4aa19016bf4784","gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_forget_page_retrievals()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0f053c08f9d5a4512d10406f7b20b9c60ec43d9bbea48b28b7e4cf7187ee191b","gbrain_fts_input(t text)": "RETURNS text kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=c73d0dbc333c6dccc9714a6b8d1b7785f48170556b9024002ddca1c80b25d87d",@@ -431,7 +430,8 @@"gbrain_lease_shared_skill_delivery()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=5e493c1ac8dce8cb025a736629e563437c4b214744137c302c532c20bf7e7acf","gbrain_mark_derivation_scope_entry()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=72ac0027fd37ecc4c72ad2e294ae3a98564736339b9ac917ea5d4112ec3cd35f","gbrain_queue_page_projection()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=6c544b9c129b6a17dcabeb5ee8d44a2b0e0af9d02ca3fe47c7d7f22ec313042c",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -3355,7 +3355,8 @@"page_body_manifest.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_body_manifest FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","pages.bump_page_generation_clock_trg": "CREATE TRIGGER bump_page_generation_clock_trg AFTER INSERT OR DELETE OR UPDATE ON public.pages FOR EACH STATEMENT EXECUTE FUNCTION bump_page_generation_clock_fn()","pages.bump_page_generation_trg": "CREATE TRIGGER bump_page_generation_trg BEFORE INSERT OR UPDATE ON public.pages FOR EACH ROW EXECUTE FUNCTION bump_page_generation_fn()",diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-default.json b/test/fixtures/goldens/catalog/postgres-engine-init-default.jsonindex ebd5f96e7b..2ba03eafe7 100644--- a/test/fixtures/goldens/catalog/postgres-engine-init-default.json+++ b/test/fixtures/goldens/catalog/postgres-engine-init-default.json@@ -546,7 +546,6 @@"gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5","gbrain_bump_trust_generation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4708a89d166ac0999a8922ad8ee8f69fea3213c59e0782d96220f93b0c001a62",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_clear_atom_page_state()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7db0ef05d1220a579e64428b2dd7cf5183191da186fbe64b6496433a7a713d11","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_fact_fingerprint(claim text)": "RETURNS text kind=f lang=sql volatility=i secdef=false config=[] body_sha256=ff99709590deb4c83f0e16d30b3988ca2598018f5fd6f30d132acf31b1010174",@@ -567,7 +566,8 @@"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=d1d584b91ceea7f4e63c235b790ef89c958c578e635f77ddd644918bc36d33f1","gbrain_refuse_purged_page()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=8aaaf7c22fc9acb4b1e84fe75f11ae6c889949b78de1ef6bdba1db54ef43844e","gbrain_refuse_purged_take()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=4a291b0448ab7a31926aa482b5222e0595d31a6bfad81b851b13e4bf581a0d83",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7452350236ed4c68a6cd1f4d78a1381a4ef44cc70e8a032141f01bba4a704702",@@ -4318,7 +4318,8 @@"page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_purges.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.page_purges DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_versions.page_versions_trust_snapshot": "CREATE TRIGGER page_versions_trust_snapshot BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_snapshot_version_trust()","page_versions.page_versions_write_attribution": "CREATE TRIGGER page_versions_write_attribution BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_version_attribution()",diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.jsonindex 5383269beb..f1da570cc6 100644--- a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json@@ -546,7 +546,6 @@"gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5","gbrain_bump_trust_generation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4708a89d166ac0999a8922ad8ee8f69fea3213c59e0782d96220f93b0c001a62",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_clear_atom_page_state()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7db0ef05d1220a579e64428b2dd7cf5183191da186fbe64b6496433a7a713d11","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_fact_fingerprint(claim text)": "RETURNS text kind=f lang=sql volatility=i secdef=false config=[] body_sha256=ff99709590deb4c83f0e16d30b3988ca2598018f5fd6f30d132acf31b1010174",@@ -567,7 +566,8 @@"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=d1d584b91ceea7f4e63c235b790ef89c958c578e635f77ddd644918bc36d33f1","gbrain_refuse_purged_page()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=8aaaf7c22fc9acb4b1e84fe75f11ae6c889949b78de1ef6bdba1db54ef43844e","gbrain_refuse_purged_take()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=4a291b0448ab7a31926aa482b5222e0595d31a6bfad81b851b13e4bf581a0d83",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7452350236ed4c68a6cd1f4d78a1381a4ef44cc70e8a032141f01bba4a704702",@@ -4318,7 +4318,8 @@"page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_purges.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.page_purges DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_versions.page_versions_trust_snapshot": "CREATE TRIGGER page_versions_trust_snapshot BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_snapshot_version_trust()","page_versions.page_versions_write_attribution": "CREATE TRIGGER page_versions_write_attribution BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_version_attribution()",diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.jsonindex 5b7839c5d5..0a534c8c5d 100644--- a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json+++ b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json@@ -546,7 +546,6 @@"gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5","gbrain_bump_trust_generation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4708a89d166ac0999a8922ad8ee8f69fea3213c59e0782d96220f93b0c001a62",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_clear_atom_page_state()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7db0ef05d1220a579e64428b2dd7cf5183191da186fbe64b6496433a7a713d11","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_fact_fingerprint(claim text)": "RETURNS text kind=f lang=sql volatility=i secdef=false config=[] body_sha256=ff99709590deb4c83f0e16d30b3988ca2598018f5fd6f30d132acf31b1010174",@@ -567,7 +566,8 @@"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=d1d584b91ceea7f4e63c235b790ef89c958c578e635f77ddd644918bc36d33f1","gbrain_refuse_purged_page()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=8aaaf7c22fc9acb4b1e84fe75f11ae6c889949b78de1ef6bdba1db54ef43844e","gbrain_refuse_purged_take()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=4a291b0448ab7a31926aa482b5222e0595d31a6bfad81b851b13e4bf581a0d83",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7452350236ed4c68a6cd1f4d78a1381a4ef44cc70e8a032141f01bba4a704702",@@ -4314,7 +4314,8 @@"page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_purges.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.page_purges DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_versions.page_versions_trust_snapshot": "CREATE TRIGGER page_versions_trust_snapshot BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_snapshot_version_trust()","page_versions.page_versions_write_attribution": "CREATE TRIGGER page_versions_write_attribution BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_version_attribution()",diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.jsonindex 7164210a8f..3fdbc2e4e6 100644--- a/test/fixtures/goldens/migrations/records.json+++ b/test/fixtures/goldens/migrations/records.json@@ -16,9 +16,8 @@"CONTENT_CHUNKS_GENERATION_INDEX": "c434b3a4acdad499cf3b9f170d9f9967b8e3e8218c829db99f3ecba3b53c8b5d","CONTENT_CHUNKS_OCCURRENCE_GENERATION_INDEX": "b4f73db97ad878ef7256128ddef83fd11e2e08fd215e389d9e921a0daf04853d","CONTENT_CHUNKS_OCCURRENCE_INDEX": "7b692ba777b30399ab5a3b100eb40b3b9d1b3fb2322dc4dc808ba8a4d667912c",- "DEFINER_GUARDS": "f4ab795c899067c4ef39d5efc2d16a0fa3076359dd53cef61aa61274f3232f38",- "DERIVATION_GUARD_GATE_SQL": "45a722bb5e8338f16008c09775a9ce61d80af662c22f98f48796c68bc8ca1803",- "DERIVATION_GUARD_TRIGGER_SQL": "fabef9b0a794796aaa9b1f0fc3cac12b3ddc19e285f3b1a5580803c7d9b297ae",+ "DEFINER_GUARDS": "5f44654b4ac1202d60368f05ed7736bedcec5267673d42ee4b6b9fff8cff2106",+ "DERIVATION_STORED_GUARD_SQL": "df2f7a46d7c8a364c4e5ae208f4d8830b976b3f2aeca6f21667517bc9810b66d","EXEMPT_RE": "e8b623114f4f77fc3abcfc479abec1442dbf41bc607e046d124b44572d59953c","FACTS_SUPERSEDED_BY_INDEX": "555c2b267989359a078de0f82cea830584bc0a268be6796bf526c0a9bed45905","FACT_PURGES_ALL_SUBJECTS_INDEX": "99e2eb6c24134b539cb4cfd6e5ff66a724463525d09e9ba1fdde3c13f5787b6c",@@ -52,7 +51,7 @@"TABLES": "3fc77a0fccb525f9b791098f9eae27b19adaa3f5dadbabcff2a719137cbc3ef8","TOKEN_TTL_MAX_SECONDS": "f4a45bec6ec0bacc859dc57732ceb76cec7eb72f242b5a6c89d47190d0525ab4","TOKEN_TTL_MIN_SECONDS": "441d8ce6bd21f753de90abd3013eaa9992a469ea60c590f1005533618199aa25",- "TRIGGERS": "0582df7f12b7baa3f675d8459d2ed809880a7a8fa65658c7b625e3973194a8f3",+ "TRIGGERS": "ce913384dc4209f35654ecb53e29d5a7bdefeba8a4a824e0ad49ce9dae7c6ef4","analyzeAfterIndexBuild": "8d627df6b496e1c197a244f8519aeaf3aebcd23e3f7cf514576d453a4270e33a","analyzeDeferred": "e627ca5e77ce0b79cf5eae7c749a0c9275f04bc186704e3f3a6e05121bb78442","analyzeYieldingToVacuum": "edba1beff1547ea5c2e9f902efe44ab24e8d7016b2253603dcbba92d4137ca9a",@@ -69,7 +68,7 @@"ensureFactsFtsIndex": "95e723314ac30cea2db48e0e167c554ef1fa06df80cae765faa2a080a3a655c2","getFtsLanguage": "0d790b4c4af1f67a2a1bbd59470beb13f434917b381931baf8404a41c5d903db","grantFromRow": "2d0603bb0f964d7e45e04aa76bac54cd4f6f63c91a8d9f028b60b4792bc1695e",- "hardenGuards": "e4320bb6e10670023d441b4c9357305b20ed422fdfcfcadfc4e836ba8941e442",+ "hardenGuards": "40fecc92694e291f65a78492e33e6647c49d1a9222167739c7d8e27a1c7adfde","hnswMaxDimsForType": "a187cdcc520f813b7c39da97ce53da58509232ed9f851627ef41abfe1b68bd26","inShortTransaction": "366c67944d8aeb6b71450da05259a0fa5005fa8f6ec6091671f3c78a682db216","isLockTimeoutError": "52a3720e1ffb74ce381cc3269f78130c38a89c807e308283ec3d557bae2b89b1",@@ -4408,8 +4407,8 @@"idempotent": true,"name": "segment_derivations","sql": {- "length": 7699,- "sha256": "15dde68619705e562fa89cd5ebcd58571e0a05af4e48bca1b05231a0c5e65603"+ "length": 9373,+ "sha256": "cae7c94cd835c6cc15c027d7f85ac41b0f9b01c143d8e7d273f2229b0db10aa6"},"sqlFor": "absent","transaction": false,@@ -4462,8 +4461,7 @@"helpers": ["AFTER_ROW_PURGE_TRIGGERS","DEFINER_GUARDS",- "DERIVATION_GUARD_GATE_SQL",- "DERIVATION_GUARD_TRIGGER_SQL",+ "DERIVATION_STORED_GUARD_SQL","FUNCTION_SEARCH_PATH_HARDENING_SQL","LEGACY_SEARCH_PATH_SETTINGS","TRIGGERS",diff --git a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.jsonindex 8b74ba252c..407e113253 100644--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json@@ -542,7 +542,6 @@"gbrain_advance_page_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2a431195dc4c4150e3428251d0dec0a685cdc2992525c1b4b54dff103d5d99c9","gbrain_advance_tag_revision()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7807b26b4933148aa63c67fca824a60d3492396728205d04e16c48c81174cbd5","gbrain_bump_trust_generation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4708a89d166ac0999a8922ad8ee8f69fea3213c59e0782d96220f93b0c001a62",- "gbrain_caller_sees_page(page integer)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea0448d6c5e86f513bcfa6072042f97cb07e64d6559bfc9d0df1a9d21689a62e","gbrain_clear_atom_page_state()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7db0ef05d1220a579e64428b2dd7cf5183191da186fbe64b6496433a7a713d11","gbrain_count_git_canonical_sources()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ef162804d8f0946d3df6209096567f0ca4255e02fceeee0adc8e52c47806d6a0","gbrain_count_modifications()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=9518c925621def19cafb2918da4d41e602ce94619af872eafa3c11b46c66296f",@@ -564,7 +563,8 @@"gbrain_refuse_purged_fact()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=d1d584b91ceea7f4e63c235b790ef89c958c578e635f77ddd644918bc36d33f1","gbrain_refuse_purged_page()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=8aaaf7c22fc9acb4b1e84fe75f11ae6c889949b78de1ef6bdba1db54ef43844e","gbrain_refuse_purged_take()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=4a291b0448ab7a31926aa482b5222e0595d31a6bfad81b851b13e4bf581a0d83",- "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0d0afb3e61857f1668f2e7996da1c6aaf269aecaa1bf3763ce90df90e2d66fd3",+ "gbrain_refuse_stored_purging_derivation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=true config=[search_path=pg_catalog, public, pg_temp] body_sha256=3f11d09c3b95ae5a066c240caec9a7b068cf206b3ed350420e84cc379ab1cf8a","gbrain_require_managed_writer()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ae9883e69ac3121bc07689f68518c1d97a02a2788a64e496a26f12720300fe8a","gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=7452350236ed4c68a6cd1f4d78a1381a4ef44cc70e8a032141f01bba4a704702",@@ -4331,7 +4331,8 @@"page_body_manifest.page_body_manifest_derivation_scope_delete": "CREATE TRIGGER page_body_manifest_derivation_scope_delete AFTER DELETE ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_body_manifest.page_body_manifest_derivation_scope_retire": "CREATE TRIGGER page_body_manifest_derivation_scope_retire AFTER UPDATE OF gen_to ON public.page_body_manifest FOR EACH ROW WHEN (((old.gen_to IS NULL) AND (new.gen_to IS NOT NULL) AND (old.staging_id IS NULL))) EXECUTE FUNCTION gbrain_mark_derivation_scope_entry()","page_purges.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.page_purges DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",- "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW WHEN (gbrain_caller_sees_page(new.page_id)) EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_purging": "CREATE TRIGGER page_segment_derivations_refuse_purging BEFORE INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_purging_derivation()",+ "page_segment_derivations.page_segment_derivations_refuse_stored_purging": "CREATE TRIGGER page_segment_derivations_refuse_stored_purging AFTER INSERT OR UPDATE OF output, receipt ON public.page_segment_derivations FOR EACH ROW EXECUTE FUNCTION gbrain_refuse_stored_purging_derivation()","page_segment_texts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.page_segment_texts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","page_versions.page_versions_trust_snapshot": "CREATE TRIGGER page_versions_trust_snapshot BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_snapshot_version_trust()","page_versions.page_versions_write_attribution": "CREATE TRIGGER page_versions_write_attribution BEFORE INSERT ON public.page_versions FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_version_attribution()",diff --git a/test/fixtures/goldens/pglite-upgrade-replay/repeat-boot-recreated-objects.json b/test/fixtures/goldens/pglite-upgrade-replay/repeat-boot-recreated-objects.jsonindex 95298c8314..bb845117ed 100644--- a/test/fixtures/goldens/pglite-upgrade-replay/repeat-boot-recreated-objects.json+++ b/test/fixtures/goldens/pglite-upgrade-replay/repeat-boot-recreated-objects.json@@ -7,6 +7,7 @@"trg:page_body_manifest.page_body_manifest_derivation_scope_delete","trg:page_body_manifest.page_body_manifest_derivation_scope_retire","trg:page_segment_derivations.page_segment_derivations_refuse_purging",+ "trg:page_segment_derivations.page_segment_derivations_refuse_stored_purging","trg:page_segment_texts.managed_writer_guard","trg:pages.bump_page_generation_clock_trg","trg:pages.bump_page_generation_trg",diff --git a/test/guard-definer-pglite.test.ts b/test/guard-definer-pglite.test.tsindex 7cf2678191..513e498002 100644--- a/test/guard-definer-pglite.test.ts+++ b/test/guard-definer-pglite.test.ts@@ -1,7 +1,7 @@/*** #7632 on PGLite: one role, so the guards read every ledger row either way, but the catalog matches Postgres (the- * guards are definers with pg_temp last on their path, the raising guard triggers fire AFTER ROW, the derivation guard is- * gated, every pinned search_path ends in pg_temp) and an AFTER ROW guard still refuses the write in the same statement.+ * guards are definers with pg_temp last on their path, the raising guard triggers fire AFTER ROW, the derivation guard's+ * BEFORE ROW drop is joined by its AFTER ROW check, every pinned search_path ends in pg_temp) and an AFTER ROW guard still refuses the write in the same statement.*/import { afterAll, beforeAll, describe, expect, test } from 'bun:test';import { PGLiteEngine } from '../src/core/pglite-engine.ts';@@ -24,15 +24,16 @@ describe('purge and withdrawal guard catalog on PGLite (#7632)', () => {expect(rows).toEqual([...DEFINER_GUARDS].map(g => g.fn).sort().map(fn => ({ fn, secdef: true, config: [`search_path=${GUARD_SEARCH_PATH}`], public_execute: false })));});- test('the raising guards fire AFTER ROW and the derivation guard is gated on the writer seeing the page', async () => {- const rows = await engine.executeRaw<{ trigger: string; timing: string; gated: boolean }>(- `SELECT tgname AS trigger, CASE WHEN (tgtype & 2) <> 0 THEN 'BEFORE' ELSE 'AFTER' END AS timing, pg_get_triggerdef(oid) LIKE '%WHEN (gbrain_caller_sees_page(new.page_id))%' AS gated- FROM pg_trigger WHERE NOT tgisinternal AND tgname IN ('facts_refuse_purged', 'takes_refuse_purged', 'pages_refuse_purged', 'page_segment_derivations_refuse_purging') ORDER BY 1`);+ test('the raising guards fire AFTER ROW and the derivation guard drops BEFORE ROW and checks AFTER ROW', async () => {+ const rows = await engine.executeRaw<{ trigger: string; timing: string }>(+ `SELECT tgname AS trigger, CASE WHEN (tgtype & 2) <> 0 THEN 'BEFORE' ELSE 'AFTER' END AS timing FROM pg_trigger WHERE NOT tgisinternal+ AND tgname IN ('facts_refuse_purged', 'takes_refuse_purged', 'pages_refuse_purged', 'page_segment_derivations_refuse_purging', 'page_segment_derivations_refuse_stored_purging') ORDER BY 1`);expect(rows).toEqual([- { trigger: 'facts_refuse_purged', timing: 'AFTER', gated: false },- { trigger: 'page_segment_derivations_refuse_purging', timing: 'BEFORE', gated: true },- { trigger: 'pages_refuse_purged', timing: 'AFTER', gated: false },- { trigger: 'takes_refuse_purged', timing: 'AFTER', gated: false },+ { trigger: 'facts_refuse_purged', timing: 'AFTER' },+ { trigger: 'page_segment_derivations_refuse_purging', timing: 'BEFORE' },+ { trigger: 'page_segment_derivations_refuse_stored_purging', timing: 'AFTER' },+ { trigger: 'pages_refuse_purged', timing: 'AFTER' },+ { trigger: 'takes_refuse_purged', timing: 'AFTER' },]);});