Skip to content

Memory index meta never written when gateway auto-sync finds identity missing with existing chunks #90338

Closed

Description

@junxuku-byte

Bug Report

Version: OpenClaw 2026.6.1 (2e08f0f)
OS: macOS 15.4.0 (arm64, M4 Mac Mini)

Summary

The gateway's memory auto-sync creates a dead loop: it indexes files (creating chunks) but never writes the meta table entry (memory_index_meta_v1), so indexIdentityState remains "missing" forever. All memory_search calls return "index metadata is missing" with 0 results.

Root Cause (from source analysis)

In manager-dZw31DAG2.js, the runSync() method at ~line 2073:

if (indexIdentity.status !== "valid" && !needsFullReindex) {
    this.dirty = true;
    // ... mark sessions dirty
    return;  // ← Returns without writing meta!
}

The condition needsFullReindex is false when hasIndexedChunks is true (which it is, because the sync itself just created chunks). So after the first sync cycle:

  1. Identity is "missing" (no meta)
  2. hasIndexedChunks = true (sync created chunks)
  3. needsInitialIndex = false (has chunks)
  4. needsExplicitIdentityReindex = false (not CLI-triggered)
  5. Early return without writing meta
  6. Next sync → same loop

Reproduction

  1. Start with an empty meta table in omes-vec.db (e.g., after DB corruption or version upgrade)
  2. openclaw gateway start
  3. Gateway auto-sync runs, indexes files, creates chunks
  4. memory_search returns "index metadata is missing"
  5. Running openclaw memory index --force from CLI writes meta correctly
  6. But gateway restart clears meta again (gateway re-syncs from scratch)

Workaround Attempted

  • openclaw gateway stop → clear DB → openclaw memory index --force → openclaw gateway start
  • Gateway starts, sees existing chunks, but still enters the dead loop because its sync finds identity "missing" and hasIndexedChunks=true

Environment

  • Embedding provider: openai-compatible (local oMLX on localhost:8000, model bge-m3-mlx-fp16)
  • DB: ~/.openclaw/memory/omes-vec.db (SQLite with sqlite-vec)
  • Extra paths: 4 external directories (~1200 files total)
  • 6 agents configured, all show providerState: pending after gateway starts

Expected Behavior

When gateway auto-sync encounters identity "missing" but has indexed chunks (from its own sync or CLI), it should either:

  1. Write meta after completing the sync (even if identity is still "missing"), OR
  2. Treat "identity missing + has chunks from current sync" as needsInitialIndex = true

Activity

  1. clawsweeper commented on Jun 4, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 4, 2026, 9:27 AM ET / 13:27 UTC.

    Summary
    This should stay open: current main and v2026.6.1 still contain the reported memory-index state where missing metadata plus existing chunks leaves the manager dirty and search paused instead of repairing the metadata or rebuilding.

    Reproducibility: yes. at source level: current code can be put in the reported state by indexing chunks, deleting memory_index_meta_v1, and running non-CLI sync/search. I did not run a live gateway repro in this read-only pass.

    Next step
    This is a narrow, source-reproducible memory-index consistency bug with clear likely files and validation.

    Review details

    Best possible solution:

    Make the memory manager recover missing metadata with existing chunks by forcing the existing safe reindex path or by writing validated metadata, then cover that gateway-style state with a focused regression test.

    Do we have a high-confidence way to reproduce the issue?

    Yes, at source level: current code can be put in the reported state by indexing chunks, deleting memory_index_meta_v1, and running non-CLI sync/search. I did not run a live gateway repro in this read-only pass.

    Is this the best way to solve the issue?

    Yes, the narrow maintainable fix belongs in the existing memory-index manager recovery/reindex decision, not in a new config option or gateway-specific workaround.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • A live gateway/database reproduction was not run in this read-only review, so the proof is source-level plus existing test behavior.
    • The repair must avoid searching stale chunks from a mismatched index; missing metadata should trigger a safe rebuild or a validated metadata repair, not an unconditional trust of existing rows.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 550f70756574.

    Label changes

    Label changes:

    • add P2: The bug can make memory search unusable for affected local-memory users, but it is scoped to memory-index recovery and has a reported manual force-index workaround.
    • add impact:session-state: The issue is about persistent memory-index metadata drifting from indexed chunks, which affects recall and session memory state.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

    Label justifications:

    • P2: The bug can make memory search unusable for affected local-memory users, but it is scoped to memory-index recovery and has a reported manual force-index workaround.
    • impact:session-state: The issue is about persistent memory-index metadata drifting from indexed chunks, which affects recall and session memory state.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs extensions/memory-core/src/memory/index.test.ts
    • node scripts/run-vitest.mjs extensions/memory-core/src/memory/manager-reindex-state.test.ts

    What I checked:

    Likely related people:

    • steipete: The available blame and shortlog for the memory manager, identity-state, and adjacent regression tests point to Peter Steinberger on the relevant current-main files. (role: recent area contributor; confidence: medium; commits: e900428a472d, 550f70756574; files: extensions/memory-core/src/memory/manager-sync-ops.ts, extensions/memory-core/src/memory/manager.ts, extensions/memory-core/src/memory/index.test.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on Jun 4, 2026
  3. mnowrot commented on Jun 4, 2026

    @mnowrot
    Contributor

    Confirming this on Linux (v2026.6.1) with builtin provider. Additionally found that even when meta IS written (via CLI --force while gateway is running), the running gateway never sees it because the atomic rename() swap in runSafeReindex only replaces the directory entry — the gateway process holds an open fd to the old inode and there's no re-open path.

    Also found resolveInitialMemoryDirty() at line ~3188 always returns true for memory-source agents on startup, guaranteeing a reindex every boot regardless of actual state.

    Full details cross-posted on #90042.

  4. added a commit that references this issue on Jun 6, 2026
    be3db39
  5. self-assigned this
    on Jun 8, 2026
  6. vincentkoc commented on Jun 8, 2026

    @vincentkoc
    Member

    Fixed on main in d46dc39.

    What changed:

    • Gateway/background sync now treats missing memory index metadata as repairable through the existing full reindex path when the configured embedding provider is available.
    • The repair uses the production safe-reindex path in the regression, so metadata is rewritten with the rebuilt index and stale rows are dropped.
    • If existing semantic chunks are present but embeddings are currently unavailable, sync stays dirty/paused instead of replacing the semantic index with an FTS-only rebuild.

    Proof run on the pushed patch:

    • node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-memory.config.ts extensions/memory-core/src/memory/index.test.ts extensions/memory-core/src/memory/manager-reindex-state.test.ts -> 49 passed.
    • node scripts/run-oxlint.mjs extensions/memory-core/src/memory/manager-sync-ops.ts extensions/memory-core/src/memory/index.test.ts -> clean.
    • git diff --check -> clean.
    • .agents/skills/autoreview/scripts/autoreview --mode local -> autoreview clean: no accepted/actionable findings reported.

    Remote proof: origin/main resolves to d46dc39b18ec0fdc8c9967f0a8301949b2e5a9e3. GitHub checks for that exact SHA had started at closeout; no failures observed yet, several checks still pending/in progress.

  7. added a commit that references this issue on Jun 8, 2026
    d46dc39
  8. added a commit that references this issue on Jun 9, 2026
    cfe377c
  9. locked as resolved and limited conversation to collaborators on Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions