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);