Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge origin/master into capy/writer-fence-fail-closed

garrytanc5dc7af5f558
diff --cc src/core/schema-migrations/latest.generated.ts
index 4059749ed5,4059749ed5..6b1b446066
--- a/src/core/schema-migrations/latest.generated.ts
+++ b/src/core/schema-migrations/latest.generated.ts
@@@ -4,4 -4,4 +4,4 @@@
// The highest schema migration version (migrate.ts LATEST_VERSION), importable without
// loading the migrations themselves.
--export const LATEST_SCHEMA_VERSION = 276;
++export const LATEST_SCHEMA_VERSION = 277;
diff --cc src/core/schema-migrations/registry.generated.ts
index 86647443ad,f09d46ac19..e72f2028c7
--- a/src/core/schema-migrations/registry.generated.ts
+++ b/src/core/schema-migrations/registry.generated.ts
@@@ -276,7 -276,7 +276,8 @@@ import { v272 } from './v272-git-canoni
import { v273 } from './v273-segment-derivations.ts';
import { v274 } from './v274-pages-withheld-source-path.ts';
import { v275 } from './v275-rls-backfill-unguarded-tables.ts';
- import { v276 } from './v276-writer-fence-fail-closed.ts';
+ import { v276 } from './v276-persistence-foreground-committed-index.ts';
++import { v277 } from './v277-writer-fence-fail-closed.ts';
// Array order is historical (see HISTORICAL_ARRAY_ORDER in the generator); the
// runner sorts by version before applying.
@@@ -552,4 -552,4 +553,5 @@@ export const MIGRATIONS: Migration[] =
v274,
v275,
v276,
++ v277,
];
diff --cc src/core/schema-migrations/v277-writer-fence-fail-closed.ts
index cb5fd6c534,0000000000..d196da5ade
mode 100644,000000..100644
--- a/src/core/schema-migrations/v277-writer-fence-fail-closed.ts
+++ b/src/core/schema-migrations/v277-writer-fence-fail-closed.ts
@@@ -1,31 -1,0 +1,31 @@@
+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_SQL,
+} from '../shared-skills/persistence-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.
+//
+// #7636: the writer-protocol fences read singleton state (persistence_brain,
+// git_canonical_brain) and the sources, pages and persistence tables as the
+// writing role. A role that neither owns those tables nor bypasses RLS, with
+// write policies on a guarded table but none on the lookup, read zero rows and
+// the fence treated that as "unmanaged" or "quiesced". Init always writes both
+// singleton rows, so a missing one now raises writer_coordinator_required
+// (unreadable state), as does a page or source lookup row-level security
+// hides, the git-canonical recount under RLS on sources, and protocol
+// activation while RLS filters the tables it must see empty. An unmanaged
+// brain, the owner and any role that can read the state behave as before.
+// Replaces only the five functions: their triggers already call them, and
+// re-creating the triggers would take ACCESS EXCLUSIVE locks on the largest
+// tables. No privilege changes, no SECURITY DEFINER, no row is read or written.
+// Provisional number: renumbered at the merge slot.
- export const v276: Migration = {
- version: 276,
++export const v277: Migration = {
++ version: 277,
+ name: 'writer_fence_fail_closed',
+ idempotent: true,
+ 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 --cc test/fixtures/goldens/migrations/records.json
index b90c49297d,87a755dc51..d927307300
--- a/test/fixtures/goldens/migrations/records.json
+++ b/test/fixtures/goldens/migrations/records.json
@@@ -1,6 -1,6 +1,6 @@@
{
"golden": {
-- "count": 271,
++ "count": 272,
"gaps": [
17,
18,
@@@ -87,7 -88,7 +88,7 @@@
"verifyProjectionStatistics": "0d231b04ecfbc5a4109d6fca9567bf4e8c9e9db6c3fbbb35212e026579ed6f67",
"withSchemaLockTimeout": "95605bd3004955e11e936c7a4aa6889319b401098abf9db18ef3e48da2c3fc59"
},
-- "latest": 276,
++ "latest": 277,
"records": [
{
"handler": {
@@@ -2281,8 -2282,8 +2282,8 @@@
"idempotent": true,
"name": "durable_concurrent_persistence",
"sql": {
- "length": 15331,
- "sha256": "09717602776466f6d551f3ccc53dada977abf3e90837df80ef27b75526f994c7"
- "length": 13533,
- "sha256": "44196cf3f167069f378f222b703225d8f5348a4c72b7e72712f7963cbe259a5b"
++ "length": 15532,
++ "sha256": "d18cf500d26ac27f68e4cdeb71e9c23220c33505b6b08100377e91fcdf1a82a8"
},
"sqlFor": "absent",
"transaction": "absent",
@@@ -4446,18 -4447,34 +4447,47 @@@
"verify": "absent",
"version": 275
},
+ {
+ "handler": {
+ "form": "arrow",
+ "helpers": [
+ "PERSISTENCE_FOREGROUND_COMMITTED_INDEX",
+ "PLANNER_REPAIR_TABLES",
+ "analyzeAfterIndexBuild",
+ "analyzeDeferred",
+ "analyzeYieldingToVacuum",
+ "buildIndexOnline",
+ "dropInvalidConcurrentIndex",
+ "lockTableForAnalyze",
+ "migrationNotice",
+ "quietMigrationNotices",
+ "tableRows"
+ ],
+ "sha256": "6216cb939d9e686a3386b406051d172d78e86f55edb629f7672b9602926d0484"
+ },
+ "idempotent": true,
+ "name": "persistence_foreground_committed_index",
+ "sql": {
+ "length": 0,
+ "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+ },
+ "sqlFor": "absent",
+ "transaction": false,
+ "verify": "absent",
+ "version": 276
++ },
+ {
+ "handler": "absent",
+ "idempotent": true,
+ "name": "writer_fence_fail_closed",
+ "sql": {
+ "length": 14628,
+ "sha256": "662048ed2b30ecb75cd4bbee438564fda6533f6e647b43f82ea1cfaaadb4bb7c"
+ },
+ "sqlFor": "absent",
+ "transaction": "absent",
+ "verify": "absent",
- "version": 276
++ "version": 277
}
],
"versions": [
@@@ -4731,7 -4748,7 +4761,8 @@@
273,
274,
275,
-- 276
++ 276,
++ 277
]
},
"normalizer": "migrations-record-v1"