Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(journal): an uncharged claim release clears its claim phase, so a writer_busy row no longer reads as a stalled preparation
time-attackad07c87c1a52
diff --git a/src/core/persistence/journal.ts b/src/core/persistence/journal.tsindex ec0ca3066f..418294620a 100644--- a/src/core/persistence/journal.ts+++ b/src/core/persistence/journal.ts@@ -633,8 +633,10 @@ export async function renewWriteClaim(engine: SqlEngine, id: string, token: stri}/** `charge` (#6278): a `preparation_deadline` release counts one preparation attempt; `claim_lost`, `consumer_stopping` and the rest never do. */export async function releaseUnpublishedClaim(engine: SqlEngine, row: WriteRequest, reason: string, opts: { charge?: boolean } = {}): Promise<void> {+ // An uncharged release ends a finished preparation: its claim phase would read as a preparation still waiting.await engine.executeRaw(`UPDATE persistence_requests SET state='queued',execution_token=NULL,claim_expires_at=NULL,- blocked_reason=$3,updated_at=now(),preparation_attempts=preparation_attempts+CASE WHEN $4::boolean THEN 1 ELSE 0 END+ blocked_reason=$3,updated_at=now(),preparation_attempts=preparation_attempts+CASE WHEN $4::boolean THEN 1 ELSE 0 END,+ claim_phase=CASE WHEN $4::boolean THEN claim_phase ENDWHERE id=$1::uuid AND execution_token=$2::uuidAND state='running' AND recovery IS NULL AND publication_started=false AND ${PERSISTENCE_PROTOCOL_PREDICATE}`, [row.id, row.execution_token, reason, opts.charge === true]);}diff --git a/test/persistence-git-coalescing-5530.slow.test.ts b/test/persistence-git-coalescing-5530.slow.test.tsindex 67ee156598..59c0e31a40 100644--- a/test/persistence-git-coalescing-5530.slow.test.ts+++ b/test/persistence-git-coalescing-5530.slow.test.ts@@ -25,7 +25,7 @@ import type { BrainEngine } from '../src/core/engine.ts';import type { OperationContext } from '../src/core/ops/contract.ts';import { phaseCGrandfather } from '../src/commands/migrations/v0_13_1.ts';import { admitCanonicalGrandfather } from '../src/core/persistence/grandfather.ts';-import { claimWorktree } from '../src/core/persistence/ownership.ts';+import { acquireWorktree, claimWorktree, getWorktreeBinding } from '../src/core/persistence/ownership.ts';import { activateSharedSkillPersistence } from '../src/core/persistence/skill-activation.ts';import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';import { disposePersistenceConsumer, startPersistenceConsumer } from '../src/core/persistence/service.ts';@@ -395,6 +395,21 @@ for (const kind of testBackends()) describe(`#5530 Git effect coalescing (${kindwhile ((await gitStates(engine)).queued) { await release(engine); await pass(engine); }expect(await gitStates(engine)).toEqual({ committed: BACKLOG + 1 });}), 300_000);+ test('a write that finds the worktree busy is requeued as writer_busy with no stale preparing phase', () => withBrain(kind, async ({ engine, home, ctx }) => {+ const repo = makeRepo(home, 'content');+ await bindSource(engine, 'default', repo);+ await activateSharedSkillPersistence(engine, { confirmQuiesced: true });+ await seed(ctx('default'), 1);+ const binding = (await getWorktreeBinding(engine, 'default', localHostId()))!;+ const held = (await acquireWorktree(binding, 0, undefined, engine))!;+ try {+ await submitPageMutation(ctx('default'), { operation: 'put_page', waitMs: 1500,+ params: { slug: 'notes/lock-held', request_id: randomUUID(), content: pageContent(7777) } }).catch(() => undefined);+ const [row] = await engine.executeRaw<{ state: string; blocked_reason: string | null; claim_phase: unknown }>(+ "SELECT state,blocked_reason,claim_phase FROM persistence_requests ORDER BY created_at DESC LIMIT 1");+ expect(row).toEqual({ state: 'queued', blocked_reason: 'writer_busy', claim_phase: null });+ } finally { await held.release(); await disposePersistenceConsumer(engine); }+ }), 300_000);// Wave 7: the coalesced claim hoists its worktree-wide conditions into one InitPlan. This is the claim's// predicate before that change, row by row; every state below must claim exactly the rows it selects.test('the coalesced claim takes exactly the rows of the per-row reference predicate', () => withBrain(kind, async ({ engine, home, ctx }) => {