Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(sync): the write-stream probe boots its writer before the drain starts

time-attackc73c5bc71bc7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1082672d3..2422dfd979 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,7 @@ Efficiency wave 9 (GBRA-75). Base is master at wave 8 (310371559). Measured on 4
- Tests:
- `persistence-git-coalescing-5530.slow.test.ts` and its Postgres twin add two cases. A write behind six full groups, sent while one is committing, must publish within the wait with at most the in-flight group ahead of it; this fails on base on both engines. A write that finds the worktree locked is requeued as `writer_busy` with no claim phase.
- `persistence-bounded-read-session.test.ts` has 7 cases: sequencing, bound refresh, rollback and retry, joining a run's session, prepared reads, the PGLite and no-permit paths, a real lock wait that ends at its bound with nothing left running, and a re-sync. On the re-sync, base runs 101 bounded transactions for 8 files and the branch runs 16.
+ - `managed-sync-foreground-priority.test.ts` (Postgres arm) flake fixed. "a stream of writes from another process" now boots and connects its writer process before the drain starts. Before, the drain's lead depended on how fast a cold process started, so a slow runner could commit most groups before the first write. Forcing a 600 ms boot fails the old test 4 of 4 times and passes the new one 4 of 4.
- Crash robot: 600 s on each engine, every seam, with PgBouncer and `pooler_disconnect` on Postgres.
## [0.60.146.0] - 2026-10-10
diff --git a/test/fixtures/foreground-put-page-worker.ts b/test/fixtures/foreground-put-page-worker.ts
index 3dfc77d0a2..96928ef404 100644
--- a/test/fixtures/foreground-put-page-worker.ts
+++ b/test/fixtures/foreground-put-page-worker.ts
@@ -4,7 +4,8 @@
* Env: WORKER_DATABASE_URL, WORKER_SOURCE, WORKER_SLUGS (comma-separated, one
* put_page each, in order; with WORKER_GO, the go file's content instead), WORKER_INTERVAL_MS (gap between writes; 0 = back to
* back), WORKER_OUT (JSON results), WORKER_GO (optional: a file whose creation starts the writes, so a
- * test can start the process ahead and write at a chosen moment). GBRAIN_HOME is the drain's, so both processes
+ * test can start the process ahead and write at a chosen moment), WORKER_READY (optional: a file this process creates once
+ * connected, so a test can wait out its startup before the moment it measures). GBRAIN_HOME is the drain's, so both processes
* are the same local writer on the same owner host. WORKER_PREPARING_HOLD_MS (optional): when this process claims its
* own write, its preparation waits that long first (results record `held: [start, end]`), so the write stays claimed
* by this process, unpublished, while the drain's lanes hold the worktree.
@@ -22,6 +23,7 @@ let admittedAt: number | undefined;
const postgres = new PostgresEngine();
const engine = observeAdmissionTransactions(postgres, () => { admittedAt ??= Date.now(); });
await postgres.connect({ database_url: process.env.WORKER_DATABASE_URL!, poolSize: 4 });
+if (process.env.WORKER_READY) writeFileSync(process.env.WORKER_READY, '1');
const sourceId = process.env.WORKER_SOURCE!;
const interval = Number(process.env.WORKER_INTERVAL_MS ?? '0');
const results: Array<{ slug: string; state: string; error?: string; submitted: number; returned: number; admitted?: number; held?: [number, number] }> = [];
diff --git a/test/managed-sync-foreground-priority.test.ts b/test/managed-sync-foreground-priority.test.ts
index 5dbbc6ce02..9f7f6fc03e 100644
--- a/test/managed-sync-foreground-priority.test.ts
+++ b/test/managed-sync-foreground-priority.test.ts
@@ -6,7 +6,7 @@
*/
import { afterAll, beforeAll, expect, test } from 'bun:test';
import { randomUUID } from 'node:crypto';
-import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { execFileSync } from 'node:child_process';
@@ -61,10 +61,10 @@ function recordClaims(e: BrainEngine): { claims: Map<string, number>; restore: (
} as BrainEngine['executeRaw'];
return { claims, restore: () => { e.executeRaw = execute; } };
}
-function writer(source: string, slugs: string[], intervalMs = 0, go?: string, preparingHoldMs = 0) {
+function writer(source: string, slugs: string[], intervalMs = 0, go?: string, preparingHoldMs = 0, ready?: string) {
const out = join(home, `worker-${randomUUID()}.json`);
const child = Bun.spawn([process.execPath, join(import.meta.dir, 'fixtures', 'foreground-put-page-worker.ts')], { stdin: 'ignore', stdout: 'pipe', stderr: 'pipe',
- env: { ...process.env, GBRAIN_HOME: home, WORKER_DATABASE_URL: databaseUrl, WORKER_SOURCE: source, WORKER_SLUGS: slugs.join(',') || '-', WORKER_INTERVAL_MS: String(intervalMs), WORKER_OUT: out, ...(go ? { WORKER_GO: go } : {}),
+ env: { ...process.env, GBRAIN_HOME: home, WORKER_DATABASE_URL: databaseUrl, WORKER_SOURCE: source, WORKER_SLUGS: slugs.join(',') || '-', WORKER_INTERVAL_MS: String(intervalMs), WORKER_OUT: out, ...(go ? { WORKER_GO: go } : {}), ...(ready ? { WORKER_READY: ready } : {}),
...(preparingHoldMs ? { WORKER_PREPARING_HOLD_MS: String(preparingHoldMs) } : {}) } });
return async () => {
const [stderr, code] = await Promise.all([new Response(child.stderr).text(), child.exited]);
@@ -225,9 +225,15 @@ test('a stream of writes from another process still lets the drain publish a gro
if (!engine) return;
resetWriteSwitches();
const e = engine, source = await fixture(e, 64);
+ // The writer process boots and connects before the drain starts, so the stream begins right after the first group
+ // commits instead of whenever a cold process gets going (by then a fast drain can have committed most of its groups).
+ const go = join(home, `go-${randomUUID()}`), ready = join(home, `ready-${randomUUID()}`);
+ const finish = writer(source, [], 0, go, 0, ready);
+ await until(async () => existsSync(ready));
const drain = performSync(e, { sourceId: source, noPull: true, noEmbed: true, noExtract: true, drain: true, lanes: 2 });
await until(async () => (await rows(e, source)).some(row => row.state === 'committed' && row.kind === 'managed_sync_import'));
- const written = await writer(source, Array.from({ length: 12 }, (_, i) => `notes/stream-${i}`))();
+ writeFileSync(go, Array.from({ length: 12 }, (_, i) => `notes/stream-${i}`).join(','));
+ const written = await finish();
const result = await drain;
expect(written.map(write => write.state)).toEqual(written.map(() => 'committed'));
expect(result.status).toBe('first_sync');