Environment:0xsline OpenChatCut SQLite
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Storage |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Node.js built-in `node:sqlite` (DatabaseSync) persistent store for project state, generation jobs, and full-text/semantic search.
Description
This environment provides the SQLite database backend used as the sole persistent store for OpenChatCut project data. It uses Node.js 24's built-in `DatabaseSync` from the `node:sqlite` module — no external native SQLite binding is required. The database file is stored at `{runtimeProfile.rootDir}/project-store-v1.sqlite3` and runs in WAL journal mode with `synchronous = FULL` for crash safety. Additional connections from fulltext-search.ts and semantic-vectors.ts open separate long-lived `DatabaseSync` handles on the same file, with `sqlite-vec` for vector similarity search.
Usage
Use this environment for project store persistence (Project_Store CRUD), generation job lifecycle (job state machine and progress tracking), full-text search (FTS5), and semantic vector search. It is the mandatory prerequisite for any implementation that reads or writes durable project or job state.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | macOS, Windows, Linux | Cross-platform via node:sqlite |
| Hardware | Any | IOPS matter for large stores |
| Disk | Sufficient space for project data | Typically < 1GB; grows with project count |
Dependencies
System Packages
- Node.js >= 24 (provides `node:sqlite` module natively)
npm Packages
- `sqlite-vec` >= 0.1.9 (vector similarity search extension)
Quick Install
# SQLite is built into Node.js 24 — no separate install needed.
# Install the vector search extension:
npm install sqlite-vec
Code Evidence
Database initialization with WAL mode from `server/storage/sqlite-store.ts:33-50`:
function openDatabase(): DatabaseSync {
if (database) return database;
const path = storePath();
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
const db = new DatabaseSync(path);
db.exec('PRAGMA busy_timeout = 5000;');
try {
db.exec(`
PRAGMA journal_mode = WAL;
PRAGMA synchronous = FULL;
CREATE TABLE IF NOT EXISTS kv (
k TEXT PRIMARY KEY,
v TEXT NOT NULL
);
`);
database = db;
return db;
} catch (error) {
db.close();
throw error;
}
}
Store path resolution from `server/storage/sqlite-store.ts:26-29`:
export function storePath(): string {
const profile = runtimeProfile();
return join(profile.rootDir, 'project-store-v1.sqlite3');
}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `SQLite project store is not initialized` | `initializeSqliteProjectStore()` not called | Ensure the storage lifecycle plugin runs at startup |
| `EPERM` on temp-library cleanup (Windows) | Other DatabaseSync handles open on the same file | `registerSqliteStoreConnectionCloser()` must close all connections |
| `database is locked` | Concurrent writer contention | `PRAGMA busy_timeout = 5000` should handle this; check for long transactions |
| `Cannot find module 'node:sqlite'` | Node.js < 22 | Upgrade to Node.js >= 24 |
Compatibility Notes
- Windows: Windows refuses to delete a file while a handle is open. The store registers closers for all auxiliary connections (fulltext-search, semantic-vectors) via `registerSqliteStoreConnectionCloser()`.
- WAL mode: Write-Ahead Logging allows concurrent readers with a single writer. The `busy_timeout` of 5000ms prevents "database is locked" under contention.
- Migration: JSON-to-SQLite migration is atomic and runs once at startup. Legacy JSON files remain as backups but are never authoritative after migration.