Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(e2e): core-memory lock topology step retries write_pending with the same request_id

garrytana0b3b0474314
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a6c64e550..fb5bc91c9a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,8 @@ gbrain now warms PowerShell once per process before the protection step: a trivi
| First backup on a cold Windows machine (PowerShell start over 15 s) | Fails with `private_backup_path_unavailable` | Succeeds |
| PowerShell that hangs during protection | Fails after one 15 s launch | Fails after one 15 s launch (unchanged) |
+The `core-memory-locks-postgres` E2E test also stops failing intermittently: its source-topology step could wait out its 1-second lock limit behind 18 concurrent core writes and report the retryable `write_pending`, which the test did not retry. It now retries with the same `request_id`, as that error's fix text says. The deadlock and commit-count assertions are unchanged.
+
## To take advantage of v0.60.111.0
`gbrain upgrade` installs the binary. There are no schema migrations.
diff --git a/test/e2e/core-memory-locks-postgres.test.ts b/test/e2e/core-memory-locks-postgres.test.ts
index 376c039ed6..ceedb2fc07 100644
--- a/test/e2e/core-memory-locks-postgres.test.ts
+++ b/test/e2e/core-memory-locks-postgres.test.ts
@@ -36,13 +36,17 @@ async function writer(engine: BrainEngine) {
}
// topologyTransaction takes publication capacity without waiting and throws the retryable
-// writer_pool_capacity when the concurrent writes hold every slot; a caller retries it.
-async function retryOnPoolCapacity<T>(run: () => Promise<T>): Promise<T> {
+// writer_pool_capacity when the concurrent writes hold every slot. Under the same contention its
+// 1 s lock_timeout can expire behind the core writes' brain-row share locks, which it reports as
+// the retryable write_pending ("Retry the same lifecycle request_id"). A caller retries both with
+// the same request_id; a deadlock or any other error still fails the test.
+async function retryTopology<T>(run: (requestId: string) => Promise<T>): Promise<T> {
+ const requestId = randomUUID();
for (let attempt = 1; ; attempt++) {
try {
- return await run();
+ return await run(requestId);
} catch (error) {
- if ((error as { code?: string }).code !== 'writer_pool_capacity' || attempt >= 40) throw error;
+ if (!['writer_pool_capacity', 'write_pending'].includes((error as { code?: string }).code ?? '') || attempt >= 40) throw error;
await new Promise(r => setTimeout(r, 50 * Math.min(attempt, 10)));
}
}
@@ -61,8 +65,8 @@ describeE2E('core memory ordered source lock (Postgres)', () => {
}
const probe = join(root, '..', 'probe'); mkdirSync(probe);
const topology = (async () => {
- await retryOnPoolCapacity(() => runManagedSourceLifecycle(engine, { operation: 'add', sourceId: 'probe', path: probe }));
- return retryOnPoolCapacity(() => runManagedSourceLifecycle(engine, { operation: 'remove', sourceId: 'probe', confirmDestructive: true }));
+ await retryTopology(requestId => runManagedSourceLifecycle(engine, { operation: 'add', sourceId: 'probe', path: probe, requestId }));
+ return retryTopology(requestId => runManagedSourceLifecycle(engine, { operation: 'remove', sourceId: 'probe', confirmDestructive: true, requestId }));
})();
const results = await Promise.all(writes);
await topology;