Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: keep published migration v278 byte for byte; the current request guard is REQUEST_PROTOCOL_GUARD_V287_SQL

garrytan292090dd5381
diff --git a/src/core/schema-migrations/v278-writer-fence-fail-closed.ts b/src/core/schema-migrations/v278-writer-fence-fail-closed.ts
index b81c5b614e..07a0bd6bed 100644
--- a/src/core/schema-migrations/v278-writer-fence-fail-closed.ts
+++ b/src/core/schema-migrations/v278-writer-fence-fail-closed.ts
@@ -2,7 +2,7 @@ import type { Migration } from './types.ts';
import { GIT_CANONICAL_COUNT_FUNCTION_SQL } from '../persistence/git-canonical-schema.ts';
import { MANAGED_WRITER_GUARD_FUNCTION_SQL } from '../persistence/writer-guard-schema.ts';
import {
- EFFECT_PROTOCOL_GUARD_SQL, PROTOCOL_ACTIVATION_GUARD_SQL, REQUEST_PROTOCOL_GUARD_V278_SQL,
+ EFFECT_PROTOCOL_GUARD_SQL, PROTOCOL_ACTIVATION_GUARD_SQL, REQUEST_PROTOCOL_GUARD_SQL,
} from '../shared-skills/persistence-schema.ts';
// Applied by src/core/migrate.ts on the next initSchema(); see docs/ENGINES.md
@@ -27,6 +27,6 @@ export const v278: Migration = {
version: 278,
name: 'writer_fence_fail_closed',
idempotent: true,
- sql: [MANAGED_WRITER_GUARD_FUNCTION_SQL, GIT_CANONICAL_COUNT_FUNCTION_SQL, REQUEST_PROTOCOL_GUARD_V278_SQL,
+ sql: [MANAGED_WRITER_GUARD_FUNCTION_SQL, GIT_CANONICAL_COUNT_FUNCTION_SQL, REQUEST_PROTOCOL_GUARD_SQL,
EFFECT_PROTOCOL_GUARD_SQL, PROTOCOL_ACTIVATION_GUARD_SQL].map(sql => `${sql.trim().replace(/;$/, '')};`).join('\n'),
};
diff --git a/src/core/schema-migrations/v287-multi-page-recovery-record.ts b/src/core/schema-migrations/v287-multi-page-recovery-record.ts
index 2bfcf70ed4..91999d4188 100644
--- a/src/core/schema-migrations/v287-multi-page-recovery-record.ts
+++ b/src/core/schema-migrations/v287-multi-page-recovery-record.ts
@@ -1,5 +1,5 @@
import type { Migration } from './types.ts';
-import { REQUEST_PROTOCOL_GUARD_SQL } from '../shared-skills/persistence-schema.ts';
+import { REQUEST_PROTOCOL_GUARD_V287_SQL } from '../shared-skills/persistence-schema.ts';
export const v287: Migration = {
// GBRA-190 G4 (D2): one publication may write several pages (a withdrawal strikes its claim on every page that
@@ -10,5 +10,5 @@ export const v287: Migration = {
version: 287,
name: 'multi_page_recovery_record',
idempotent: true,
- sql: REQUEST_PROTOCOL_GUARD_SQL + ';',
+ sql: REQUEST_PROTOCOL_GUARD_V287_SQL + ';',
};
diff --git a/src/core/shared-skills/persistence-schema.ts b/src/core/shared-skills/persistence-schema.ts
index 83513689cd..6512bfd4fe 100644
--- a/src/core/shared-skills/persistence-schema.ts
+++ b/src/core/shared-skills/persistence-schema.ts
@@ -42,10 +42,10 @@ const requestProtocolGuardSql = (pageRecoveryMismatch: string): string => `CREAT
* (the page files one publication writes together, model.ts PagesRecoveryRecord), which binaries that predate it
* refuse unread (recovery-version.ts). v287 installs it.
*/
-export const REQUEST_PROTOCOL_GUARD_SQL = requestProtocolGuardSql(`record->>'version' IS DISTINCT FROM '1'
+export const REQUEST_PROTOCOL_GUARD_V287_SQL = requestProtocolGuardSql(`record->>'version' IS DISTINCT FROM '1'
AND NOT (record->>'version'='3' AND record->>'target'='pages' AND jsonb_typeof(record->'files')='array')`);
-/** The request guard as v278 shipped it (page recovery version 1 only), so that migration's SQL stays as released. */
-export const REQUEST_PROTOCOL_GUARD_V278_SQL = requestProtocolGuardSql(`record->>'version' IS DISTINCT FROM '1'`);
+/** The request guard as v278 shipped it (page recovery version 1 only), so that published migration stays byte for byte as released; the current guard is REQUEST_PROTOCOL_GUARD_V287_SQL. */
+export const REQUEST_PROTOCOL_GUARD_SQL = requestProtocolGuardSql(`record->>'version' IS DISTINCT FROM '1'`);
export const EFFECT_PROTOCOL_GUARD_SQL = `CREATE OR REPLACE FUNCTION gbrain_guard_effect_protocol() RETURNS trigger LANGUAGE plpgsql SET search_path = pg_catalog, public AS $$
DECLARE floor integer;
BEGIN
@@ -98,7 +98,7 @@ export const SHARED_SKILLS_PERSISTENCE_SCHEMA_STATEMENTS: readonly string[] = [
RAISE EXCEPTION 'writer_upgrade_required: this mutation requires persistence protocol 2' USING ERRCODE='42501';
END IF;
END $$`,
- REQUEST_PROTOCOL_GUARD_SQL,
+ REQUEST_PROTOCOL_GUARD_V287_SQL,
`DROP TRIGGER IF EXISTS gbrain_request_protocol ON persistence_requests`,
`CREATE TRIGGER gbrain_request_protocol BEFORE INSERT OR UPDATE OR DELETE ON persistence_requests
FOR EACH ROW EXECUTE FUNCTION gbrain_guard_request_protocol()`,