-
-
Notifications
You must be signed in to change notification settings - Fork 69.3k
Memory SQLite should use WAL journal mode by default #36035
Copy link
Copy link
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.