Deterministic Concurrency & Isolation Fuzzer
ChaosSQL injects stochastic micro-jitter to trigger rare database race conditions, classifies isolation anomalies through Adya dependency graphs, and shrinks 100-operation execution traces to 1-minimal reproductions in milliseconds.
Built on Formal Concurrency Research
ChaosSQL replaces heuristic guesswork with rigorous isolation theory, provable scheduling bounds, and algorithmic test case minimization.
Adya Graph Cycle Detection
Builds dynamic dependency graphs $SG(S) = (V, E)$ tracking write-read (wr), write-write (ww), and read-write anti-dependency (rw) edges. Formally classifies cycles into Lost Update (P4), Write Skew (A5B), Read Skew (A5A), Dirty Writes (G0), and G2 Anti-Dependency.
PCT-SQL Priority Scheduling
Adapts Burckhardt's Probabilistic Concurrency Testing algorithm to SQL transactions. Guarantees finding concurrency bugs of depth $d$ with mathematical probability $\mathbb{P}[\text{bug}] \ge \frac{1}{n \cdot k^{d-1}}$, avoiding deadlocks and thread starvation.
Zeller Delta-Debugging ($ddmin$)
When an invariant fails across thousands of interleaved operations, ChaosSQL partitions the execution history using binary and $n$-way search until reaching 1-minimality: removing any single remaining operation causes the bug to disappear.
10 Flagship Demonstration Scenarios
Explore real-world isolation bugs across financial ledgers, inventory systems, medical on-call rotas, and distributed exchanges.
Banking Lost Update
Concurrent withdrawal operations under READ COMMITTED overwrite balances without locking.
Go Developer Testing SDK (pkg/chaostest)
Embed deterministic concurrency fuzzing and automatic anomaly shrinking directly into standard go test suites.
package myapp_test
import (
"context"
"testing"
"github.com/bregaldahq/chaossql/pkg/chaostest"
)
func TestAccountTransfer_NoLostUpdates(t *testing.T) {
ctx := context.Background()
schema := `
CREATE TABLE accounts (
id INT PRIMARY KEY,
balance INT NOT NULL
);`
seed := `INSERT INTO accounts VALUES (1, 1000), (2, 1000);`
chaostest.New(t).
WithSchema(schema).
WithSeed(seed).
WithInvariant("total_wealth", "SELECT sum(balance) AS total FROM accounts;", "total == 2000").
AddOperation("transfer_1_to_2",
"SELECT balance FROM accounts WHERE id = 1 -> bal1",
"UPDATE accounts SET balance = {bal1 - 50} WHERE id = 1",
"UPDATE accounts SET balance = balance + 50 WHERE id = 2",
).
AddOperation("transfer_2_to_1",
"SELECT balance FROM accounts WHERE id = 2 -> bal2",
"UPDATE accounts SET balance = {bal2 - 50} WHERE id = 2",
"UPDATE accounts SET balance = balance + 50 WHERE id = 1",
).
AssertNoAnomalies(ctx, 4, 30, 42) // workers=4, iterations=30, seed=42
}
Hermitage Isolation Anomaly Matrix
Empirical comparison of isolation semantics across database engines under concurrent execution.
| Anomaly / Phenonemon | Formal Cycle | SQLite (WAL) | PostgreSQL (RC) | PostgreSQL (SSI) | MySQL (InnoDB RR) |
|---|---|---|---|---|---|
| P4 — Lost Update | T1 ──(rw)──► T2 ──(ww)──► T1 |
PERMITTED | PERMITTED | PREVENTED | PREVENTED |
| A5B — Write Skew | T1 ──(rw)──► T2 ──(rw)──► T1 |
PERMITTED | PERMITTED | PREVENTED | PERMITTED |
| A5A — Read Skew | T1 ──(rw)──► T2 ──(wr)──► T1 |
PERMITTED | PERMITTED | PREVENTED | PREVENTED |
| G0 — Dirty Write | T1 ──(ww)──► T2 ──(ww)──► T1 |
PREVENTED | PREVENTED | PREVENTED | PREVENTED |
| G1a — Dirty Read (Aborted) | w1(x) ... r2(x) ... a1 |
PREVENTED | PREVENTED | PREVENTED | PREVENTED |
| G2 — Anti-Dependency Cycle | T1 ──(rw)──► T2 ──(rw)──► T3 ──(rw)──► T1 |
PERMITTED | PERMITTED | PREVENTED | PERMITTED |
| G-DL — Deadlock Cycle | T1 ──(waits)──► T2 ──(waits)──► T1 |
DETECTED (Timeout) | DETECTED (40P01) | DETECTED (40P01) | DETECTED (1213) |
Command Reference
Zero external runtime dependencies. Compiles to a single standalone binary with CGO_ENABLED=0.
# 1. Run scenario with deterministic seed and causal trace reduction
chaossql run examples/banking_lost_update/chaos.yaml --seed=42 --workers=4
# 2. Run all 9 interactive demonstrations
chaossql demo banking
chaossql demo hospital
chaossql demo deadlock
# 3. Scaffold a new fuzzer scenario
chaossql init my_scenario --driver sqlite
# 4. Pre-flight static linter for scenario expressions
chaossql validate my_scenario/chaos.yaml
# 5. High-throughput PRNG & Adya cycle benchmark (13.9M ops/s)
chaossql bench
# 6. Generate empirical isolation comparison matrix
chaossql matrix