Skip to content

fix(memory): qualify stale memory search results - #117706

Merged
steipete merged 3 commits into
mainfrom
codex/fix-memory-search-dirty-index
Aug 2, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/fix-memory-search-dirty-index

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

memory search could report "no results" for a memory that exists, with nothing indicating anything was wrong.

Reproduced on a production host (agent roboclaw):

  1. An agent turn wrote a fact to ~/.openclaw/workspace/memory/2026-08-01.md:
    - Secret perf-test codeword: ZEBRA-COMET-20260801T222919Z.
  2. openclaw memory search "ZEBRA-COMET" --agent roboclaw --json → {"results": []}. Same for "ZEBRA" and "codeword". Exit 0, nothing on stderr.
  3. openclaw memory status --agent roboclaw at that same moment reported the truth: Indexed: 375/36 files · 777 chunks, Dirty: yes, FTS: ready.
  4. After 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 — status renders it — so this was a recorded fact that was not read where it was needed.

The memory_search agent 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, and status exposes it via dirty and custom.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 for reason: "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, and action fields, and is consumed by all three surfaces: the CLI (JSON and human output), the Gateway memory.search method, and the memory_search agent 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.
  • New coverage asserts the qualified-result invariant for CLI JSON output, CLI human output, the agent tool, and the Gateway method, and asserts the clean path stays unqualified.
  • pnpm install clean on first attempt.
  • Autoreview (Codex 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: memory-core Extension: memory-core size: S maintainer Maintainer-authored PR labels Aug 2, 2026
@steipete steipete self-assigned this Aug 2, 2026
@steipete
steipete marked this pull request as ready for review August 2, 2026 00:07
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 1, 2026, 8:26 PM ET / August 2, 2026, 00:26 UTC.

ClawSweeper review

What this changes

The branch adds stale, warning, and action fields to Memory Core search responses when a bounded refresh leaves the index dirty, covering CLI output, Gateway memory.search, and the memory_search agent tool.

Merge readiness

⛔ Blocked until real behavior proof is added - 5 items remain

This PR remains necessary: current main does not qualify dirty Memory Core searches, while the branch carries the recorded stale-index fact into the CLI, Gateway, and model-facing tool. The implementation follows the shared owner-boundary direction and has focused regression coverage, but it still needs inspectable after-fix runtime proof before merge and a maintainer should explicitly accept the additive public result contract.

Priority: P1
Reviewed head: 166b121739273e3b90aff2347a85b3f946c528df
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation and focused coverage look coherent, but missing real after-fix behavior proof remains a merge gate.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR contains a detailed before-fix production report and mock-based tests, but no inspectable after-fix CLI, Gateway, or agent-tool output proving that a real dirty index now emits the qualified response. Attach redacted terminal output, logs, a recording, or a linked artifact; remove private paths, identifiers, endpoints, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR contains a detailed before-fix production report and mock-based tests, but no inspectable after-fix CLI, Gateway, or agent-tool output proving that a real dirty index now emits the qualified response. Attach redacted terminal output, logs, a recording, or a linked artifact; remove private paths, identifiers, endpoints, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 8 items Current main still lacks the behavior: The current checkout at d976f8828b60195eebed7958ffccfa65a61593ea has no resolveMemorySearchStaleness helper or optional stale-result fields in the shared type, CLI, Gateway method, or agent tool, so the PR is not obsolete or already implemented.
Shared staleness owner: The PR adds one helper that converts manager dirty state or an invalid index identity into a typed warning and repair command, keeping the qualification policy at the shared result-contract boundary.
All reported consumer paths receive the shared status: The CLI reads status after search and includes the qualification in JSON or emits it before human output; Gateway spreads the same helper into memory.search; the tool uses the helper after its search path.
Findings None None.
Security None None.

How this fits together

Memory Core indexes agent memory files and serves searches to operators through the CLI, to integrations through Gateway, and to models through memory_search. The manager records whether its index is dirty; this PR propagates that state after a search so downstream consumers can distinguish incomplete results from a definitive miss.

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
Loading

Decision needed

Question Recommendation
After real behavior proof is attached, should maintainers accept the additive Memory Core SDK and Gateway search-result contract that exposes residual index staleness? Accept the additive contract: Keep stale, warning, and action optional, verify a real dirty-index response, and merge the shared owner-boundary repair.

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

  • Add real behavior proof - Needs real behavior proof before merge: The PR contains a detailed before-fix production report and mock-based tests, but no inspectable after-fix CLI, Gateway, or agent-tool output proving that a real dirty index now emits the qualified response. Attach redacted terminal output, logs, a recording, or a linked artifact; remove private paths, identifiers, endpoints, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The branch adds optional fields to the Gateway result shape and exports a new helper through the Memory Core host SDK; tolerant consumers are safe, but strict response validators or external plugin consumers need the additive contract explicitly accepted.
  • Resolve merge risk (P1) - The PR has no inspectable after-fix runtime artifact yet, so the reported production failure and all three qualified output surfaces have not been independently observed on the proposed head.
  • Complete next step (P2) - No mechanical repair finding is present; the remaining gates are contributor-supplied real behavior proof and explicit maintainer acceptance of the public additive contract.
Agent review details

Security

None.

PR surface

Source +14, Tests +98, Docs +6. Total +118 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 7 50 36 +14
Tests 3 99 1 +98
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 155 37 +118

Review metrics

Metric Value Why it matters
Public result contract 3 optional result fields added CLI JSON, Gateway callers, and model-tool consumers can now receive stale-index qualification, so compatibility review should cover response parsing expectations.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/memory-core/src/cli-index-search.runtime.ts, unknown-data-model-change: extensions/memory-core/src/cli.test.ts, unknown-data-model-change: extensions/memory-core/src/tools.ts, vector/embedding metadata: extensions/memory-core/src/cli-index-search.runtime.ts, vector/embedding metadata: extensions/memory-core/src/cli.test.ts, vector/embedding metadata: extensions/memory-core/src/memory-tool-manager.test-mocks.ts, and 5 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Confirm the additive result contract (recommended)
    Accept the optional SDK and Gateway fields after a redacted runtime transcript proves stale searches are qualified without changing clean responses.
  2. Pause for a narrower boundary
    Do not merge if maintainers do not want to expose staleness through the host SDK and Gateway response contract.

Technical review

Best 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 main returns ordinary results without that recorded fact. This read-only environment did not run a fresh production or local reproduction.

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.

Labels

Label justifications:

  • P1: A dirty memory index can produce authoritative-looking empty results for operators and model recall.
  • merge-risk: 🚨 compatibility: The PR adds optional fields to the Gateway search response and exports a new Memory Core host-SDK helper.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR contains a detailed before-fix production report and mock-based tests, but no inspectable after-fix CLI, Gateway, or agent-tool output proving that a real dirty index now emits the qualified response. Attach redacted terminal output, logs, a recording, or a linked artifact; remove private paths, identifiers, endpoints, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current main still lacks the behavior: The current checkout at d976f8828b60195eebed7958ffccfa65a61593ea has no resolveMemorySearchStaleness helper or optional stale-result fields in the shared type, CLI, Gateway method, or agent tool, so the PR is not obsolete or already implemented. (packages/memory-host-sdk/src/host/types.ts:161, d976f8828b60)
  • Shared staleness owner: The PR adds one helper that converts manager dirty state or an invalid index identity into a typed warning and repair command, keeping the qualification policy at the shared result-contract boundary. (packages/memory-host-sdk/src/host/types.ts:164, 166b12173927)
  • All reported consumer paths receive the shared status: The CLI reads status after search and includes the qualification in JSON or emits it before human output; Gateway spreads the same helper into memory.search; the tool uses the helper after its search path. (extensions/memory-core/src/cli-index-search.runtime.ts:267, 166b12173927)
  • Search already has bounded refresh semantics: Current Memory Core search invokes a search-scoped synchronous bootstrap only when indexed content is absent, supporting the PR’s choice to warn after residual staleness rather than make every query perform an unbounded rebuild. (extensions/memory-core/src/memory/manager.ts:1112, d976f8828b60)
  • Focused coverage: The branch adds assertions for dirty CLI JSON and human output, the model-facing tool, and the Gateway method; its tool test also confirms the retry path remains bounded. (extensions/memory-core/src/tools.test.ts:982, 166b12173927)
  • Feature-history routing: The current Memory Manager contract and provider-status type appear to date to the recent Memory Core work in d0b362f2558e91e450124c8212c253a5bad316a8, authored by Peter Steinberger; the PR branch continues that same area. (packages/memory-host-sdk/src/host/types.ts:161, d0b362f2558e)

Likely related people:

  • steipete: Git history attributes the current MemoryProviderStatus and MemorySearchManager contract to Peter Steinberger, whose GitHub handle is steipete; the same person authored the focused branch. (role: current Memory Core contract author and recent area contributor; confidence: high; commits: d0b362f2558e, 00124bb3a36f, ebc32404d321; files: packages/memory-host-sdk/src/host/types.ts, extensions/memory-core/src/memory/manager.ts, extensions/memory-core/src/tools.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach a redacted after-fix CLI, Gateway, or memory_search transcript showing a dirty index returns stale, warning, and action.
  • Have the Memory Core owner explicitly accept the additive SDK and Gateway result contract.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-02T00:12:25.448Z sha 00124bb :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 2, 2026
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer decision and after-fix runtime proof for head 166b121739273e3b90aff2347a85b3f946c528df:

Peter Steinberger (@steipete), the Memory Core owner and PR author, explicitly authorized landing this PR. That accepts the additive optional stale, warning, and action result fields called out in the review.

I also ran the built CLI against a fully isolated temporary state directory with provider: "none"; no production state or credentials were used. I indexed a fixture, then added an extraPaths entry so the existing index identity became stale. The real status surface reported:

{
  "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 cobalt-lantern-117706.

@steipete
steipete merged commit 7d1d721 into main Aug 2, 2026
127 of 130 checks passed
@steipete
steipete deleted the codex/fix-memory-search-dirty-index branch August 2, 2026 00:40
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* fix(memory): qualify stale search results

* fix(memory): satisfy staleness checks

* fix(memory): normalize absent staleness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant