Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

The lock-wait sync test says why a page failed when it fails (#9423)

Garry Tan1c3428a26f4c
diff --git a/changelog.d/capy-lock-wait-e2e-failure-detail.md b/changelog.d/capy-lock-wait-e2e-failure-detail.md
new file mode 100644
index 0000000000..07d9a34dcf
--- /dev/null
+++ b/changelog.d/capy-lock-wait-e2e-failure-detail.md
@@ -0,0 +1,6 @@
+**Two sync tests are easier to trust: one no longer fails on a busy runner, and the other says why a page failed when it fails.** Neither changes what it checks.
+
+### Tests
+
+- `test/sync-pass-reader-gaps-6712.test.ts`: the delegated-deadline test slept on the real clock and then checked the deadline 50 ms before it expired, so a runner that woke a timer 50 ms late failed it (seen once on CI, 5 of 5 passes locally). It now drives `setTimeout` and `performance.now` with Bun's fake timers, with the same 600 ms deadline, 400 ms window and 450, 350 and 500 ms steps. A probe that stalls the event loop for 60 ms after the first slice fails the old test and passes the new one. A probe that stops a committing slice from extending the deadline still fails the new one.
+- `test/e2e/persistence-preparation-lock-wait-postgres.test.ts`: when the drain doesn't end `synced`, the test prints every page that didn't commit. For a page that failed with `storage_error`, that printout carried only the generic public message, so a CI failure (one page, `storage_error`, while the test held its lock) couldn't be traced: it passed 44 of 44 times locally, 24 of them with four copies running at once. The printout now includes each page's recorded failure detail (the error class, the database error text, the statement and the source frame), so the next failure names its cause.
diff --git a/test/e2e/persistence-preparation-lock-wait-postgres.test.ts b/test/e2e/persistence-preparation-lock-wait-postgres.test.ts
index f2f0ffda37..57125cef2c 100644
--- a/test/e2e/persistence-preparation-lock-wait-postgres.test.ts
+++ b/test/e2e/persistence-preparation-lock-wait-postgres.test.ts
@@ -66,9 +66,9 @@ async function fixture(e: BrainEngine, count: number) {
await e.executeRaw('UPDATE persistence_brain SET enabled=true WHERE singleton=1');
return { id, root };
}
-type ImportRow = { slug: string; state: string; blocked_reason: string | null; error_code: string | null; preparation_attempts: number; error_message: string | null };
+type ImportRow = { slug: string; state: string; blocked_reason: string | null; error_code: string | null; preparation_attempts: number; error_message: string | null; error_detail?: unknown };
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]);
+ `SELECT slug,state,blocked_reason,error_code,preparation_attempts,error_message,error_detail 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,deleted_at FROM pages WHERE source_id=$1 AND ';
/** The lock holder: another session holding `pages` ACCESS EXCLUSIVE in an open transaction until `drop()`. */
@@ -186,7 +186,7 @@ describe.skipIf(!hasDatabase())('a lock-blocked preparation read ends at the bud
// The root was free: the same member and every page committed once the lock dropped, and the counter reset on commit.
if (result.drain?.outcome !== 'synced') {
const uncommitted = (await imports(engine, f.id)).filter(row => row.state !== 'committed')
- .map(({ slug, state, error_code, error_message }) => ({ slug, state, error_code, error_message }));
+ .map(({ slug, state, error_code, error_message, error_detail }) => ({ slug, state, error_code, error_message, error_detail }));
console.error(`[lock-wait] drain ${JSON.stringify(result.drain)}; rows not committed: ${JSON.stringify(uncommitted)}`);
}
expect(result.drain).toMatchObject({ outcome: 'synced' });
diff --git a/test/sync-pass-reader-gaps-6712.test.ts b/test/sync-pass-reader-gaps-6712.test.ts
index 7373f24de6..7764383cc9 100644
--- a/test/sync-pass-reader-gaps-6712.test.ts
+++ b/test/sync-pass-reader-gaps-6712.test.ts
@@ -10,7 +10,7 @@
* index advanced; GBRA-133 PR 3a: a pass that only settled paths (screened them unchanged) is not progress.
* Synthetic content only.
*/
-import { afterEach, describe, expect, test } from 'bun:test';
+import { afterEach, describe, expect, jest, test } from 'bun:test';
import { execFileSync } from 'node:child_process';
import { mkdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
@@ -58,18 +58,20 @@ describe('#6712 PR 4b lane C: cursor readers on the pass', () => {
test('a delegated deadline extends while the owner\'s passes commit pages, and stops once they settle paths without committing', async () => {
const lines: string[] = [];
+ // Fake timers drive setTimeout and performance.now together, so the 50 ms margin below is exact, not a runner's scheduling slack.
+ jest.useFakeTimers();
// A 600 ms deadline with a 400 ms progress window: a slice that commits a page at 450 ms carries the run past 600 ms (to 850 ms).
const deadline = new DelegatedSyncDeadline(600, 400, line => lines.push(line));
try {
- await new Promise(resolve => setTimeout(resolve, 450));
+ jest.advanceTimersByTime(450);
deadline.noteSlice(passResult(3, 5));
- await new Promise(resolve => setTimeout(resolve, 350));
+ jest.advanceTimersByTime(350);
expect(deadline.stop.signal.aborted).toBe(false);
expect(lines.join('\n')).toContain('still progressing');
// GBRA-133 PR 3a: this slice settled paths but committed none (screened unchanged): no extension.
deadline.noteSlice({ ...passResult(3, 2), added: 0 });
- await new Promise(resolve => setTimeout(resolve, 500));
+ jest.advanceTimersByTime(500);
expect(deadline.stop.signal.aborted).toBe(true);
- } finally { deadline.dispose(); }
+ } finally { deadline.dispose(); jest.useRealTimers(); }
});
});