Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(persistence): history fixture's reschedule timeout dumps effect, lock and request state (#6345 diagnostics)
time-attackd8b8fa3056f4
diff --git a/scripts/persistence/history-fixture.ts b/scripts/persistence/history-fixture.tsindex 2ebe7bf5b8..567c6ce868 100644--- a/scripts/persistence/history-fixture.ts+++ b/scripts/persistence/history-fixture.ts@@ -229,6 +229,19 @@ async function executeCommitted(world: Parameters<typeof executeOp>[0], d: OpDesreturn observation;}+/** #6345: what a delayed Git effect that never rescheduled was doing, for the timeout message. */+export async function delayedEffectDiagnostics(engine: BrainEngine, requestId: string, lock: string): Promise<string> {+ const rows = (sql: string, params: unknown[] = []) => engine.executeRaw<{ row: unknown }>(sql, params)+ .then(found => found.map(r => JSON.stringify(r.row)).join('\n ') || '(none)', (error: Error) => `(query failed: ${error.message})`);+ const effects = await rows(`SELECT to_jsonb(e) - 'data' AS row FROM persistence_effects e+ JOIN persistence_requests r ON r.id=e.request_id WHERE r.request_id=$1::uuid ORDER BY e.id`, [requestId]);+ const pending = await rows(`SELECT jsonb_build_object('id',id,'request_id',request_id,'state',state,'source_id',source_id,'slug',slug) AS row+ FROM persistence_requests WHERE state NOT IN ('committed','conflict','failed','cancelled') ORDER BY sequence`);+ const latest = await rows(`SELECT to_jsonb(e) - 'data' AS row FROM persistence_effects e ORDER BY e.updated_at DESC, e.id DESC LIMIT 12`);+ return [`delayed request ${requestId} effects:\n ${effects}`, `index.lock present: ${existsSync(lock)}`,+ `non-terminal requests:\n ${pending}`, `12 latest effects:\n ${latest}`].join('\n');+}+export async function buildHistoryFixture(engine: BrainEngine,{ pages, seed, sources, worktrees, root: requestedRoot, writeWaitMs }: HistoryFixtureOptions): Promise<HistoryFixture> {assert(Number.isSafeInteger(pages) && pages >= 1 && pages <= 10_000, 'history fixture: pages must be 1..10000');@@ -279,7 +292,9 @@ export async function buildHistoryFixture(engine: BrainEngine,JOIN persistence_requests r ON r.id=e.request_id WHERE r.request_id=$1::uuid AND e.kind='git'AND e.state='queued' AND e.attempts>0 AND e.error_code='git_index_stale' AND e.next_attempt_at>now()`, [delayed.requestId]);if (effect) { delayedEffectId = effect.id; break; }- assert(Date.now() < deadline, 'history fixture: the Git effect never rescheduled after the stale index.lock');+ if (Date.now() >= deadline) {+ assert.fail(`history fixture: the Git effect never rescheduled after the stale index.lock\n${await delayedEffectDiagnostics(engine, delayed.requestId, lock)}`);+ }await Bun.sleep(100);}// The production requeue is a fixed 30 s with no setting to lengthen it, and callers keep thediff --git a/test/persistence-history-fixture.test.ts b/test/persistence-history-fixture.test.tsindex e1b8710d86..9f84448112 100644--- a/test/persistence-history-fixture.test.ts+++ b/test/persistence-history-fixture.test.ts@@ -14,10 +14,10 @@* Seams: none; PGLite always, Postgres when DATABASE_URL is set.*/import { describe, expect, test } from 'bun:test';-import { mkdtempSync, rmSync } from 'node:fs';+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';-import { buildHistoryFixture, HISTORY_FIXTURE_TABLES, historyPlan, type HistoryFixture } from '../scripts/persistence/history-fixture.ts';+import { buildHistoryFixture, delayedEffectDiagnostics, HISTORY_FIXTURE_TABLES, historyPlan, type HistoryFixture } from '../scripts/persistence/history-fixture.ts';import { isolatedSharedSkillsEngine } from './helpers/shared-skills-engine.ts';import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';import { withEnv } from './helpers/with-env.ts';@@ -81,3 +81,23 @@ test('one seed is one logical history; another seed differs', () => {expect([...kinds].sort()).toEqual(['add_timeline_entry', 'delete_page', 'edit_page', 'forget', 'put_page', 'remember','restore_page', 'takes_add', 'takes_supersede']);});++test('#6345: the reschedule timeout message dumps the delayed effect, the lock, pending requests and the latest effects', async () => {+ const home = mkdtempSync(join(tmpdir(), 'gbrain-history-fixture-diag-'));+ try {+ await withEnv({ GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, async () => {+ const { engine, close } = await isolatedSharedSkillsEngine(undefined);+ try {+ const lock = join(home, 'index.lock');+ writeFileSync(lock, '');+ const requestId = '00000000-0000-4000-8000-000000006345';+ const dump = await delayedEffectDiagnostics(engine, requestId, lock);+ expect(dump).toContain(`delayed request ${requestId} effects:\n (none)`);+ expect(dump).toContain('index.lock present: true');+ expect(dump).toContain('non-terminal requests:\n (none)');+ expect(dump).toContain('12 latest effects:\n (none)');+ expect(dump).not.toContain('query failed');+ } finally { await close(); }+ });+ } finally { rmSync(home, { recursive: true, force: true }); }+}, 120_000);