Skip to content

Memory SQLite should use WAL journal mode by default #36035

@nguathen

Description

@nguathen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions