Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(#6007): effects lock the brain row before the source row (links effect vs worktree claim deadlock)
garrytan44fdf7456dbe
diff --git a/src/core/persistence/effect-recovery.ts b/src/core/persistence/effect-recovery.tsindex fd6740de84..1099cf2763 100644--- a/src/core/persistence/effect-recovery.ts+++ b/src/core/persistence/effect-recovery.ts@@ -25,6 +25,9 @@ const effectStatusFix = (effect: Pick<PersistenceEffect, 'source_id'>): Action =export async function guardEffectSource(tx: BrainEngine, effect: PersistenceEffect, hostId: string): Promise<WorktreeBinding | null> {await declarePersistenceProtocol(tx);+ // Lock order is brain row, then source row: the effect-row protocol trigger share-locks the brain row,+ // and a worktree claim holds the brain row while it locks the source (#6007 deadlock).+ await tx.executeRaw('SELECT singleton FROM persistence_brain WHERE singleton=1 FOR SHARE');if (effect.worktree_id) {const [owner] = await tx.executeRaw<{ owner_host_id: string; state: string }>('SELECT owner_host_id,state FROM persistence_worktrees WHERE id=$1::uuid FOR SHARE', [effect.worktree_id]);if (!owner || owner.owner_host_id !== hostId || owner.state !== 'active') throw opError('owner_unavailable', 'The effect requires its active canonical owner.',