Skip to content

fix(memory-wiki): avoid repeated vault work for exact page reads - #129897

Merged
steipete merged 2 commits into
openclaw:mainfrom
BsnizND:fix/memory-wiki-get-fast-path
Sep 5, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
BsnizND:fix/memory-wiki-get-fast-path

Conversation

@BsnizND

@BsnizND BsnizND commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #116048. Related: #116374.

What Problem This Solves

Exact canonical wiki reads previously enumerated and parsed unrelated pages. Repeated initialization also hashed the entire compiled vault, and a cold local source sync could mistake an inactive cache owner for a missing snapshot and compile again.

This change reads canonical paths through the shared rooted page reader, reuses a reconciled owner during ordinary requests, and activates local source sync before checking index readiness. Cold activation, explicit lifecycle refresh, vault replacement and compile publication retain their existing validation. A fresh CLI process still validates the compiled snapshot; this is not a constant-time cold-start guarantee.

The reader preserves compiled-claim precedence, agent visibility, files larger than 16 MiB and hardlinks. Missing or non-file candidates fall through to existing discovery, including deleted pages nominated by an older compiled snapshot. Permission failures, symlink refusals and file-identity mismatches remain terminal across exact and scanned reads. There is one shared reader rather than a weaker fallback path.

Evidence

  • All 510 tests across 43 Memory Wiki test files passed. Regression failures were reproduced against main, the original PR and the intermediate lifecycle repair before applying their fixes.
  • Coverage includes exact/basename/ID equivalence for large and hardlinked pages, path-shaped claim IDs, visibility, missing/malformed/non-file fallback, three deterministic file-swap routes, deleted compiled candidates, cache reuse, restart, rollback and stale publication fencing.
  • Changed-file repository checks passed, including types, lint, dead exports, storage guards and runtime import cycles. Full pnpm build passed.
  • Independent source review and the final repository autoreview found no actionable findings. The earlier autoreview finding about deleted compiled candidates was reproduced and repaired at the shared reader.
  • Real built CLI and temporary loopback Gateway, using a synthetic 5,001-page vault with automatic compilation enabled: cold CLI exact read 2.383 s without changing the publication log; warm Gateway exact read 0.757 s; warm exact read with an unrelated unreadable page 0.699 s. These are end-to-end CLI timings, including client startup.
  • With that unreadable neighbor, basename scanning and cold snapshot validation still returned the expected permission error. The exact warm request returned the same target and requested line slice. The temporary Gateway was stopped afterward.

The first real-flow attempt on the original query-only candidate took 86.523 s and triggered compilation; it exposed the prerequisite lifecycle work addressed here. That first-run timing is not a like-for-like benchmark against the warm Gateway timings above.

Review decisions and scope

The prior ClawSweeper rank-up requests are addressed: hardlink support is retained and tested, while rooted filesystem boundary refusals are documented and tested across readers. The pinned fs-safe 0.8.1 source was directly inspected for explicit unlimited-byte and hardlink policies. No SQLite schema, stored format, configuration option, provider or protocol changes are introduced.

Production delta: +77/-9, net +68. The growth provides canonical-path validation and the lifecycle-owner reuse check; missing-candidate handling is consolidated in the existing reader. Tests: +301/-34, net +267; a redundant mocked no-op case is replaced by real SQLite lifecycle coverage. Docs: +9/-1. Release-note context is retained here; no changelog edit is needed before release generation.

Thanks to @BsnizND (Brian Snyder) for this PR and @sloptop-the-terrible for the original reproduction and direct-read direction in #116374. The contributor's original commit remains in this branch's ancestry.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@BsnizND
BsnizND marked this pull request as ready for review August 26, 2026 05:21
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 5, 2026, 12:45 AM ET / 04:45 UTC.

ClawSweeper review

What this changes

Memory Wiki avoids whole-vault work for warm exact page reads by sharing a rooted reader and reusing validated cache owners.

Merge readiness

⛔ Blocked before merge - 2 items remain

No blocking findings. The repair remains useful on current main, addresses the prior size and hardlink concerns, and has relevant CLI/Gateway proof.

Priority: P2
Reviewed head: f268ee0aea2630a8d0e4ab0e372c11494abf70ed

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair with useful regression coverage and relevant real CLI/Gateway evidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured built CLI and loopback Gateway results exercise query reading and local cache activation on a 5,001-page vault, preserve the requested line slice despite an unreadable neighbor, and show no cold-read republication. Dependency-source access limits this review, not that recorded proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured built CLI and loopback Gateway results exercise query reading and local cache activation on a 5,001-page vault, preserve the requested line slice despite an unreadable neighbor, and show no cold-read republication. Dependency-source access limits this review, not that recorded proof.
Evidence reviewed 14 items Current main still needs the repair: Current main falls through from compiled-claim lookup to readQueryableWikiPages before resolving an exact path. No merged replacement fixing this behavior is established by the supplied related-item context.
Shared reading boundary: Exact paths, compiled candidates, and scanned pages use the same rooted reader with explicit large-file and hardlink policies. Only not-found and not-file errors become missing candidates; other read failures propagate.
Entrypoints and visibility: The CLI, Gateway wiki.get method, wiki_get tool, and memory corpus supplement converge on getMemoryWikiPage. The new direct path retains compiled-claim precedence, the existing page resolver, and the same visibility filter.
Findings None None.
Security None None.

How this fits together

Memory Wiki turns Markdown vaults into searchable knowledge and compiled snapshots. CLI commands, Gateway requests, and agent tools use its query layer to return visible pages and requested line slices.

flowchart TD
  A[CLI, Gateway, or agent request] --> B[Activate or reuse vault owner]
  B --> C[Check compiled claim lookup]
  C --> D[Read eligible exact path]
  C --> E[Discover fallback pages]
  D --> F[Shared rooted page reader]
  E --> F
  F --> G[Apply visibility and return line slice]
Loading

Before merge

  • Resolve merge risk (P1) - Independent fs-safe 0.8.1 source verification remains incomplete in this worker because dependency sources were unavailable and network resolution failed; the recorded real-behavior proof remains valid.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +68, Tests +267, Docs +8. Total +343 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 77 9 +68
Tests 3 301 34 +267
Docs 1 9 1 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 387 44 +343

Review metrics

Metric Value Why it matters
Production versus tests Production net +68 lines; tests net +267 lines Production growth supplies canonical-path validation, shared boundary-error handling, and lifecycle reuse without adding a second reader or persistent cache.

Stored data model

Persistent data-model change detected: serialized state: extensions/memory-wiki/src/query.ts, unknown-data-model-change: extensions/memory-wiki/src/query.ts, vector/embedding metadata: extensions/memory-wiki/src/compiled-cache.ts, vector/embedding metadata: extensions/memory-wiki/src/query.ts, vector/embedding metadata: extensions/memory-wiki/src/source-sync.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #116048
Summary: This PR is a candidate repair for the canonical exact-path scan issue; the overlapping open PR does not establish a safe supersession.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one rooted page-reading boundary, with compile and lifecycle activation owning snapshot freshness; explicit path validation and missing-candidate handling justify the bounded production growth.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one rooted page-reading boundary, with compile and lifecycle activation owning snapshot freshness; explicit path validation and missing-candidate handling justify the bounded production growth.

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

Yes, from source: current main enumerates the vault before resolving an ordinary exact path, so an unrelated unreadable page can reject it. This read-only review did not execute a failing current-main run.

Is this the best way to solve the issue?

Yes for the reported exact-read failure: the patch repairs the plugin-owned reader and lifecycle setup while preserving shared lookup and visibility rules.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d5992278b3b8.

Labels

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This fixes avoidable vault-wide work and unrelated-page failures in the optional Memory Wiki read path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 built CLI and loopback Gateway results exercise query reading and local cache activation on a 5,001-page vault, preserve the requested line slice despite an unreadable neighbor, and show no cold-read republication. Dependency-source access limits this review, not that recorded proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured built CLI and loopback Gateway results exercise query reading and local cache activation on a 5,001-page vault, preserve the requested line slice despite an unreadable neighbor, and show no cold-read republication. Dependency-source access limits this review, not that recorded proof.

Evidence

What I checked:

  • Current main still needs the repair: Current main falls through from compiled-claim lookup to readQueryableWikiPages before resolving an exact path. No merged replacement fixing this behavior is established by the supplied related-item context. (extensions/memory-wiki/src/query.ts:1231, d5992278b3b8)
  • Shared reading boundary: Exact paths, compiled candidates, and scanned pages use the same rooted reader with explicit large-file and hardlink policies. Only not-found and not-file errors become missing candidates; other read failures propagate. (extensions/memory-wiki/src/query.ts:233, f268ee0aea26)
  • Entrypoints and visibility: The CLI, Gateway wiki.get method, wiki_get tool, and memory corpus supplement converge on getMemoryWikiPage. The new direct path retains compiled-claim precedence, the existing page resolver, and the same visibility filter. (extensions/memory-wiki/src/query.ts:1267, f268ee0aea26)
  • Lifecycle ownership remains explicit: Initialization reuses only a reconciled owner matching the vault path and generation. Plugin service startup still clears prior owners and validates durable identities; compile publication still fences retired owners and changed publications. (extensions/memory-wiki/src/vault.ts:161, f268ee0aea26)
  • Existing freshness contract: Documentation assigns compiled freshness to compilation and plugin lifecycle refresh, including cross-process publication and rollback handling. The warm-owner optimization follows this existing contract. Public docs: docs/plugins/memory-wiki.md. (docs/plugins/memory-wiki.md:205, f268ee0aea26)
  • Regression coverage inspected: Added filesystem tests cover exact/basename/ID equivalence for large and hardlinked pages, claim precedence, visibility, missing candidates, and three file-swap routes. SQLite lifecycle coverage checks inactive-owner reuse, repeated initialization, explicit refresh, and rollback; existing restart and stale-publication tests remain. (extensions/memory-wiki/src/query.reads.test.ts:34, f268ee0aea26)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-26T05:29:05.779Z sha ba07cb2 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-26T05:45:53.710Z sha ba07cb2 :: needs maintainer review before merge. :: none

@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Reviewed head ba07cb2 while selecting small, high-certainty performance fixes. The exact-path optimization targets a real full-vault scan, but I am holding this PR for two observable compatibility regressions at extensions/memory-wiki/src/query.ts:1278.

  • [P2] Preserve the same size contract across lookup forms. vault.readText(relativePath) inherits the pinned @openclaw/[email protected] default limit of 16 MiB. The existing readQueryableWikiPagesByPaths uses fs.readFile without that limit. A valid page larger than 16 MiB therefore fails with too-large when requested by canonical path, while its basename/ID lookup still reaches the old reader. This also changes shipped v2026.8.2 behavior.
  • [P2] Align hardlink handling across lookup forms. The same default reader rejects files with multiple hardlinks. The existing walker enumerates these as ordinary files and the existing reader accepts them. An existing hardlinked page now fails only through the new exact-path branch. Keep this performance change compatible, or make a deliberate, documented owner-level policy change across all page-reading paths with regression coverage.

I directly inspected the pinned dependency's root defaults and read implementation, and reproduced both differences with synthetic files using the published 0.5.6 package:

sources/large.md: fs.readFile succeeds (16,777,224 bytes); root.readText throws too-large
sources/linked.md: fs.readFile succeeds (9 bytes); root.readText throws hardlink

The existing bounded walker includes both fixtures as files. This is dependency-level reproduction plus source tracing through the tool, CLI, Gateway and corpus-supplement callers; it is not an end-to-end PR run. The isolated PR test attempt stopped before dependency installation/tests because the branch's package-manager pin differs from trusted current main.

Best-fix verdict: correct owner, incomplete contract alignment. Preserve a common page-reading contract across exact, claim and fuzzy lookups while retaining rooted file-descriptor validation. A new persistent cache or caller-specific bypass is unnecessary. Add coverage for the two lookup-form equivalence cases above. The latest completed ClawSweeper review's boundary-policy decision and hardlink-coverage request remain relevant.

LOC: production +55/-5 (net +50), tests +67/-1 (net +66). Consolidating page-read ownership would also reduce the duplicated reader flow. No storage-schema change is required for this repair.

@steipete steipete self-assigned this Sep 5, 2026
Read canonical pages through the shared rooted reader while preserving compiled
claim precedence, large pages, hardlinks, visibility and missing-path fallbacks.
Skip deleted compiled candidates without suppressing filesystem boundary errors.

Reuse reconciled cache owners during ordinary initialization and activate local
source sync before checking dashboard readiness. Retain cold and explicit
lifecycle source validation, vault replacement fencing and publication checks.

Cover reader contracts, stale candidates, lifecycle reuse and rollback with real
filesystem and SQLite regressions. Document cold CLI activation costs.

Fixes openclaw#116048. Related openclaw#116374; thanks @sloptop-the-terrible for the original
reproduction and direct-read direction.

Co-authored-by: Brian Snyder <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M and removed size: S labels Sep 5, 2026
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

The earlier size/hardlink findings are resolved in f268ee0. The shared reader preserves both contracts, retains compiled-claim precedence, handles deleted compiled candidates, and rejects filesystem boundary races. Real CLI/Gateway proof also exposed and repaired repeated lifecycle validation and unnecessary cold local recompilation; the PR body now documents the remaining cold activation cost and full evidence.

All 510 Memory Wiki tests, changed-file checks, full build, independent source review and final autoreview passed. The prior rank-up requests are addressed in the PR body. Requesting a fresh review because this includes lifecycle behavior beyond the earlier review.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete steipete changed the title fix(memory-wiki): avoid vault scans for exact page reads fix(memory-wiki): avoid repeated vault work for exact page reads Sep 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 5, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 5, 2026
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Maintainer resolution of the two evidence checks in the newly published review for f268ee0:

  1. Dependency-source access: I directly inspected the installed fs-safe 0.8.1 implementation during the repair and have now independently fetched its tagged upstream source as well. The root contract, byte-budget normalization, and opened-file reader confirm the explicit large-file/hardlink policy used here. Real tests cover files above 16 MiB and hardlinks across exact/basename/ID lookups, plus terminal boundary refusals in all three race routes. The review worker's network limitation is covered by this source inspection and the recorded runtime proof.

  2. Data-model heuristic: There is no stored-format change. The entire compiled-cache production diff is an eight-line predicate over the existing process-local owner; schema versions, snapshot types, serialization, metadata and store read/write/reconciliation remain unchanged. Query reads retain the existing Markdown parser, and local source sync calls the existing initializer. Existing SQLite restart/reopen, rollback and stale-publication tests pass. The real cold CLI read reused its existing database publication without changing the publication log. No migration is needed.

The fresh report has no code findings, no required product decision and no rank-up requests. Both rendered evidence checks are addressed; the tested head is unchanged.

Named follow-up: cold bridge/unsafe-local activation. The existing imported-source writer deliberately skips preparation for unchanged imports (source-page-shared.ts); a separate focused check should assess unnecessary compilation when those modes start with an inactive owner while preserving that lazy-write boundary. This PR's cold-start initialization repair covers local mode, and its warm-owner reuse applies across modes.

@steipete
steipete merged commit 47b8889 into openclaw:main Sep 5, 2026
193 of 194 checks passed
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
Co-authored-by: BSnizND <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Brian Snyder <[email protected]>
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-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: M 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]: wiki.get scans the vault for an exact canonical page path

2 participants