fix: switch SQLite from WAL to DELETE journal mode to prevent corruption#14326
Open
theabecaster wants to merge 2 commits intoanomalyco:devfrom
Open
fix: switch SQLite from WAL to DELETE journal mode to prevent corruption#14326theabecaster wants to merge 2 commits intoanomalyco:devfrom
theabecaster wants to merge 2 commits intoanomalyco:devfrom
Conversation
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
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
please fix, multiple opencode instances nuke all of my sessions;d |
Closed
6 tasks
|
Looks like the specs are failing on this PR: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #14194
Type of change
What does this PR do?
SQLite WAL mode uses a shared memory file (
-shm) viammapto coordinate across processes. Docker bind mounts on macOS don't reliably propagatemmaporfcntllocks, so two instances sharing~/.local/share/opencode/silently corrupt the database.This switches
journal_modefrom WAL to DELETE (eliminating the-shmfile entirely), replaceswal_checkpoint(PASSIVE)withlocking_mode = EXCLUSIVE(so the second instance getsSQLITE_BUSYinstead ofSQLITE_CORRUPT), and updatesjson-migration.tswhich was re-setting journal mode to WAL during bulk inserts.No performance impact — opencode uses one connection per process, so WAL's concurrent-read advantage was unused.
How did you verify your code works?
bun devlocally with the pragma changes, sessions create and update normallySQLITE_BUSYerror afterbusy_timeout(5s) instead ofSQLITE_CORRUPTScreenshots / recordings
Not a UI change.
Checklist