Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
W1 gate: origin-check statement pins follow the deleted_at column; migrations and PGLite upgrade-replay goldens record the v240 index
garrytan8e5ab7815f18
diff --git a/docs/eval/managed-sync-stall-repro.md b/docs/eval/managed-sync-stall-repro.mdindex abe0061718..901f7b91e3 100644--- a/docs/eval/managed-sync-stall-repro.md+++ b/docs/eval/managed-sync-stall-repro.md@@ -40,7 +40,7 @@ every number below comes from those captures.`wait_event_type = Lock` / `relation`, zero committed pages, and themoment the lock lifts everything resumes. The hanging await is`assertSyncPageOrigin` in `prepareManagedSyncMutation` (step- `page_origin`): `SELECT id,slug,source_path FROM pages WHERE source_id=$1+ `page_origin`): `SELECT id,slug,source_path,deleted_at FROM pages WHERE source_id=$1AND source_path=ANY($2::text[])`, which is simply the first `pages` readafter the lock appeared; any other preparation read would block the sameway. What held or queued such a lock in the reporter's environment is not@@ -463,7 +463,7 @@ the drain's owner-pid fix. Captures under `stall-lock-b/`.= $1 AND deleted_at IS NULL AND (content_hash = $2 OR …)`, fourconnections), `readPageSnapshot` (`WITH chosen AS (SELECT p.* FROM pages…)`), the `page_projections` join, and the group-memoized origin read- (`SELECT id,slug,source_path FROM pages WHERE source_id=$1 AND+ (`SELECT id,slug,source_path,deleted_at FROM pages WHERE source_id=$1 ANDsource_path=ANY($2)`, three to four connections; `preparationReads` dropsthe member's bound by design). The bound itself ran: the trace shows 2,035`BEGIN; SET LOCAL statement_timeout = 116000-120000` transactions in thediff --git a/scripts/bench/managed-sync-catchup-phases.ts b/scripts/bench/managed-sync-catchup-phases.tsindex 0197c64851..22774f6e28 100644--- a/scripts/bench/managed-sync-catchup-phases.ts+++ b/scripts/bench/managed-sync-catchup-phases.ts@@ -48,7 +48,7 @@ const SIG = {requestLookup: /^SELECT (?:\*|count\(\*\)::int AS n) FROM persistence_requests WHERE principal_kind=\$1 AND principal_id=\$2 AND request_id=(?:\$3::uuid|ANY\(\$3::uuid\[\]\))$/,foregroundCheck: /^SELECT id FROM persistence_requests WHERE worktree_id=\$1::uuid AND state IN \('queued','running','recovering'\) AND NOT\(COALESCE\(intent->>'kind',''\) LIKE 'managed_sync_%'\)/,consumerOnly: /^UPDATE persistence_requests r SET claim_expires_at=|^SELECT 1 FROM persistence_requests WHERE worktree_id=\$1::uuid AND NOT \(id=ANY/,- origin: /^SELECT id,slug,source_path FROM pages WHERE source_id=\$1 AND source_path=ANY\(/,+ origin: /^SELECT id,slug,source_path,deleted_at FROM pages WHERE source_id=\$1 AND source_path=ANY\(/,snapshot: /^WITH chosen AS \( SELECT p\.\* FROM pages p WHERE p\.slug=\$1/,writerCheck: /^SELECT lane,revoked_at,grant_ceiling FROM persistence_local_writers WHERE id=\$1::uuid$/,};diff --git a/test/bench-managed-sync-catchup.test.ts b/test/bench-managed-sync-catchup.test.tsindex cf18477ec2..cb4ae16e87 100644--- a/test/bench-managed-sync-catchup.test.ts+++ b/test/bench-managed-sync-catchup.test.ts@@ -88,7 +88,7 @@ describe('feeder', () => {test('the gap before a write-wait read is idle, gaps before cursor saves are producing', () => {const records = [...chain(-100, 1, ['SELECT completed_keys FROM op_checkpoints WHERE op=$1 AND fingerprint=$2']),- ...chain(0, 1, ['SELECT id,slug,source_path FROM pages WHERE source_id=$1 AND source_path=ANY($2::text[])', 'WITH chosen AS ( SELECT p.* FROM pages p WHERE p.slug=$1 AND p.source_id=$2 )',+ ...chain(0, 1, ['SELECT id,slug,source_path,deleted_at FROM pages WHERE source_id=$1 AND source_path=ANY($2::text[])', 'WITH chosen AS ( SELECT p.* FROM pages p WHERE p.slug=$1 AND p.source_id=$2 )','SELECT lane,revoked_at,grant_ceiling FROM persistence_local_writers WHERE id=$1::uuid']),...chain(200, 1, ['begin', 'UPDATE op_checkpoints SET completed_keys=$4::text::jsonb,updated_at=now() WHERE op=$1 AND fingerprint=$2 AND completed_keys=$3::text::jsonb', 'commit']),...chain(5000, 1, ['SELECT * FROM persistence_requests WHERE id=ANY($1::uuid[])']),diff --git a/test/e2e/persistence-preparation-deadline.e2e.test.ts b/test/e2e/persistence-preparation-deadline.e2e.test.tsindex da7a3ff9ec..4cfeddeca2 100644--- a/test/e2e/persistence-preparation-deadline.e2e.test.ts+++ b/test/e2e/persistence-preparation-deadline.e2e.test.ts@@ -56,7 +56,7 @@ async function fixture(e: BrainEngine, count: number) {}const imports = (e: BrainEngine, source: string) => e.executeRaw<{ slug: string; state: string; blocked_reason: string | null; error_code: string | null; preparation_attempts: number; error_message: string | null }>(`SELECT slug,state,blocked_reason,error_code,preparation_attempts,error_message FROM persistence_requests WHERE source_id=$1 AND intent->>'kind'='managed_sync_import' ORDER BY sequence`, [source]);-const ORIGIN_CHECK_SQL = 'SELECT id,slug,source_path FROM pages WHERE source_id=$1 AND ';+const ORIGIN_CHECK_SQL = 'SELECT id,slug,source_path,deleted_at FROM pages WHERE source_id=$1 AND ';/*** Holds the origin check of `path` open until `onHold(attempt)` resolves, then lets the statement run. The statementdiff --git a/test/e2e/persistence-preparation-lock-wait-postgres.test.ts b/test/e2e/persistence-preparation-lock-wait-postgres.test.tsindex 5584a068c8..cee2b441c1 100644--- a/test/e2e/persistence-preparation-lock-wait-postgres.test.ts+++ b/test/e2e/persistence-preparation-lock-wait-postgres.test.ts@@ -69,7 +69,7 @@ async function fixture(e: BrainEngine, count: number) {type ImportRow = { slug: string; state: string; blocked_reason: string | null; error_code: string | null; preparation_attempts: number; error_message: string | null };const imports = (e: BrainEngine, source: string) => e.executeRaw<ImportRow>(`SELECT slug,state,blocked_reason,error_code,preparation_attempts,error_message FROM persistence_requests WHERE source_id=$1 AND intent->>'kind'='managed_sync_import' ORDER BY sequence`, [source]);-const ORIGIN_CHECK_SQL = 'SELECT id,slug,source_path FROM pages WHERE source_id=$1 AND ';+const ORIGIN_CHECK_SQL = 'SELECT id,slug,source_path,deleted_at FROM pages WHERE source_id=$1 AND ';/** The lock holder: another session holding `pages` ACCESS EXCLUSIVE in an open transaction until `drop()`. */async function holdPagesLock(url: string) {diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.jsonindex 21e023ce33..5be4d2f4e5 100644--- a/test/fixtures/goldens/migrations/records.json+++ b/test/fixtures/goldens/migrations/records.json@@ -1,6 +1,6 @@{"golden": {- "count": 234,+ "count": 235,"gaps": [17,18,@@ -23,6 +23,7 @@"PERSISTENCE_COMPACTABLE_INDEX": "25ee657878efb41ba9ea3a7624464ddcf66407d861659456c230366e57f230a0","PERSISTENCE_DATABASE_PENDING_INDEX_SQL": "6e0f618be33d037454933ea4dea11438413d45aef35d3bd4f33e89624d6e199e","PERSISTENCE_EFFECT_PARKED_INDEX_SQL": "0107863883415378d7c0dce7a0cbd5311c2c5a59fc0f81917cc8b767fd235cf2",+ "PERSISTENCE_REQUEST_SLUG_INTENT_INDEX": "5f2e4a3dde452e610fe7eaae949642c00d7c61a363b1cd344d7f0917db233aa5","PERSISTENCE_SYNC_RUN_INDEXES": "e1b12613c5fd2facb850e6857b0bddcf49b2478ec258fa226fe15e71e55df9c1","PERSISTENCE_SYNC_WATERMARK_INDEX": "93523954a30e8483717f07ec97a3e0cd062b15d8a60cc759281054b06c23bb40","TOKEN_TTL_MAX_SECONDS": "f4a45bec6ec0bacc859dc57732ceb76cec7eb72f242b5a6c89d47190d0525ab4",@@ -52,7 +53,7 @@"sqlQueryForEngine": "71fb1ccec1b22cdc1662876dbd8c17ed81e9ab83485c6965cdf5caa4fc4a4ab5","verifyProjectionStatistics": "0d231b04ecfbc5a4109d6fca9567bf4e8c9e9db6c3fbbb35212e026579ed6f67"},- "latest": 239,+ "latest": 240,"records": [{"handler": {@@ -2246,8 +2247,8 @@"idempotent": true,"name": "durable_concurrent_persistence","sql": {- "length": 11594,- "sha256": "2f3633b4ae6df69183c7c3ae813a10d0bcd323d5b6ef0855f8777e671f69037b"+ "length": 11749,+ "sha256": "66065b6bd5f2c11094ff00db6ebea8d19e45bf2e395ca3aac880edea9f20b0df"},"sqlFor": "absent","transaction": "absent",@@ -3623,6 +3624,29 @@"transaction": "absent","verify": "absent","version": 239+ },+ {+ "handler": {+ "form": "arrow",+ "helpers": [+ "PERSISTENCE_REQUEST_SLUG_INTENT_INDEX",+ "buildIndexOnline",+ "dropInvalidConcurrentIndex",+ "migrationNotice",+ "quietMigrationNotices"+ ],+ "sha256": "d1c2cefa48f3a8a50282122f9ea92c472415552938f2ebf3f30b3087393ae2b7"+ },+ "idempotent": true,+ "name": "persistence_request_slug_intent_index",+ "sql": {+ "length": 0,+ "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"+ },+ "sqlFor": "absent",+ "transaction": false,+ "verify": "absent",+ "version": 240}],"versions": [@@ -3859,7 +3883,8 @@236,237,238,- 239+ 239,+ 240]},"normalizer": "migrations-record-v1"diff --git a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.jsonindex 36b7c537a1..f00c1bb8eb 100644--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json@@ -1176,6 +1176,7 @@"persistence_requests_principal_kind_principal_id_request_id_key": "CREATE UNIQUE INDEX persistence_requests_principal_kind_principal_id_request_id_key ON public.persistence_requests USING btree (principal_kind, principal_id, request_id)","persistence_requests_recovery": "CREATE INDEX persistence_requests_recovery ON public.persistence_requests USING btree (worktree_id, sequence) WHERE (recovery IS NOT NULL)","persistence_requests_sequence_key": "CREATE UNIQUE INDEX persistence_requests_sequence_key ON public.persistence_requests USING btree (sequence)",+ "persistence_requests_slug_intent": "CREATE INDEX persistence_requests_slug_intent ON public.persistence_requests USING btree (source_id, slug, sequence) WHERE ((intent IS NOT NULL) AND (NOT compacted))","persistence_requests_sync_run_committed": "CREATE INDEX persistence_requests_sync_run_committed ON public.persistence_requests USING btree (source_id, ((intent ->> 'runId'::text)), ((intent ->> 'index'::text))) WHERE ((state = 'committed'::text) AND (intent ? 'runId'::text))","persistence_requests_sync_run_open": "CREATE INDEX persistence_requests_sync_run_open ON public.persistence_requests USING btree (worktree_id, ((intent ->> 'runId'::text))) WHERE ((state <> 'committed'::text) AND ((intent ->> 'kind'::text) = ANY (ARRAY['managed_sync_import'::text, 'managed_sync_delete'::text])))","persistence_requests_sync_watermark": "CREATE INDEX persistence_requests_sync_watermark ON public.persistence_requests USING btree (worktree_id, source_incarnation, completed_at DESC) WHERE ((state = 'committed'::text) AND (COALESCE((intent ->> 'kind'::text), ''::text) ~~ 'managed_sync_%'::text))",diff --git a/test/persistence-sync-options.serial.test.ts b/test/persistence-sync-options.serial.test.tsindex 06a324243d..f85e6af0a3 100644--- a/test/persistence-sync-options.serial.test.ts+++ b/test/persistence-sync-options.serial.test.ts@@ -590,7 +590,7 @@ type SyncBarrier = 'discovery' | 'discovery-commit' | 'foreground' | 'freeze' |function matchesSyncBarrier(boundary: SyncBarrier, sql: string, params: unknown[] | undefined, transactional: boolean): boolean {if (boundary === 'discovery') return sql.startsWith('SELECT slug,source_path,id FROM pages WHERE source_id=');if (boundary === 'foreground') return sql.includes("NOT(COALESCE(intent->>'kind','') LIKE 'managed_sync_%') LIMIT 1");- if (boundary === 'freeze') return sql.startsWith('SELECT id,slug,source_path FROM pages WHERE source_id=') && !transactional;+ if (boundary === 'freeze') return sql.startsWith('SELECT id,slug,source_path,deleted_at FROM pages WHERE source_id=') && !transactional;if (boundary === 'request-lookup') return sql.startsWith('SELECT') && sql.includes('FROM persistence_requests') && sql.includes('request_id=') && !transactional;if (boundary === 'admission-commit') return sql.includes('UPDATE persistence_counters SET outstanding_count=outstanding_count+1');// A won cursor swap is the saved cursor (#5984 feeder, no read-back): the freeze transaction's last statement is its manifest touch.diff --git a/test/sync-waivers-chunk.test.ts b/test/sync-waivers-chunk.test.tsindex f0ca62c1d9..634f757874 100644--- a/test/sync-waivers-chunk.test.ts+++ b/test/sync-waivers-chunk.test.ts@@ -36,7 +36,7 @@ function fakeEngine(opts: { busySlugs?: Set<string> } = {}) {if (sql.includes('FROM persistence_source_bindings')) return [{ owner_epoch: '3' }];if (sql.startsWith('SELECT id,slug,deleted_at')) return (params[1] as string[]).map(slug => ({ id: Number(slug.slice(1)) + 1, slug, deleted: true, knowledge_revision: '7' }));if (sql === UNFINISHED_PAGE_REQUEST_SQL) { unfinishedReads++; return statement(opts.busySlugs?.has(String(params[3])) ? [{ id: 'busy' }] : []); }- if (sql.startsWith('SELECT id,slug,source_path FROM pages')) { const path = (params[1] as string[])[0]!; const i = Number(/p(\d+)\.md/.exec(path)![1]); return statement([{ id: i + 1, slug: `p${i}`, source_path: path }]); }+ if (sql.startsWith('SELECT id,slug,source_path,deleted_at FROM pages')) { const path = (params[1] as string[])[0]!; const i = Number(/p(\d+)\.md/.exec(path)![1]); return statement([{ id: i + 1, slug: `p${i}`, source_path: path }]); }throw new Error(`unexpected SQL: ${sql.slice(0, 60)}`);},};