Skip to content

fix(memory): await search-sync before returning results to prevent stale index (fixes #52115)#93791

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
liuhao1024:fix/memory-search-sync-await-v2
Jun 17, 2026
Merged

fix(memory): await search-sync before returning results to prevent stale index (fixes #52115)#93791
vincentkoc merged 3 commits into
openclaw:mainfrom
liuhao1024:fix/memory-search-sync-await-v2

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

Real behavior proof

  • Behavior addressed: memory_search returns stale results when the gateway has been running for a while because startAsyncSearchSync fires off the index sync as a background task without waiting for completion.
  • Environment tested: macOS 26.4.1, OpenClaw build from upstream/main (7d4001c), Node.js v24
  • Steps run after the patch: Ran manager.async-search.test.ts and search-manager.test.ts suites, built the project with pnpm build
  • Evidence after fix:
$ grep -n "await.*startAsyncSearchSync\|async function startAsyncSearchSync" extensions/memory-core/src/memory/manager.ts extensions/memory-core/src/memory/manager-async-state.ts
extensions/memory-core/src/memory/manager.ts:633:    await startAsyncSearchSync({
extensions/memory-core/src/memory/manager-async-state.ts:2:export async function startAsyncSearchSync(params: {

$ node -e "const fs=require('fs'); const s=fs.readFileSync('extensions/memory-core/src/memory/manager-async-state.ts','utf8'); console.log('sync is awaited:', s.includes('await params.sync')); console.log('no fire-and-forget:', !s.includes('void params.sync'));"
sync is awaited: true
no fire-and-forget: true
  • Observed result after fix: startAsyncSearchSync is now async and awaits the sync operation before returning. The caller in MemoryIndexManager.search() awaits the result, ensuring the index is fresh before search results are read.
  • What was not tested: Live gateway long-running scenario. The behavioral change (fire-and-forget → await) is verified by the async-search test suite and code inspection.

@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 16, 2026
@vincentkoc vincentkoc self-assigned this Jun 16, 2026
liuhao1024 and others added 3 commits June 17, 2026 08:55
…ale index

When the gateway process has been running for a while, memory_search
returns stale results because startAsyncSearchSync fires off the index
sync as a background task (void ... .catch()) without waiting for it
to complete. Search results are then read from the old index state.

Change startAsyncSearchSync from sync/fire-and-forget to async/await
so that the index is synced before search results are returned. This
ensures memory_search reflects the current filesystem state, matching
the behavior of the CLI  command which creates
a fresh manager each time.

Fixes openclaw#52115
@vincentkoc
vincentkoc force-pushed the fix/memory-search-sync-await-v2 branch from c691e98 to 34d15b4 Compare June 17, 2026 00:55
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer repair applied and land-ready.

Verification:

  • node scripts/run-vitest.mjs extensions/memory-core/src/memory/index.test.ts extensions/memory-core/src/memory/manager.async-search.test.ts extensions/memory-core/src/memory/manager.reindex-recovery.test.ts — 65 passed
  • Blacksmith Testbox tbx_01kv9gqn15zway6n1cz0wrmw05check:changed passed
  • fresh autoreview — no accepted/actionable findings
  • git diff --check — clean

The repo-native prepare helper completed pnpm build but its broad local pnpm check hit the repeatable host-only database-first guard OOM. The remote changed gate is clean, the PR is mergeable, and GitHub reports no required checks.

@vincentkoc
vincentkoc merged commit b3a1472 into openclaw:main Jun 17, 2026
163 of 167 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 17, 2026
…ale index (fixes openclaw#52115) (openclaw#93791)

* fix(memory): await search-sync before returning results to prevent stale index

When the gateway process has been running for a while, memory_search
returns stale results because startAsyncSearchSync fires off the index
sync as a background task (void ... .catch()) without waiting for it
to complete. Search results are then read from the old index state.

Change startAsyncSearchSync from sync/fire-and-forget to async/await
so that the index is synced before search results are returned. This
ensures memory_search reflects the current filesystem state, matching
the behavior of the CLI  command which creates
a fresh manager each time.

Fixes openclaw#52115

* test(memory): prove search waits for dirty sync

* test(memory): align search with synchronous sync

---------

Co-authored-by: Vincent Koc <[email protected]>
crh-code pushed a commit to crh-code/openclaw that referenced this pull request Jun 18, 2026
…ale index (fixes openclaw#52115) (openclaw#93791)

* fix(memory): await search-sync before returning results to prevent stale index

When the gateway process has been running for a while, memory_search
returns stale results because startAsyncSearchSync fires off the index
sync as a background task (void ... .catch()) without waiting for it
to complete. Search results are then read from the old index state.

Change startAsyncSearchSync from sync/fire-and-forget to async/await
so that the index is synced before search results are returned. This
ensures memory_search reflects the current filesystem state, matching
the behavior of the CLI  command which creates
a fresh manager each time.

Fixes openclaw#52115

* test(memory): prove search waits for dirty sync

* test(memory): align search with synchronous sync

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core proof: supplied External PR includes structured after-fix real behavior proof. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants