From 9a980c08f6e8b8ea40375f1ddd0c09db1733a725 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 18 Nov 2026 20:06:48 +0000 Subject: [PATCH] fix(outbox): prune delivered rows inside the add's write transaction Every outbox add ran pruneDelivered as its own autocommit DELETE before the add's BEGIN IMMEDIATE transaction, so it took the database's write lock twice. With several server processes adding at once, the housekeeping DELETE could wait past busy_timeout and fail the whole add with a 500 ("database is locked"), seen on the Windows CI runner in "concurrent processes share the 1000-row active pool". The prune now runs first inside the add's own transaction: one write lock per add, in the same order as before. --- lib/message-outbox.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/message-outbox.ts b/lib/message-outbox.ts index 163edf84d..e1f9eb685 100644 --- a/lib/message-outbox.ts +++ b/lib/message-outbox.ts @@ -548,11 +548,13 @@ export async function runOutboxCommand(sessionId: string, command: Record { + // Inside the add's own write lock: a separate autocommit DELETE took the lock a second time per add, and failing + // to get it (busy past busy_timeout with several servers adding at once) failed the whole add with a 500. + pruneDelivered(database, now - KEEP_DELIVERED_MS); const concurrent = row(id); if (concurrent) { if (!entryBelongsToSession(concurrent, sessionId)) return { kind: "conflict" };