From c547a067bc213ba47f18173ea670f1ebced7ce8d Mon Sep 17 00:00:00 2001 From: Abraham Gonzalez Date: Thu, 19 Feb 2026 14:36:19 -0500 Subject: [PATCH] fix: switch SQLite from WAL to DELETE journal mode to prevent corruption MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WAL mode relies on shared memory (mmap) and POSIX file locking via the -shm file, both of which are unreliable across Docker volume mounts on macOS. When two instances share the same database through bind mounts, the broken mmap coordination causes silent data corruption (SQLITE_CORRUPT). Switch to DELETE journal mode which eliminates the -shm shared memory dependency entirely. Add EXCLUSIVE locking mode so the process holds the database lock for its connection lifetime — a second instance gets a clear SQLITE_BUSY error instead of silent corruption. Performance impact is negligible since opencode uses a single connection per process, making WAL's concurrent-read advantage unused. Closes #14194 --- packages/opencode/src/storage/db.ts | 4 ++-- packages/opencode/src/storage/json-migration.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/opencode/src/storage/db.ts b/packages/opencode/src/storage/db.ts index 6d7bfd728102..17a6c40bb994 100644 --- a/packages/opencode/src/storage/db.ts +++ b/packages/opencode/src/storage/db.ts @@ -70,12 +70,12 @@ export namespace Database { const sqlite = new BunDatabase(path.join(Global.Path.data, "opencode.db"), { create: true }) - sqlite.run("PRAGMA journal_mode = WAL") + sqlite.run("PRAGMA journal_mode = DELETE") sqlite.run("PRAGMA synchronous = NORMAL") sqlite.run("PRAGMA busy_timeout = 5000") sqlite.run("PRAGMA cache_size = -64000") sqlite.run("PRAGMA foreign_keys = ON") - sqlite.run("PRAGMA wal_checkpoint(PASSIVE)") + sqlite.run("PRAGMA locking_mode = EXCLUSIVE") const db = drizzle({ client: sqlite, schema }) diff --git a/packages/opencode/src/storage/json-migration.ts b/packages/opencode/src/storage/json-migration.ts index 828ce4799b4d..5802ff6851fe 100644 --- a/packages/opencode/src/storage/json-migration.ts +++ b/packages/opencode/src/storage/json-migration.ts @@ -46,7 +46,7 @@ export namespace JsonMigration { const db = drizzle({ client: sqlite }) // Optimize SQLite for bulk inserts - sqlite.exec("PRAGMA journal_mode = WAL") + sqlite.exec("PRAGMA journal_mode = DELETE") sqlite.exec("PRAGMA synchronous = OFF") sqlite.exec("PRAGMA cache_size = 10000") sqlite.exec("PRAGMA temp_store = MEMORY")