Skip to content

[Feature]: memory_search returns stale/invalid results when gateway is long-running #52115

Description

@FicheallADa

Summary

Summary

The memory_search tool (invoked via the agent/tool chain, not CLI) has two related bugs when the gateway process has been running for a while:

  1. Stale index — After workspace files are created, renamed, or deleted, memory_search continues returning results based on the old index state. The CLI command openclaw memory search returns correct results for the same query at the same time.
  2. Ghost paths — Search results include file paths that no longer exist on disk, causing downstream read failures.

Both stem from the gateway's long-lived memory manager not re-syncing its index with the filesystem before serving queries.

Problem to solve

Expected vs Actual

Expected Actual
New file created Appears in search results Not found until gateway restart
File deleted/moved Removed from results Old path still returned
Returned paths All exist on disk Some are stale / non-existent

Proposed solution

Steps to Reproduce

# 1. Start gateway
openclaw gateway start

# 2. Query via tool: memory_search("user preferences")
# Note the results.

# 3. Create a new file highly relevant to the query
# e.g. memory/user-preferences-test.md with matching content

# 4. Without restarting gateway, query again
# → new file does NOT appear (stale index)

# 5. Delete a file that appeared in step 2, then query again
# → deleted file's path still appears (ghost path)

# Control: `openclaw memory search "user preferences"` via CLI
# returns correct results — it creates a fresh manager each time.

### Alternatives considered

_No response_

### Impact### Evidence/examples

_No response_

### Additional information

_No response_

Metadata

Metadata

Assignees

No one assigned

    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.enhancementNew feature or requestimpact: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.no-staleExclude from stale automation

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions