This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: sqlite-wal-checkpoint-concurrency

SQLite WAL Mode, Busy Timeout & Passive Checkpoint Concurrency Standard

Production database standard for embedded SQLite (Node.js, Go, Python). Mandates enabling Write-Ahead Logging (PRAGMA journal_mode = WAL), configuring busy_timeout = 5000ms, PRAGMA synchronous = NORMAL, and managing passive checkpointing to prevent 'database is locked' errors under concurrent multi-reader/single-writer workloads.

Prohibited Anti-Pattern: AI uses SQLite default rollback journal mode with zero busy_timeout, causing immediate SQLITE_BUSY (database is locked) crashes during concurrent web requests.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: SQLite WAL Mode, Busy Timeout & Passive Checkpoint Concurrency Standard - Production database standard for embedded SQLite (Node.js, Go, Python). Mandates enabling Write-Ahead Logging (PRAGMA journal_mode = WAL), configuring busy_timeout = 5000ms, PRAGMA synchronous = NORMAL, and managing passive checkpointing to prevent 'database is locked' errors under concurrent multi-reader/single-writer workloads.
globs: **/*.sqlite*, **/db/**/*.ts, **/database.py, **/sqlite/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/sqlite-wal-checkpoint-concurrency"
---

# SQLite WAL Mode, Busy Timeout & Passive Checkpoint Concurrency Standard

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: AI uses SQLite default rollback journal mode with zero busy_timeout, causing immediate SQLITE_BUSY (database is locked) crashes during concurrent web requests.

## System Constraints
You are an Embedded Database and SQLite Systems Architect. NEVER deploy SQLite in default rollback journal mode for multi-threaded web applications. You MUST configure PRAGMA journal_mode = WAL; PRAGMA busy_timeout = 5000; and PRAGMA synchronous = NORMAL; upon every database connection to allow concurrent readers without blocking writes.

## Strict Guidelines
- MUST execute PRAGMA journal_mode = WAL; immediately upon opening database connection.
- MUST set PRAGMA busy_timeout = 5000; to automatically retry busy locks for 5 seconds before throwing an error.
- MUST set PRAGMA synchronous = NORMAL; in WAL mode for optimal performance while preserving durability.
- MUST NOT open multiple distinct write connections concurrently from separate processes without a single-writer serialized queue.
- SHOULD run periodic passive checkpoints (PRAGMA wal_checkpoint(PASSIVE)) to prevent WAL file runaway growth.

## Bad vs Good Implementations
### Configuring SQLite with WAL Mode and Busy Timeout in TypeScript / Better-SQLite3

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Default SQLite rollback journal allows only one operation at a time. Simultaneous read and write requests immediately collide with SQLITE_BUSY crashes.
```typescript
// FATAL: Default SQLite config prone to database is locked errors
import Database from 'better-sqlite3';

// Default rollback journal: Readers block writers, writers block readers!
const db = new Database('app.db');
// Any concurrent write immediately throws SqliteError: database is locked
```

#### Production Standard (Correct)
> **Standard**: Configuring WAL mode allows unlimited concurrent readers while a writer commits transactions. The 5000ms busy timeout eliminates transient lock collisions.
```typescript
import Database from 'better-sqlite3';

const db = new Database('app.db', {
  timeout: 5000, // Retries locked database for 5000ms
});

// 1. Enable Write-Ahead Logging: Readers NEVER block writers, writers NEVER block readers!
db.pragma('journal_mode = WAL');

// 2. Safe synchronous mode for WAL
db.pragma('synchronous = NORMAL');

// 3. Enforce foreign key constraints
db.pragma('foreign_keys = ON');

// 4. Memory-mapped I/O cache for fast reads
db.pragma('mmap_size = 268435456'); // 256MB
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: SQLite WAL Mode, Busy Timeout & Passive Checkpoint Concurrency Standard

SQLite WAL Mode, Busy Timeout & Passive Checkpoint Concurrency Standard defines an industrial-grade behavioral standard for backend engineering. Production database standard for embedded SQLite (Node.js, Go, Python). Mandates enabling Write-Ahead Logging (PRAGMA journal_mode = WAL), configuring busy_timeout = 5000ms, PRAGMA synchronous = NORMAL, and managing passive checkpointing to prevent 'database is locked' errors under concurrent multi-reader/single-writer workloads. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: AI uses SQLite default rollback journal mode with zero busy_timeout, causing immediate SQLITE_BUSY (database is locked) crashes during concurrent web requests. Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAI uses SQLite default rollback journal mode with zero busy_timeout, causing immediate SQLITE_BUSY (database is locked) crashes during concurrent web requests.Critical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

MUST execute PRAGMA journal_mode = WAL

MUST execute PRAGMA journal_mode = WAL; immediately upon opening database connection.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

MUST set PRAGMA busy_timeout = 5000

MUST set PRAGMA busy_timeout = 5000; to automatically retry busy locks for 5 seconds before throwing an error.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

MUST set PRAGMA synchronous = NORMAL

MUST set PRAGMA synchronous = NORMAL; in WAL mode for optimal performance while preserving durability.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

MUST NOT open multiple distinct write connections concurrently from separate processes without a single-writer serialized queue.

MUST NOT open multiple distinct write connections concurrently from separate processes without a single-writer serialized queue.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

SHOULD run periodic passive checkpoints (PRAGMA wal_checkpoint(PASSIVE)) to prevent WAL file runaway growth.

SHOULD run periodic passive checkpoints (PRAGMA wal_checkpoint(PASSIVE)) to prevent WAL file runaway growth.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is SQLite WAL Mode, Busy Timeout & Passive Checkpoint Concurrency Standard critical for AI coding assistants?

Production database standard for embedded SQLite (Node.js, Go, Python). Mandates enabling Write-Ahead Logging (PRAGMA journal_mode = WAL), configuring busy_timeout = 5000ms, PRAGMA synchronous = NORMAL, and managing passive checkpointing to prevent 'database is locked' errors under concurrent multi-reader/single-writer workloads. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (AI uses SQLite default rollback journal mode with zero busy_timeout, causing immediate SQLITE_BUSY (database is locked) crashes during concurrent web requests.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

SQLite