Skip to content

Memory index meta not written during --force reindex or gateway reload #91497

Description

@bottenbenny

Bug Summary

When the gateway reloads or openclaw memory index --force is executed, the meta table in the SQLite memory databases is not written. This causes the index identity check to fail on subsequent memory searches, resulting in:

  • Index identity: index metadata is missing (if meta was completely missing)
  • Index identity: index provider settings changed (if meta was present but providerKey mismatch)
  • Vector search: paused until memory is rebuilt

Reproduction Steps

  1. Ensure memory search is working (e.g., memory_search tool returns results)
  2. Trigger a gateway reload OR run openclaw memory index --force --agent <agent>
  3. After the reload/reindex completes, run openclaw memory status --agent <agent>
  4. Observe the index identity warning

Root Cause Analysis

The meta write happens in runSafeReindex() at manager-dZw31DAG2.js around line 2260-2280:

const meta = {
    model: this.provider?.model ?? "fts-only",
    provider: this.provider?.id ?? "none",
    providerKey: this.providerKey,
    // ...
};
this.writeMeta(meta);

The issue is that this.provider and this.providerKey may not be initialized when writeMeta is called during the --force reindex flow. The provider initialization is lazy — ensureProviderInitialized() is called elsewhere (e.g., before sync()) but not before the safe reindex path writes meta.

When the provider is not initialized:

  • this.provider?.model resolves to undefined (not the default model)
  • this.providerKey is undefined or computed incorrectly
  • The meta table ends up with an empty model or wrong providerKey

Additionally, after the config change is applied and the gateway hot-reloads, the memory managers are recreated and the old meta rows may be lost during the atomic reindex swap (the build() function in runSafeReindex creates a fresh temp DB, but the provider isn't initialized before writeMeta runs).

Expected Behavior

openclaw memory index --force should always write a correct meta row with the resolved model, provider, and providerKey, matching the actual embeddings used to index the chunks.

Actual Behavior

meta is either missing or contains incorrect values (empty model, wrong providerKey), causing the index identity check to fail on the next status check or search.

Workaround

Manually insert the correct meta row into ~/.openclaw/memory/<agent>.sqlite:

import sqlite3, json
meta = {
    "model": "text-embedding-3-small",
    "provider": "openai",
    "providerKey": "<computed_provider_key>",
    "sources": ["memory"],
    "scopeHash": "<computed_scope_hash>",
    "chunkTokens": 400,
    "chunkOverlap": 80,
    "ftsTokenizer": "unicode61",
    "vectorDims": 1536
}
# INSERT INTO meta (key, value) VALUES ('memory_index_meta_v1', json.dumps(meta))

Suggested Fix

Ensure ensureProviderInitialized() is called before writeMeta() in the runSafeReindex/build() path. The provider must be fully initialized so that:

  • this.provider.model is resolved to the actual model (e.g., text-embedding-3-small)
  • this.providerKey is computed from providerRuntime.cacheKeyData (for OpenAI: includes provider, baseUrl, model, headers)

Specifically, in manager-dZw31DAG2.js around line 2260, add await this.ensureProviderInitialized() before building the meta object.

Environment

  • OpenClaw version: 2026.6.1
  • OS: Linux 6.8.0-124-generic
  • Node: v24.16.0
  • Memory backend: builtin (sqlite-vec)
  • Embedding provider: openai / text-embedding-3-small
  • Affected agents: main, engineer, writer (all agents with memory search enabled)

Related Code Locations

  • manager-dZw31DAG2.js:2260-2280writeMeta(meta) in runSafeReindex
  • manager-dZw31DAG2.js:1130-1160resolveCurrentIndexIdentityState (reads meta for comparison)
  • manager-dZw31DAG2.js:2520-2528computeProviderKey() (providerKey computation)
  • memory-embedding-adapter-ebyy2fpA.js — OpenAI adapter, defines cacheKeyData used for providerKey

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions