Environment:777genius Agent teams ai SQLite
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Data_Persistence |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
SQLite database (via Node.js built-in `node:sqlite`) for review persistence scope locking with WAL mode, heartbeat-based lease management, and crash-left lease recovery.
Description
The app uses Node.js 24+'s built-in `DatabaseSync` from `node:sqlite` to manage review persistence scope locks. The SQLite database is stored at `.review-persistence-locks.sqlite3` in the teams base path. It runs in WAL journal mode with `PRAGMA synchronous = FULL` for durability. The lock table tracks scope ID, owner token (UUID), owner PID, process start time, and heartbeat timestamps. Lease acquisition uses `BEGIN IMMEDIATE` transactions with busy timeout (2000ms) and retry loops. Stale lease detection compares process start times to handle PID recycling.
Usage
Use this environment for the review persistence scope lock implementation that serializes review change operations across app instances and scopes.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| Runtime | Node.js >= 24.15.0 | `node:sqlite` is built-in (experimental in Node 24) |
| OS | macOS, Windows, or Linux | Cross-platform SQLite |
| Disk | Teams base path writable | `.review-persistence-locks.sqlite3` created there |
Dependencies
Node.js Packages
- `node:sqlite` (built-in Node.js 24+ module — `DatabaseSync`)
- No external npm packages required
Credentials
No credentials required. The database file is created with mode `0o600` (owner read/write only).
Quick Install
# No install needed — node:sqlite is built into Node.js 24+
# Ensure Node.js >= 24.15.0 is installed
node --version
Code Evidence
SQLite import and database setup from `ReviewPersistenceScopeLock.ts:1,71-91`:
import { DatabaseSync } from 'node:sqlite';
function openLockDatabase(): DatabaseSync {
const databasePath = getLockDatabasePath();
const cached = lockDatabases.get(databasePath);
if (cached) return cached;
const database = new DatabaseSync(databasePath);
database.exec(`PRAGMA busy_timeout = ${SQLITE_BUSY_TIMEOUT_MS}`);
database.exec('PRAGMA journal_mode = WAL');
database.exec('PRAGMA synchronous = FULL');
database.exec(`
CREATE TABLE IF NOT EXISTS review_scope_locks (
scope_id TEXT PRIMARY KEY NOT NULL,
owner_token TEXT NOT NULL,
owner_pid INTEGER NOT NULL,
owner_started_at INTEGER NOT NULL,
acquired_at INTEGER NOT NULL,
heartbeat_at INTEGER NOT NULL
) STRICT
`);
fs.chmodSync(databasePath, 0o600);
Lease acquisition with busy retry from `ReviewPersistenceScopeLock.ts:313-337`:
async function acquireLease(...): Promise<ReviewScopeLockLease> {
const database = openLockDatabase();
const ownerToken = randomUUID();
const deadline = Date.now() + options.acquireTimeoutMs;
while (true) {
try {
if (await tryAcquireLease(database, scopeId, ownerToken, budget)) {
activeOwnerTokens.add(ownerToken);
return { database, scopeId, ownerToken };
}
} catch (error) {
if (!isSqliteBusy(error)) throw error;
}
if (Date.now() >= deadline) {
throw new Error('Review changes are busy in another app process; retry shortly.');
}
await sleep(Math.min(options.retryIntervalMs, Math.max(1, deadline - Date.now())));
}
}
Heartbeat lease from `ReviewPersistenceScopeLock.ts:340-347`:
function heartbeatLease(lease: ReviewScopeLockLease): boolean {
const result = lease.database
.prepare('UPDATE review_scope_locks SET heartbeat_at = ? WHERE scope_id = ? AND owner_token = ?')
.run(Date.now(), lease.scopeId, lease.ownerToken);
return Number(result.changes) === 1;
}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `database is busy` | Another process holds the write lock | Retry within 30s acquire timeout; `PRAGMA busy_timeout = 2000` handles short waits |
| `Review changes are busy in another app process` | Acquire deadline (30s) exceeded | Wait for other process to finish, then retry |
| Lock ownership lost during operation | Heartbeat detected token removal | Operation aborts; user must retry the review change |
| Stale lock from crashed process | PID recycled to new process | Process start time comparison detects PID recycling; stale lease is reclaimed |
Compatibility Notes
- Node.js version: Requires `node:sqlite` (Node.js 24+). Not available in older Node.js.
- WAL mode: WAL and SHM files are also chmod'd to `0o600` for security.
- Windows: Process start time probing shells out to `powershell.exe` (~1s startup); probe results cached with TTL.
- Concurrent acquires: In-flight process start probes are shared across concurrent acquirers to limit process spawns.