Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge capy/convergence-pr-b-barrier-ledger (C, D, E fixes) into capy/gst-1582-import-deferral

garrytande22702a346c
diff --cc src/core/persistence/refresh-barrier.ts
index 2d92300d14,548d27bbec..bae287eee2
--- a/src/core/persistence/refresh-barrier.ts
+++ b/src/core/persistence/refresh-barrier.ts
@@@ -75,11 -76,10 +76,13 @@@ export const REFRESH_BARRIER_MAX_WAIT_M
/**
* The owner's housekeeping: a deferred write whose refresh is still unreleased past the wait limit ends failed with
- * `refresh_barrier_expired` (nothing applied, counters released). The refresh row is locked first (lock order: worktree,
- * refresh, counters, request), so an expiry and the release that would make the row claimable never both win.
+ * `refresh_barrier_expired` (nothing applied, counters released). The transaction declares the persistence protocol (the
+ * brain row FOR SHARE) before it locks the refresh row, the order fenceAndMerge takes them in (brain FOR UPDATE, then the
+ * refresh), so an expiry overlapping a fence waits instead of deadlocking; with the refresh row locked, an expiry and
+ * the release that would make the row claimable never both win.
+ * GST-1582: one held for an import that has not landed past the limit ends `pending_import_expired` the same way; its
+ * claim and its expiry both move the row, so the expiry checks the row is still unclaimed and its import still pending
+ * under the request lock completeWrite takes.
*/
export async function expireDeferredWrites(engine: BrainEngine, hostId: string, signal?: AbortSignal): Promise<WriteRequest[]> {
const [config] = await engine.executeRaw<{ value: string }>('SELECT value FROM config WHERE key=$1', [REFRESH_BARRIER_MAX_WAIT_KEY], { signal });