From 54965d70959e789ccf609a52561fc758204e3f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Fri, 24 Jul 2026 08:32:11 +0000 Subject: [PATCH] email: set busy_timeout on the email db to ride out concurrent writers The API and email sidecar both open emails.db; without a busy timeout a write overlap (resync, or the thread_id backfill) throws "database is locked" and 500s a request. Wait up to 5s for the other writer instead. Co-Authored-By: Claude Opus 4.8 --- src/servers/api/email/email-db.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/servers/api/email/email-db.ts b/src/servers/api/email/email-db.ts index 40c94bb6..553af9d3 100644 --- a/src/servers/api/email/email-db.ts +++ b/src/servers/api/email/email-db.ts @@ -133,6 +133,9 @@ function fallbackThreadId(row: { id: string; subject: unknown; from_address: unk export function openEmailDb(email: string): Database { const dbPath = join(DATA_PATH, email, 'emails.db'); const db = new Database(dbPath, { create: true }); + // The API and the email sidecar both open this file; wait out a concurrent writer (e.g. a resync + // or the one-time thread_id backfill) instead of failing immediately with "database is locked". + db.exec('PRAGMA busy_timeout = 5000'); db.exec('PRAGMA journal_mode = DELETE'); db.exec('PRAGMA foreign_keys = ON'); db.exec(SCHEMA_TABLES);