Skip to content

fix(memory-wiki): avoid full vault reads for multi-term metadata searches - #166355

Merged
obviyus merged 1 commit into
mainfrom
fix/memory-wiki-digest-prefilter-166302
Oct 7, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/memory-wiki-digest-prefilter-166302

Conversation

@obviyus

@obviyus obviyus commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #166302

What Problem This Solves

Multi-term wiki_search queries read the whole vault even when every query token appears in a page's compiled metadata, because the digest prefilter requires a contiguous phrase.

User Impact

Queries can use the existing digest candidate path when all their tokens match compiled metadata. Scoring, result formatting, fallback behavior, and stored data formats are unchanged; no migration or recompile is required for this fix.

Why This Change Was Made

Reuse the existing query tokens and lineMatchesQuery helper for digest admission rather than introducing a separate tokenizer or matching policy. Update the stale scoring comment and add a regression that checks result equality with a live scan while ensuring unrelated pages are not opened.

Thanks to @etzelm for the report and analysis.

Evidence

Built baseline (24b93dea01ea65f3f9e8944c998656ad6baccef6) and candidate Gateways in an isolated Linux/Node 24 container. Invoked the real wiki_search tool through POST /tools/invoke against a generated 3,000-page compiled vault, requesting the top result. Counted actual Markdown file opens:

Query/control Baseline page opens Candidate page opens
cobalt quartz amber lantern (tokens spread across title, ID, aliases, questions; never a phrase) 3,000 1
Single term 1 1
Exact phrase in metadata 1 1
No all-token metadata match, matching body fallback 3,000 3,000
route-question 1 1

All five result objects, including scores and snippets, were identical before and after. The distributed-token result retained score 32.

  • Regression fails on baseline because it opens an unrelated page; passes with the fix.
  • query.reads.test.ts and query.test.ts: 81 tests passed, 29.81 seconds wall time for the focused wrapper invocation (CI time pending).
  • Real pnpm tsgo:extensions typecheck completed without diagnostics; built candidate with pnpm build.
  • One real gpt-5-mini call with low reasoning and a 4,096-token output budget selected wiki_search; executing its arguments through the built candidate Gateway returned the expected page.

The existing candidate limit and full-scan fallback remain unchanged. A query still scans remaining pages when digest candidates do not fill the requested result count.

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@obviyus

obviyus commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus marked this pull request as ready for review October 7, 2026 00:13
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 8:18 PM ET / October 7, 2026, 00:18 UTC.

ClawSweeper review

What this changes

Memory Wiki’s search now admits compiled metadata containing all query tokens, avoiding unnecessary page reads when those candidates fill the requested results, with a regression covering that behavior.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still has the reported admission mismatch. The focused repair and supplied production-path evidence support it, and no actionable introduced defect was found.

Priority: P2
Reviewed head: ba70109dd3769dcd3e59d04c9d95d040afbd6127

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and relevant before/after production-path evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured baseline/candidate Gateway evidence exercises the changed Memory Wiki search owner through POST /tools/invoke in isolated Linux/Node 24 containers: distributed metadata tokens reduce page opens from 3,000 to 1 with identical results, while four relevant controls preserve behavior. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured baseline/candidate Gateway evidence exercises the changed Memory Wiki search owner through POST /tools/invoke in isolated Linux/Node 24 containers: distributed metadata tokens reduce page opens from 3,000 to 1 with identical results, while four relevant controls preserve behavior. No stored-data contract changes.
Evidence reviewed 10 items Pinned introduced change: The merge-base-to-head diff changes only the digest admission predicate, its explanatory comment, and one search-boundary regression. The predicate reuses the existing phrase-or-all-token matcher rather than creating another matching policy.
Current main still needs the repair: Fetched main still requires metadataLower.includes(queryLower) for ordinary digest admission. Its live scorer accepts distributed query tokens, establishing that this PR addresses a remaining mismatch rather than duplicating a current-main fix.
Fallback and security boundaries remain intact: Complete query.ts inspection shows unchanged candidate limits, live scoring, result formatting, page visibility filtering, and remaining-page fallback when results underfill. query-pages.ts continues reading through the existing vault-boundary owner; candidate matching does not grant new authority.
Findings None None.
Security None None.

How this fits together

Memory Wiki searches OpenClaw’s Markdown knowledge vault using compiled metadata to select pages before reading and scoring them. Its results feed agent tools, CLI searches, and Gateway clients.

flowchart TD
  A[Wiki search query] --> C[Metadata candidate selection]
  B[Compiled vault metadata] --> C
  C --> D[Read candidate pages]
  D --> E[Visibility checks and scoring]
  E --> F{Enough results}
  F -->|Yes| H[Ranked search results]
  F -->|No| G[Read remaining vault pages]
  G --> E
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +41. Total +41 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 41 0 +41
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 44 3 +41

Review metrics

Metric Value Why it matters
Observed page reads 3,000 → 1 for the distributed-token scenario Contributor runtime evidence measures the intended search improvement while preserving all five control result objects.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166302
Summary: This PR is the explicit implementation candidate for the canonical digest-admission issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Use the existing token matcher for digest admission while retaining live scoring, visibility checks, and the documented body-search fallback.

Do we have a high-confidence way to reproduce the issue?

Yes: current-main source rejects distributed metadata tokens before selecting pages, forcing a full scan when no phrase candidate exists. Contributor baseline/candidate Gateway measurements corroborate this path; the reviewer did not execute it.

Is this the best way to solve the issue?

Yes: reusing the existing phrase-or-all-token matcher is a narrow repair of candidate admission, and the regression observes unrelated reads rather than merely testing the predicate.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against de3d26ee61a0.

Labels

Label changes:

  • add P2: This focused repair reduces avoidable large-vault search work without addressing the separate broader fallback and execution costs.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured baseline/candidate Gateway evidence exercises the changed Memory Wiki search owner through POST /tools/invoke in isolated Linux/Node 24 containers: distributed metadata tokens reduce page opens from 3,000 to 1 with identical results, while four relevant controls preserve behavior. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured baseline/candidate Gateway evidence exercises the changed Memory Wiki search owner through POST /tools/invoke in isolated Linux/Node 24 containers: distributed metadata tokens reduce page opens from 3,000 to 1 with identical results, while four relevant controls preserve behavior. No stored-data contract changes.

Label justifications:

  • P2: This focused repair reduces avoidable large-vault search work without addressing the separate broader fallback and execution costs.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured baseline/candidate Gateway evidence exercises the changed Memory Wiki search owner through POST /tools/invoke in isolated Linux/Node 24 containers: distributed metadata tokens reduce page opens from 3,000 to 1 with identical results, while four relevant controls preserve behavior. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured baseline/candidate Gateway evidence exercises the changed Memory Wiki search owner through POST /tools/invoke in isolated Linux/Node 24 containers: distributed metadata tokens reduce page opens from 3,000 to 1 with identical results, while four relevant controls preserve behavior. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff changes only the digest admission predicate, its explanatory comment, and one search-boundary regression. The predicate reuses the existing phrase-or-all-token matcher rather than creating another matching policy. (extensions/memory-wiki/src/query.ts:538, ba70109dd376)
  • Current main still needs the repair: Fetched main still requires metadataLower.includes(queryLower) for ordinary digest admission. Its live scorer accepts distributed query tokens, establishing that this PR addresses a remaining mismatch rather than duplicating a current-main fix. (extensions/memory-wiki/src/query.ts:538, de3d26ee61a0)
  • Fallback and security boundaries remain intact: Complete query.ts inspection shows unchanged candidate limits, live scoring, result formatting, page visibility filtering, and remaining-page fallback when results underfill. query-pages.ts continues reading through the existing vault-boundary owner; candidate matching does not grant new authority. (extensions/memory-wiki/src/query.ts:867, ba70109dd376)
  • Meaningful regression coverage: The added test distributes tokens across title, ID, aliases, and questions, compares compiled search with the uncompiled search result, and observes that an unrelated Markdown page is not opened. It uses the existing filesystem observation hook and cleanup, with no new production test seam. (extensions/memory-wiki/src/query.reads.test.ts:36, ba70109dd376)
  • After-fix production-path evidence: The captured PR body, sourceRevision d8f44da3e1862b58288dd0f3a93e0925c01ac8903695b394efda2caac49ce4f1, reports baseline and candidate built Gateways in isolated Linux/Node 24 containers, exercising wiki_search through POST /tools/invoke against a compiled 3,000-page vault. Distributed-token search reduced actual Markdown opens from 3,000 to 1; single-term, phrase, body-fallback, and route-question controls preserved their read counts. All five result objects were identical. This directly exercises createWikiSearchTool calling the changed search owner; it is contributor-supplied runtime evidence, not reviewer execution. (extensions/memory-wiki/src/tool.ts:173, ba70109dd376)
  • Established retrieval and stored-state contracts: The docs describe compiled digests as a first search pass. Inspection of the compiled snapshot types and loader confirms the patch only queries existing fields: it changes no persisted schema, serialization, publication, configuration, or migration contract. Public docs: docs/plugins/memory-wiki.md. (docs/plugins/memory-wiki.md:268, ba70109dd376)

Likely related people:

  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@obviyus
obviyus merged commit 3b6b191 into main Oct 7, 2026
171 of 172 checks passed
@obviyus
obviyus deleted the fix/memory-wiki-digest-prefilter-166302 branch October 7, 2026 00:22
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…ches (openclaw#166355)

Admit digest candidates whose metadata contains every query token, matching the live page scorer, so multi-term wiki_search queries no longer fall back to reading the whole vault. Analysis by @etzelm.

Fixes openclaw#166302.

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

Labels

extensions: memory-wiki P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: memory-wiki: digest prefilter admits only exact-phrase matches, so multi-term wiki searches always read the whole vault

1 participant