Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(#6143): the replay's sessions check for deadlock at 5 s and the reader's at 60 s, so a reader delayed past the default 1 s no longer becomes the victim (#7597 arms 4/12). Forced probe, reader delayed 1.5 s: 3 of 3 red before (reader 40P01), 3 of 3 green after; 4 s delay green
garrytanf6edd5e661bb
diff --git a/test/schema-replay-deadlock-6143.test.ts b/test/schema-replay-deadlock-6143.test.tsindex a0c2c248bb..c602317b6a 100644--- a/test/schema-replay-deadlock-6143.test.ts+++ b/test/schema-replay-deadlock-6143.test.ts@@ -4,9 +4,16 @@* reads pages (the resident persistence consumer's idle probe did, on the nightly arm) closes a cycle with it, and* Postgres aborts the replay with deadlock_detected. The replay rolls back whole, so initSchema runs it again.* Forced: a reader transaction takes sources, waits until the replay is queued on sources, then reads pages. Postgres only.+ *+ * Postgres runs its deadlock check once per wait, deadlock_timeout after the wait began, and the backend that finds the+ * cycle aborts itself. The replay queues first, so with the default 1 s on both sides a reader delayed past 1 s (a loaded+ * runner, #7597) left the replay's one check before the cycle existed, and the reader's own check then aborted the reader.+ * The replay's sessions check at 5 s and the reader's at 60 s, so the replay is the victim whenever the reader starts+ * waiting within 5 s, and a reader later than that still fails as a deadlock of the reader rather than a hang.*/import { describe, expect, test } from 'bun:test';import postgres from '#postgres';+import { PostgresEngine } from '../src/core/postgres-engine.ts';import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';import { testBackends } from './helpers/test-backends.ts';@@ -15,11 +22,16 @@ describe.skipIf(!testBackends().includes('postgres'))('#6143 schema replay againconst pg = await isolatedPersistencePostgres(process.env.DATABASE_URL!);const reader = postgres(pg.databaseUrl, { max: 1, onnotice: () => {} });const watcher = postgres(pg.databaseUrl, { max: 1, onnotice: () => {} });+ const engine = new PostgresEngine();try {+ await watcher.unsafe(`ALTER DATABASE "${new URL(pg.databaseUrl).pathname.slice(1)}" SET deadlock_timeout = '5s'`);+ await engine.connect({ database_url: pg.databaseUrl, poolSize: 2 });+ expect(await engine.executeRaw<{ deadlock_timeout: string }>('SHOW deadlock_timeout')).toEqual([{ deadlock_timeout: '5s' }]);let replay: Promise<unknown> | undefined;await reader.begin(async sql => {+ await sql`SET LOCAL deadlock_timeout = '60s'`;await sql`SELECT 1 FROM sources LIMIT 1`;- replay = pg.engine.initSchema().then(() => 'ok', (error: { code?: string; message?: string }) => `${error.code ?? ''} ${error.message ?? error}`);+ replay = engine.initSchema().then(() => 'ok', (error: { code?: string; message?: string }) => `${error.code ?? ''} ${error.message ?? error}`);for (let i = 0; i < 400; i++) {const [row] = await watcher<{ n: number }[]>`SELECT count(*)::int AS n FROM pg_locks WHERE NOT granted AND relation = 'sources'::regclass`;if (row!.n > 0) break;@@ -28,7 +40,7 @@ describe.skipIf(!testBackends().includes('postgres'))('#6143 schema replay againawait sql`SELECT 1 FROM pages LIMIT 1`;});expect(await replay).toBe('ok');- expect(await pg.engine.executeRaw<{ n: number }>("SELECT count(*)::int AS n FROM pg_trigger WHERE tgname = 'managed_writer_guard' AND tgrelid = 'sources'::regclass")).toEqual([{ n: 1 }]);- } finally { await reader.end(); await watcher.end(); await pg.close(); }+ expect(await engine.executeRaw<{ n: number }>("SELECT count(*)::int AS n FROM pg_trigger WHERE tgname = 'managed_writer_guard' AND tgrelid = 'sources'::regclass")).toEqual([{ n: 1 }]);+ } finally { await reader.end(); await watcher.end(); await engine.disconnect(); await pg.close(); }}, 120_000);});