mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-07-06 22:55:56 +08:00
libsql client-ts upstream issue #288 makes PRAGMA busy_timeout ineffective for async transactions, so concurrent db.transaction() calls reliably surface SQLITE_BUSY. Introduce DbService.withWriteTx as a serialized write helper: - Process-wide FIFO mutex (async-mutex) serializes write transactions. - libsql client's default BEGIN IMMEDIATE protects against read-then-write tx upgrade failures (no override needed at the drizzle layer). - Single 50ms BUSY retry guards against transient external locks. Reads do NOT need this — WAL gives readers snapshot isolation that is never blocked by writers. Includes unit tests (FIFO ordering, finally release on throw, single BUSY retry, persistent BUSY rethrow, non-BUSY passthrough) plus a real-libsql integration test. Updates the DbService test mock with a passthrough withWriteTx so dependent services do not throw "is not a function" in tests. Documents the API in database-patterns.md and points CLAUDE.md / data-api-overview.md at the new pattern.