Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(persistence): the effect worker's contended-worktree wait is injectable, so the w5 contention scenario stops paying 7 x 5 s (#7782)

garrytanff79b25ad8a2
diff --git a/src/core/persistence/effects.ts b/src/core/persistence/effects.ts
index ea21617124..0e80e90811 100644
--- a/src/core/persistence/effects.ts
+++ b/src/core/persistence/effects.ts
@@ -90,6 +90,8 @@ export interface EffectWorkerOptions {
embedding?: { signature: string; model: string; embed: typeof embedBatch };
/** GBRA-133: owner keys the consumer proved dead (`deadOwnerClaims`); their running effects are claimed before the lease lapses. */
deadOwners?: readonly string[];
+ /** How long a pass waits for a contended worktree (default EFFECT_LOCK_WAIT_MS); production never supplies this. */
+ lockWaitMs?: number;
}
export async function selectedEffectPage(engine: BrainEngine, effect: PersistenceEffect): Promise<PageSnapshot | null> {
@@ -819,7 +821,7 @@ async function runEffectPass(engine: BrainEngine, config: GBrainConfig, opts: Ef
const path = binding.coordination_path ?? '';
if (stalled.has(path)) return acquireWorktree(binding, 0, undefined, engine);
waited.add(path);
- const lock = await acquireWorktreeWaiting(binding, engine, EFFECT_LOCK_WAIT_MS, opts.signal);
+ const lock = await acquireWorktreeWaiting(binding, engine, opts.lockWaitMs ?? EFFECT_LOCK_WAIT_MS, opts.signal);
if (!lock) stalled.add(path);
return lock;
};
diff --git a/test/helpers/w5-scenarios.ts b/test/helpers/w5-scenarios.ts
index f6b8ec049d..0513bad5eb 100644
--- a/test/helpers/w5-scenarios.ts
+++ b/test/helpers/w5-scenarios.ts
@@ -44,15 +44,15 @@ async function resetEffect(engine: BrainEngine, id: number, data: Record<string,
claim_expires_at=NULL,error_code=NULL,outcome=NULL WHERE id=$1`, [id, JSON.stringify(data)]);
});
}
-/** Runs one effect attempt at a time with every other effect deferred. */
-async function runOnly(engine: BrainEngine, ctx: OperationContext, id: number, times = 1) {
+/** Runs one effect attempt at a time with every other effect deferred; `lockWaitMs` shortens a contended worktree wait. */
+async function runOnly(engine: BrainEngine, ctx: OperationContext, id: number, times = 1, lockWaitMs?: number) {
await disposePersistenceConsumer(engine);
for (let i = 0; i < times; i++) {
await engine.transaction(async tx => {
await declarePersistenceProtocol(tx);
await tx.executeRaw("UPDATE persistence_effects SET next_attempt_at=CASE WHEN id=$1 THEN now() ELSE now()+interval '1 hour' END", [id]);
});
- await runPersistenceEffects(engine, ctx.config, { hostId: localHostId(), limit: 1 });
+ await runPersistenceEffects(engine, ctx.config, { hostId: localHostId(), limit: 1, lockWaitMs });
}
}
const gitRepo = (root: string) => { writeFileSync(join(root, '.gitignore'), '\n'); durableGitRepo(root, ['.gitignore']); };
@@ -182,7 +182,7 @@ export async function healthyScanAndContentionNeverPark(databaseUrl?: string) {
const scan = await gitEffect(engine, slugs[0]);
await resetEffect(engine, scan.id, { source_scan: true });
const lock = await acquireWorktree((await getWorktreeBinding(engine, 'default', localHostId()))!);
- try { await runOnly(engine, ctx, scan.id, 7); }
+ try { await runOnly(engine, ctx, scan.id, 7, 50); }
finally { await lock!.release(); }
const busy = await gitEffect(engine, slugs[0]);
expect(busy).toMatchObject({ state: 'queued', error_code: 'writer_busy' });