fix(mobile): wait out SQLite locks and use WAL in encrypted store - #6090
Open
iscekic wants to merge 1 commit into
Open
fix(mobile): wait out SQLite locks and use WAL in encrypted store#6090iscekic wants to merge 1 commit into
iscekic wants to merge 1 commit into
Conversation
Surface: the mobile app (apps/mobile). Problem: Sentry KILO-APP-7K (https://kilo-code.sentry.io/issues/7707832591/) reports `Call to function 'NativeStatement.runSync' has been rejected. -> Caused by: Error code : database is locked`, mixed frames with the in-app frame at apps/mobile/src/lib/persist/encrypted-kv.ts (26 events, 2 users, last seen 2026-09-11). The same error is the project's largest unresolved crash: KILO-APP-5J (https://kilo-code.sentry.io/issues/7686568573/, 748 events, 84 users) and KILO-APP-5H (https://kilo-code.sentry.io/issues/7686568565/, 66 events, 23 users), both system-only frames at expo-sqlite's NativeStatement.runSync. Every write in the encrypted store goes through that call: setItem (encrypted-kv.ts:265-268), removeItem (275-277), clearScope (284), clearScopePrefix (291-293), plus the probe and migration (167-170). Cause evidence: the connection is opened and keyed but never configured to wait out a lock. `openWithKey` calls `SQLite.openDatabaseSync(DATABASE_NAME)` (encrypted-kv.ts:152) and, after `assertSQLCipher` (154) and `PRAGMA key` (155), returns the Drizzle handle with no `PRAGMA busy_timeout` and no `PRAGMA journal_mode = WAL`. In SQLite's default rollback-journal mode a synchronous write that meets a held lock fails immediately with SQLITE_BUSY instead of waiting. The store also swallows a failed close: `closeQuietly` catches and discards every error (132-138), and the recovery path then calls `deleteDatabaseAsync` and reopens over a h
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
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.
Changelog for users
database is lockedwhile another connection holds the lock; the encrypted store waits up to five seconds instead of failing immediately.Changelog for maintainers
PRAGMA cipher_versionprobe,PRAGMA key,PRAGMA busy_timeout = 5000,PRAGMA journal_mode = WALverified from the returned row, then the first schema probe and migrations.BUSY_TIMEOUT_MSis 5000; a WAL switch that does not returnwalthrows and fails the open.closeQuietlynow returns whether the handle closed, and recovery aborts delete-and-recreate when the previous handle stays open.error.subsystem=encrypted-kv,error.operation=reset, then rethrows.MissingSQLCipherError, delete-and-recreate when close succeeds, plus schema, migrations, storage keys, exported API, and dependencies.encrypted-kv.test.tsgainsjournalModeandfailCloseseams covering the SQL order, the 5000 ms value, a rejected WAL switch, and abort-on-unclosed-handle.E2E proof
Owner request