An adventure in writing compatible systems
Turso, a Rust rewrite of SQLite, hit a bug where every write after the database crossed 1GB made SQLite's integrity checks fail, even though Turso's own checks found the file intact. The cause was the SQLite "pending byte" page: once a file passes the 1GB mark, SQLite reserves a special page tied to file locking, and Turso did not reserve it. The deterministic simulation tests had missed the bug because every profile injected faults, so no test database ever grew to 1GB. Adding fault-free runs fixed that gap, a reminder that compatible rewrites must match undocumented-feeling quirks of the original implementation.
Related posts
- Introducing Limbo: A complete rewrite of SQLite in Rust
Turso easyNoviceLimbo is Turso's from-scratch rewrite of SQLite in Rust that aims for full language and file-format compatibility, memory safety and a modern architecture. The team chose a rewrite over the libSQL fork because invasive changes such as natural vector-index syntax and async I/O were hard to make in C without SQLite's proprietary test suite. Deterministic Simulation Testing is built in from the start, and Antithesis is used for system-level fault simulation, which has already caught io_uring partial-write bugs. Early results include a fully asynchronous sqlite3_step, a WASM-first build that works with Drizzle, fewer tunables, and a point query about 20% faster than tuned SQLite (506ns vs 620ns).
- The final boss of reliability: formal verification
Turso mediumAdeptTurso, a from-scratch SQLite rewrite, is adding formal verification via Aretta AI's Aristo, which turns natural-language intents annotated on code into formally checked properties, to complement its deterministic simulation testing and Antithesis runs. Aristo found in minutes a durability bug that DST had missed. When Turso acts as a sync replica of a cloud database, it bypasses the page cache, so pages became dirty without the dirty bit being set and were sometimes written to disk without fsync. The case for the approach is that properties like "a commit frame must be fsynced before being reported durable" are cheap to check formally. Runtime testing can miss them, because most runs happen to call fsync for unrelated reasons.
- How we used Quint to find over 10 bugs in SQLite while hardening Turso
Turso mediumAdeptModeling individual SQLite C API contracts in Quint, generating small traces, and replaying them as C programs against real SQLite uncovered more than 10 SQLite bugs while also validating Turso's compatible C API. Rather than specifying the whole database, each documented contract was modeled with only the state it needs, so a divergence points either to a model error or to a real bug. One example: sqlite3_deserialize() crashed instead of returning SQLITE_BUSY during an active read transaction. Other findings include wrong results from EXISTS-to-join and UPDATE planning optimizations, xfer optimization bypassing type and CHECK constraints, and mutex alignment undefined behaviour.
- Turso v0.7.0
Turso hardMasterTurso 0.7 drops the beta label and focuses on performance and robustness for embedded, multi-tenant use: the core no longer blocks on I/O, yields CPU via a new StepResult::Yield, moves to fallible allocation so OOM surfaces as an error, and treats the page cache as a soft limit like SQLite. The MVCC engine gets a linear-merge dual cursor that replaces per-row skiplist lookups (about a quarter of CPU time on write-heavy loads), watermark-driven garbage collection, experimental passive checkpoints that don't stop the world, and smaller row versions. SQL additions include PostgreSQL-style sequences (now backing AUTOINCREMENT), ICU collations, REINDEX, ordered-set aggregates and window-function groundwork. The SDKs gain a SQLite-compatible .NET/EF Core provider, GIL release and FTS in Python, and concurrent transactions in JavaScript.
- Beyond the Single-Writer Limitation with Turso's Concurrent Writes
Turso hardMasterTurso implements SQLite-compatible BEGIN CONCURRENT using Hekaton-style MVCC, which removes SQLite's single-writer bottleneck and the SQLITE_BUSY errors that come with it. An in-memory row-version index sits on top of the B-tree and WAL, conflicts are detected per row at commit time instead of per page, and the MVCC log is checkpointed back into the database file through the WAL. In benchmarks SQLite still wins single-threaded, but Turso is 16% faster with multiple threads and pure inserts, and 4x faster with 8 threads and 1ms of compute per transaction. The feature is an early tech preview: CREATE INDEX is not supported and full-row versioning carries a high memory cost.