Skip to content

fix(memory): DB deletion should force full session reindex #11728

@jlian

Description

@jlian

Bug

When the memory search SQLite database is deleted and the gateway restarts, needsFullReindex correctly becomes true for memory files, but session files are not fully reindexed.

Root Cause

In syncSessionFiles, indexAll is computed as:

const indexAll = params.needsFullReindex || this.sessionsDirtyFiles.size === 0;

During runSafeReindex, this is called with needsFullReindex: true, which should set indexAll = true. However, the active session immediately marks itself in sessionsDirtyFiles (size becomes 1), which means on subsequent syncs (interval or search-triggered), indexAll evaluates to false since needsFullReindex is no longer true (meta now matches) and dirtyFiles.size === 1 (not 0).

The net result: after DB deletion + restart, only the currently active session gets reindexed. All other historical sessions remain unindexed until they accumulate enough new deltas to cross the dirty threshold.

Expected Behavior

Deleting the DB and restarting should result in a full reindex of all session files, not just the active one.

Workaround

Temporarily patching indexAll = ... || true in syncSessionFiles forces a full reindex. After the one-time reindex completes, revert the patch and rebuild.

Environment

  • OpenClaw from source (commit 3188147f7)
  • OpenAI text-embedding-3-small embeddings
  • 19 session files, only 1 (active) was being reindexed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    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