transaction-correctness — Claude Code skill: WAL & ACID in Turso
Explains how transactions work in Turso: WAL mechanics, checkpointing, crash recovery, and concurrency rules.
npx skills add tursodatabase/turso --skill transaction-correctness -a claude-codeWhat transaction-correctness does
The skill breaks down how Turso handles reads and writes through WAL (Write-Ahead Logging): writer appends frames to .db-wal, reader sees a consistent snapshot at its read mark, checkpoint moves changes back to .db. It covers four checkpoint types — PASSIVE, FULL, RESTART, TRUNCATE — and concurrency rules: one writer, readers don't block the writer.
Turso skips the .db-shm file and uses in-memory structures: frame_cache hashmap, atomic read marks, and locks. The skill references wal.rs and pager.rs, shows the split between connection-private state (Pager, WalFile) and shared state (WalFileShared, DatabaseStorage). This is the foundation if you're fixing Turso's transaction layer or debugging race conditions.
Requires the Turso repository — the skill relies on specific codebase files.
What it helps with
- understand WAL mechanics in Turso
- learn crash recovery process
- study concurrency rules for database access
- debug transactional logic
- grasp Pager and WalFile architecture
Example prompts for the agent
- explain how checkpointing works in Turso
- show the difference between PASSIVE and FULL checkpoint
- how does a reader see a consistent snapshot
How to install transaction-correctness
1Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a claude-code2Manually: put the files in place
~/.claude/skills/transaction-correctness/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/transaction-correctness/
1Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a codex2Manually: put the files in place
.agents/skills/transaction-correctness/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a cursor2Manually: put the files in place
.cursor/skills/transaction-correctness/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install tursodatabase/turso transaction-correctness2Manually: put the files in place
.github/skills/transaction-correctness/SKILL.md1Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a gemini-cli2Platform CLI
gemini skills install https://github.com/tursodatabase/turso --path .claude/skills/transaction-correctnessManually: put the files in place
.devin/skills/transaction-correctness/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add tursodatabase/turso --skill transaction-correctness -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set10
The whole set →Similar
Questions about transaction-correctness
How to install transaction-correctness in Claude Code?
Run npx skills add tursodatabase/turso --skill transaction-correctness -a claude-code. The skill file will appear in ~/.claude/skills/transaction-correctness/SKILL.md.
What does transaction-correctness do?
It explains how transactions work in Turso: WAL mechanics, checkpointing, crash recovery, and concurrency rules for database access.
How is Turso different from standard SQLite?
Turso does not use the .db-shm file — instead it uses an in-memory WAL index with a frame_cache hashmap and atomic read marks, because multi-process access is not supported.
Source text
SKILL.md · MIT
--- name: transaction-correctness description: How WAL mechanics, checkpointing, concurrency rules, recovery work in tursodb --- # Transaction Correctness Guide Turso uses WAL (Write-Ahead Logging) mode exclusively. Files: `.db`, `.db-wal` (no `.db-shm` - Turso uses in-memory WAL index) ## WAL Mechanics ### Write Path 1. Writer appends frames (page data) to WAL file (sequential I/O) 2. COMMIT = frame with non-zero db_size in header (marks transaction end) 3. Original DB unchanged until checkpoint ### Read Path 1. Reader acquires read mark (mxFrame = last valid commit frame) 2. For each page: check WAL up to mxFrame, fall back to main DB 3. Reader sees consistent snapshot at its read mark ### Checkpointing Transfers WAL content back to main DB. ``` WAL grows → checkpoint triggered (default: 1000 pages) → pages copied to DB → WAL reused ``` Checkpoint types: - **PASSIVE**: Non-blocking, stops at pages needed by active readers - **FULL**: Waits for readers, checkpoints everything - **RESTART**: Like FULL, also resets WAL to beginning - **TRUNCATE**: Like RESTART, also truncates WAL file to zero length ### WAL-Index SQLite uses a shared memory file (`-shm`) for WAL index. **Turso does not** - it uses in-memory data structures (`frame_cache` hashmap, atomic read marks) since multi-process access is not supported. ## Concurrency Rules - One writer at a time - Readers don't block writer, writer doesn't block readers - Checkpoint must stop at pages needed by active readers ## Recovery On crash: 1. First connection acquires exclusive lock 2. Replays valid commits from WAL 3. Releases lock, normal operation resumes ## Turso Implementation Key files: - [WAL implementation](../../../core/storage/wal.rs) - WAL implementation - [Page management, transactions](../../../core/storage/pager.rs) ### Connection-Private vs Shared **Per-Connection (private):** - `Pager` - page cache, dirty pages, savepoints, commit state - `WalFile` - connection's snapshot view: - `max_frame` / `min_frame` - frame range for this connection's snapshot - `max_frame_read_lock_index` - which read lock slot this connection holds - `last_checksum` - rolling checksum state **Shared across connections:** - `WalFileShared` - global WAL state: - `frame_cache` - page-to-frame index (replaces `.shm` file) - `max_frame` / `nbackfills` - global WAL progress - `read_locks[5]` - read mark slots (TursoRwLock with embedded frame values) - `write_lock` - exclusive writer lock - `checkpoint_lock` - checkpoint serialization - `file` - WAL file handle - `DatabaseStorage` - main `.db` file - `BufferPool` - shared memory allocation ## Correctness Invariants 1. **Durability**: COMMIT record must be fsynced before returning success 2. **Atomicity**: Partial transactions never visible to readers 3. **Isolation**: Each reader sees consistent snapshot 4. **No lost updates**: Checkpoint can't overwrite uncommitted changes ## References - [SQLite WAL](https://sqlite.org/wal.html) - [WAL File Format](https://sqlite.org/walformat.html)
© tursodatabase · MIT · tursodatabase/turso