openclaw - 💡(How to fix) Fix [Feature]: memory_search returns stale/invalid results when gateway is long-running [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#52115Fetched 2026-04-08 01:15:28
View on GitHub
Comments
2
Participants
3
Timeline
3
Reactions
0
Timeline (top)
commented ×2labeled ×1

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.

Root Cause

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.

RAW_BUFFERClick to expand / collapse

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

ExpectedActual
New file createdAppears in search resultsNot found until gateway restart
File deleted/movedRemoved from resultsOld path still returned
Returned pathsAll exist on diskSome 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_

extent analysis

Fix Plan

To address the stale index and ghost paths issues, we need to ensure the gateway's memory manager re-syncs its index with the filesystem before serving queries. Here are the steps:

  • Re-sync index on query: Modify the memory_search tool to re-sync the index with the filesystem before executing the query.
  • Use a filesystem watcher: Implement a filesystem watcher to monitor changes to the workspace files and update the index accordingly.
  • Remove ghost paths: When a file is deleted or moved, remove its path from the index to prevent ghost paths.

Example Code

import os
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class WorkspaceWatcher(FileSystemEventHandler):
    def __init__(self, index):
        self.index = index

    def on_created(self, event):
        # Update index with new file
        self.index.add_file(event.src_path)

    def on_deleted(self, event):
        # Remove file from index
        self.index.remove_file(event.src_path)

    def on_moved(self, event):
        # Update index with new file path
        self.index.update_file(event.src_path, event.dest_path)

class MemoryManager:
    def __init__(self):
        self.index = {}
        self.watcher = WorkspaceWatcher(self.index)
        self.observer = Observer()
        self.observer.schedule(self.watcher, path='.', recursive=True)
        self.observer.start()

    def re_sync_index(self):
        # Re-sync index with filesystem
        self.index = {}
        for root, dirs, files in os.walk('.'):
            for file in files:
                self.index[file] = os.path.join(root, file)

    def search(self, query):
        # Re-sync index before searching
        self.re_sync_index()
        # Execute search query
        results = []
        for file, path in self.index.items():
            if query in file:
                results.append(path)
        return results

# Usage
manager = MemoryManager()
results = manager.search("user preferences")

Verification

To verify the fix, follow these steps:

  • Start the gateway and create a new file relevant to the query.
  • Query the memory_search tool without restarting the gateway.
  • Verify that the new file appears in the search results.
  • Delete a file that appeared in the previous search results and query again.
  • Verify that the deleted file's path no longer appears in the search results.

Extra Tips

  • Consider using a more robust filesystem watcher library to handle edge cases.
  • Implement logging to monitor index updates and search queries.
  • Test the fix thoroughly to ensure it resolves the stale index and ghost paths issues.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Feature]: memory_search returns stale/invalid results when gateway is long-running [2 comments, 3 participants]