Problem
Memory index SQLite database (~/.openclaw/memory/main.sqlite) is created with journal_mode=delete (SQLite default). This causes frequent database corruption when the gateway receives SIGTERM during write operations (restart, update, config changes).
Impact
- Users see "database disk image is malformed" errors
- Memory search stops working until manual
rm + openclaw memory index
- Happens repeatedly since gateway restarts are common
Root Cause
journal_mode=delete removes the journal file after each transaction. If the process is killed between deleting the journal and completing the write, the database corrupts.
Suggested Fix
Set PRAGMA journal_mode=WAL; when creating or opening the memory database. WAL mode:
- Is crash-safe (survives SIGTERM/SIGKILL mid-write)
- Allows concurrent reads during writes
- Is the recommended mode for applications that restart frequently
// After opening the database connection:
db.pragma('journal_mode = WAL');
Workaround
sqlite3 ~/.openclaw/memory/main.sqlite "PRAGMA journal_mode=WAL;"
But this resets if the DB is recreated (e.g., after openclaw memory index on a corrupted DB).
Environment
- OpenClaw 2026.3.2
- macOS arm64
- SQLite via better-sqlite3
Problem
Memory index SQLite database (
~/.openclaw/memory/main.sqlite) is created withjournal_mode=delete(SQLite default). This causes frequent database corruption when the gateway receives SIGTERM during write operations (restart, update, config changes).Impact
rm + openclaw memory indexRoot Cause
journal_mode=deleteremoves the journal file after each transaction. If the process is killed between deleting the journal and completing the write, the database corrupts.Suggested Fix
Set
PRAGMA journal_mode=WAL;when creating or opening the memory database. WAL mode:Workaround
But this resets if the DB is recreated (e.g., after
openclaw memory indexon a corrupted DB).Environment