Repository navigation
fix(memory): qualify stale memory search results - #117706
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed August 1, 2026, 8:26 PM ET / August 2, 2026, 00:26 UTC. ClawSweeper reviewWhat this changesThe branch adds Merge readiness⛔ Blocked until real behavior proof is added - 5 items remain This PR remains necessary: current Priority: P1 Review scores
Verification
How this fits togetherMemory Core indexes agent memory files and serves searches to operators through the CLI, to integrations through Gateway, and to models through flowchart LR
A[Agent memory files] --> B[Memory index manager]
B --> C[Bounded search-time refresh]
C --> D{Index remains dirty?}
D -->|No| E[Normal results]
D -->|Yes| F[Stale warning and repair action]
E --> G[CLI, Gateway, and agent tool]
F --> G
Decision needed
Why: The mechanical fix is coherent, but this changes a public plugin-facing export and a Gateway response shape; repository policy asks for maintainer-visible acceptance of plugin API surface changes. Before merge
Agent review detailsSecurityNone. PR surfaceSource +14, Tests +98, Docs +6. Total +118 across 11 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one shared stale-result qualification helper, preserve bounded search behavior, document the additive result fields, and land only after a redacted after-fix transcript proves an actual dirty-index search returns the warning and repair action. Do we have a high-confidence way to reproduce the issue? Yes, from source and the supplied production report: a search can complete while the manager status remains dirty, and current Is this the best way to solve the issue? Yes, with maintainer acceptance of the additive contract: surfacing residual staleness at the shared result boundary is safer than silently returning a miss or forcing an expensive rebuild during search. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d976f8828b60. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Maintainer decision and after-fix runtime proof for head Peter Steinberger (@steipete), the Memory Core owner and PR author, explicitly authorized landing this PR. That accepts the additive optional I also ran the built CLI against a fully isolated temporary state directory with {
"dirty": true,
"sources": ["memory", "sessions"],
"indexIdentity": {
"status": "mismatched",
"reason": "index scope changed"
}
}The next real CLI search returned: {
"results": [],
"stale": true,
"warning": "Memory index is stale: index scope changed. Search results may be incomplete.",
"action": "Run: openclaw memory status --index --agent main"
}This supplies the requested inspectable after-fix proof that a dirty index no longer produces an authoritative-looking bare empty result. The temporary fixture uses only the synthetic codeword |
|
Merged via squash.
|
* fix(memory): qualify stale search results * fix(memory): satisfy staleness checks * fix(memory): normalize absent staleness
What Problem This Solves
memory searchcould report "no results" for a memory that exists, with nothing indicating anything was wrong.Reproduced on a production host (agent
roboclaw):~/.openclaw/workspace/memory/2026-08-01.md:- Secret perf-test codeword: ZEBRA-COMET-20260801T222919Z.openclaw memory search "ZEBRA-COMET" --agent roboclaw --json→{"results": []}. Same for"ZEBRA"and"codeword". Exit 0, nothing on stderr.openclaw memory status --agent roboclawat that same moment reported the truth:Indexed: 375/36 files · 777 chunks,Dirty: yes,FTS: ready.openclaw memory index --agent roboclaw, the identical query returns the chunk (score 0.6365, vectorScore 0.5008, textScore 0.9465).The agent's automatic recall surfaced the fact correctly in a fresh session throughout — only the explicit search surface was wrong.
Per the repo's own severity order, silent failure ranks above crashes: an empty result set is indistinguishable from "this memory does not exist". The owning surface already knew the index was stale —
statusrenders it — so this was a recorded fact that was not read where it was needed.The
memory_searchagent tool shares this path, which is the more serious half: a model asking "what do I know about X?" could be handed an authoritative-looking empty answer and confidently tell the user nothing was ever recorded.Why This Change Was Made
The stored index identity is compared against the active provider, model, sources, scope, and chunking settings. A mismatch sets
indexIdentityDirty, andstatusexposes it viadirtyandcustom.indexIdentity.Search awaits a bounded
reason: "search"sync. But an existing index whose identity changed requires a full shadow rebuild, and that explicit repair is authorized only forreason: "cli". Search therefore left the index dirty, refreshed the identity, and returned a bare[]. The CLI JSON path then serialized only{ results }, discarding the staleness the manager already knew.Two options were considered. Making search rebuild automatically was rejected: an identity change (provider, model, configured scope, sources, or chunking) requires re-embedding the corpus, so it would turn a query — including a mid-turn agent tool call — into an unbounded, API-cost-bearing full-index operation, conflicting with the existing bounded search-time refresh design and with existing regression protection against full search/watch reindexes.
Instead the staleness is surfaced in the shared result contract, once, at the owner. A new helper converts residual dirty or invalid-identity status into
stale,warning, andactionfields, and is consumed by all three surfaces: the CLI (JSON and human output), the Gatewaymemory.searchmethod, and thememory_searchagent tool. Successful bounded incremental refreshes still clear dirty state and return the unchanged clean shape, so healthy searches are byte-identical to before.The agent tool's description now instructs the model to surface that guidance, consistent with treating tool results as prompts: the model is told what happened and what to do next rather than silently inheriting a false negative.
Automatic recall, ranking, dreaming, embeddings, vector storage, and recall-store behavior are unchanged.
User Impact
A stale index can no longer masquerade as an empty memory. Searches against a dirty or identity-mismatched index now return, alongside any results:
{ "stale": true, "warning": "Memory index is stale: index scope changed. Search results may be incomplete.", "action": "Run: openclaw memory status --index --agent main" }Healthy searches are unaffected — no new field, no behavior change. Nothing rebuilds implicitly, so no query becomes unexpectedly slow or expensive.
Evidence
node scripts/run-vitest.mjs extensions/memory-core/src/memory/manager.async-search.test.ts: 7/7 passed.pnpm installclean on first attempt.gpt-5.6-sol, high): clean, no accepted/actionable findings, "patch is correct" (0.86).Net production TypeScript +6 lines (41 added / 35 removed). Tests +103. Docs +6.