Skip to content
This repository was archived by the owner on Jun 24, 2026. It is now read-only.

Commit c547a06

Browse files
committed
fix: switch SQLite from WAL to DELETE journal mode to prevent corruption
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 anomalyco#14194
1 parent 8b99648 commit c547a06

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎packages/opencode/src/storage/db.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ export namespace Database {
7070

7171
const sqlite = new BunDatabase(path.join(Global.Path.data, "opencode.db"), { create: true })
7272

73-
sqlite.run("PRAGMA journal_mode = WAL")
73+
sqlite.run("PRAGMA journal_mode = DELETE")
7474
sqlite.run("PRAGMA synchronous = NORMAL")
7575
sqlite.run("PRAGMA busy_timeout = 5000")
7676
sqlite.run("PRAGMA cache_size = -64000")
7777
sqlite.run("PRAGMA foreign_keys = ON")
78-
sqlite.run("PRAGMA wal_checkpoint(PASSIVE)")
78+
sqlite.run("PRAGMA locking_mode = EXCLUSIVE")
7979

8080
const db = drizzle({ client: sqlite, schema })
8181

‎packages/opencode/src/storage/json-migration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export namespace JsonMigration {
4646
const db = drizzle({ client: sqlite })
4747

4848
// Optimize SQLite for bulk inserts
49-
sqlite.exec("PRAGMA journal_mode = WAL")
49+
sqlite.exec("PRAGMA journal_mode = DELETE")
5050
sqlite.exec("PRAGMA synchronous = OFF")
5151
sqlite.exec("PRAGMA cache_size = 10000")
5252
sqlite.exec("PRAGMA temp_store = MEMORY")

0 commit comments

Comments
 (0)