Skip to content

fix(memory-wiki): read exact canonical wiki pages without scanning the vault - #116374

Closed
sloptop-the-terrible wants to merge 3 commits into
openclaw:mainfrom
sloptop-the-terrible:fix/wiki-get-direct-read
Closed

sloptop-the-terrible wants to merge 3 commits into
openclaw:mainfrom
sloptop-the-terrible:fix/wiki-get-direct-read

Conversation

@sloptop-the-terrible

@sloptop-the-terrible sloptop-the-terrible commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

wiki.get resolved exact canonical page paths by enumerating and parsing the whole Memory
Wiki vault. Because that scan uses pMap(..., { stopOnError: true }), one unrelated
unreadable page could reject a read whose target was valid and readable.

Why This Change Was Made

Exact queryable paths now take a bounded direct-read path before the existing digest and
full-scan fallbacks:

  • the lookup must be vault-relative, Markdown, below one of the five queryable directories,
    free of empty/traversal segments, and not an index.md;
  • the vault and page realpaths must equal the exact canonical path, rejecting file and
    intermediate-directory symlinks just as the scanner's symlinkPolicy: "skip" does;
  • the same Markdown summary parser, lookup resolver, and visibility filter must accept the
    page before it is returned.

Missing, malformed, fuzzy, claim-id, non-visible, reserved, or noncanonical lookups retain
the existing digest-then-scan behavior.

User Impact

An operator reading sources/example.md gets one bounded page read instead of a whole-vault
scan. The read succeeds even if an unrelated page is temporarily unreadable. Fuzzy/title
lookups and visibility behavior are unchanged, and direct reads cannot follow a path the
scanner would skip.

Evidence

Focused current-head suite:

node scripts/run-vitest.mjs extensions/memory-wiki/src/query.test.ts

Test Files  1 passed (1)
Tests       51 passed (51)

The suite proves that an exact path does not enumerate an unrelated failing page and that
a directory symlink to a valid page outside the vault returns null.

A no-mock real-vault transcript also ran the public query entry point as an unprivileged
effective user. The requested page was readable, an unrelated Markdown page was root-only
and deterministically returned EACCES if scanned, and a queryable-directory symlink pointed
to a valid page outside the vault.

Before the patch on current main:

{
  "exactLookup": {
    "status": "error",
    "code": "EACCES"
  },
  "externalSymlinkLookup": null
}

At this PR's current head:

{
  "exactLookup": {
    "status": "returned",
    "path": "sources/alpha.md",
    "containsExpected": true
  },
  "externalSymlinkLookup": null
}

This reproduces the availability failure before the patch, proves the exact read after the
patch, and independently confirms that the fast path does not cross the scanner's symlink
boundary.

Fixes #116048

@sloptop-the-terrible
sloptop-the-terrible marked this pull request as ready for review July 30, 2026 10:58
@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. P2 Normal backlog priority with limited blast radius. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed August 17, 2026, 12:24 PM ET / 16:24 UTC.

ClawSweeper review

What this changes

This PR adds a direct read path for exact, canonical Memory Wiki page lookups and tests that it avoids unrelated vault reads and static directory symlinks.

Merge readiness

⛔ Blocked before merge - 10 items remain

Keep open: current main still lacks the exact-path fast path, but this PR retains the prior P1 security finding because its raw read can race with the preceding symlink check.

Priority: P1
Reviewed head: 32d85c9786b48a878b5c2f06e77fa9c4703999e7

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The availability fix is well evidenced, but the unresolved root-boundary race prevents merge readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body includes a no-mock real-vault before/after transcript for the availability fix and static external-symlink rejection; the remaining blocker is the untested replacement race.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes a no-mock real-vault before/after transcript for the availability fix and static external-symlink rejection; the remaining blocker is the untested replacement race.
Evidence reviewed 5 items Current-main baseline: Current main enumerates queryable Markdown files and reads them with p-map configured to stop on the first error; it has no exact canonical-page direct-read helper.
Introduced race: The branch validates real paths, then performs an independent raw filesystem read; a replacement after the validation can make that read follow a new symlink target.
Existing safe-root contract: The public plugin security facade exposes the root capability, while the adjacent vault-write owner documents its opened-file identity check and path-mismatch handling for replacement races.
Findings 1 actionable finding [P1] Read the canonical page through the root-bounded reader
Security Needs attention Direct read races the symlink validation: The raw file read is not bound to the earlier realpath result, so a page or ancestor replacement can make the tool return external file content.

How this fits together

Memory Wiki serves page content to agent tools from a local vault. A lookup is validated, resolved against visibility rules, then returned as page content or falls back to digest and vault scanning.

flowchart LR
A[Wiki page lookup] --> B[Memory Wiki query]
B --> C{Canonical vault path?}
C -->|Yes| D[Direct page reader]
C -->|No| E[Digest or vault scan]
D --> F[Visibility and lookup match]
E --> F
F --> G[Page content to agent]
Loading

Before merge

  • Read the canonical page through the root-bounded reader (P1) - The realpath checks at lines 1262–1266 finish before this independent readFile. A concurrent writer can replace the file or a parent directory with an external symlink in that gap, causing wiki.get to ingest content outside the vault. Use the existing root capability's readText(relativePath) path, which already guards opened-file identity, and add a swap-race regression.
  • Resolve security concern: Direct read races the symlink validation - The raw file read is not bound to the earlier realpath result, so a page or ancestor replacement can make the tool return external file content.
  • Resolve merge risk (P1) - The direct reader can return content outside the vault if a page or parent directory is replaced with a symlink after the realpath check and before the raw read.
  • Resolve merge risk (P1) - This bug-fix branch is net +61 production lines; retain only the validation unique to exact lookup and reuse the established root-bounded read primitive.
  • Resolve merge risk (P1) - GitHub reports the branch behind main, so it needs an exact-head rebase and focused rerun after the security repair.
  • Complete next step (P2) - A narrow, mechanical repair can preserve the fast path while routing the read through the existing vault-boundary owner.
  • Improve patch quality - Replace the raw read with the established root-bounded reader.
  • Improve patch quality - Add a controlled file or parent-directory replacement-race regression.
  • Improve patch quality - Rebase on current main and rerun the focused Memory Wiki suite.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P1] Read the canonical page through the root-bounded reader — extensions/memory-wiki/src/query.ts:1270
  • [high] Direct read races the symlink validation — extensions/memory-wiki/src/query.ts:1270
Agent review details

Security

Needs attention: The new direct filesystem read has a concrete time-of-check/time-of-use vault-escape risk.

PR surface

Source +61, Tests +67. Total +128 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 73 12 +61
Tests 1 67 0 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 140 12 +128

Review metrics

Metric Value Why it matters
Production vs test LOC production +61 net (73 added, 12 removed); tests +67 The new fast path is a bug fix with meaningful production growth, so its security boundary should reuse the existing rooted read owner.

Stored data model

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

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #116048
Summary: This PR is the explicit candidate fix for the open canonical Memory Wiki exact-path lookup bug.

Members:

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

Merge-risk options

Maintainer options:

  1. Use the root-bounded reader (recommended)
    Replace the raw direct read with the existing root capability and add a deterministic replacement-race regression before merge.
  2. Pause the fast path
    Do not merge the direct-read optimization until it preserves the vault's existing symlink and replacement boundary.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Replace the raw direct read with the existing root-bounded reader and add a controlled swap-race regression.

Technical review

Best possible solution:

Keep the exact-path optimization, but read through the existing root-bounded plugin API and prove a controlled file or parent-directory swap cannot escape the vault.

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

Yes. A vault with a readable target and an unrelated unreadable page reproduces the current-main failure; the PR also supplies a before/after real-vault transcript, though this read-only review did not rerun it.

Is this the best way to solve the issue?

No. Bypassing enumeration is the right repair, but a raw read after a separate realpath check is not the safest implementation; the existing root-bounded reader owns this invariant.

Full review comments:

  • [P1] Read the canonical page through the root-bounded reader — extensions/memory-wiki/src/query.ts:1270
    The realpath checks at lines 1262–1266 finish before this independent readFile. A concurrent writer can replace the file or a parent directory with an external symlink in that gap, causing wiki.get to ingest content outside the vault. Use the existing root capability's readText(relativePath) path, which already guards opened-file identity, and add a swap-race regression.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: An exact Memory Wiki read can fail today on an unrelated unreadable page, blocking a user-visible agent memory workflow.
  • merge-risk: 🚨 security-boundary: The new direct path separates symlink validation from file opening, allowing a replacement race to bypass the vault boundary.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes a no-mock real-vault before/after transcript for the availability fix and static external-symlink rejection; the remaining blocker is the untested replacement race.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a no-mock real-vault before/after transcript for the availability fix and static external-symlink rejection; the remaining blocker is the untested replacement race.

Evidence

Security concerns:

  • [high] Direct read races the symlink validation — extensions/memory-wiki/src/query.ts:1270
    The raw file read is not bound to the earlier realpath result, so a page or ancestor replacement can make the tool return external file content.
    Confidence: 0.97

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/memory-wiki/src/query.test.ts.
  • [P1] git diff --check.

What I checked:

  • Current-main baseline: Current main enumerates queryable Markdown files and reads them with p-map configured to stop on the first error; it has no exact canonical-page direct-read helper. (extensions/memory-wiki/src/query.ts:224, 49af98c12bb4)
  • Introduced race: The branch validates real paths, then performs an independent raw filesystem read; a replacement after the validation can make that read follow a new symlink target. (extensions/memory-wiki/src/query.ts:1270, 32d85c9786b4)
  • Existing safe-root contract: The public plugin security facade exposes the root capability, while the adjacent vault-write owner documents its opened-file identity check and path-mismatch handling for replacement races. (src/infra/fs-safe.ts:66, 32d85c9786b4)
  • Test coverage gap: The added tests prove static external-directory rejection and skipped unrelated reads, but neither swaps a checked page or parent directory after validation and before the read. (extensions/memory-wiki/src/query.test.ts:1591, 32d85c9786b4)
  • Area provenance: Recent main history includes the fs-safe adoption and Memory Wiki recall-boundary work by Peter Steinberger, making that history the strongest routing signal for the root-boundary repair. (extensions/memory-wiki/src/query.ts:1240, 0d7fb8eb392f)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Huvee: 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 (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-30T21:18:07.176Z sha 1ce0b2214b794526eba5c069ee99e32bc3bc480d :: needs maintainer review before merge. :: none
  • reviewed 2026-07-30T22:22:38.335Z sha 141e9df483701b65c35e4424fb327a5b881389ae :: needs maintainer review before merge. :: none
  • reviewed 2026-07-30T22:36:12.181Z sha 141e9df483701b65c35e4424fb327a5b881389ae :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T10:00:42.467Z sha 141e9df483701b65c35e4424fb327a5b881389ae :: needs changes before merge. :: [P1] Read the canonical page through the safe-root capability
  • reviewed 2026-08-02T16:15:40.286Z sha 141e9df483701b65c35e4424fb327a5b881389ae :: needs changes before merge. :: [P1] Read the canonical page through the safe-root capability
  • reviewed 2026-08-03T20:12:15.340Z sha 141e9df483701b65c35e4424fb327a5b881389ae :: needs changes before merge. :: [P1] Read the canonical page through the root-bounded capability
  • reviewed 2026-08-07T15:41:31.101Z sha 776f46972b308daf2e48fd37395eb828f1db6a47 :: needs changes before merge. :: [P1] Use a root-bounded reader for the direct page read
  • reviewed 2026-08-07T23:36:21.027Z sha 5c08bee5307ec83afef36397ed7ae9c4a79c8cfa :: needs changes before merge. :: [P1] Read the canonical page through the root-bounded reader

@sloptop-the-terrible

Copy link
Copy Markdown
Contributor Author

After-fix exact-head proof (6088f17e2e):

  • Added focused regression coverage that makes an unrelated vault page fail if read, resolves sources/alpha.md, and verifies the unrelated page is never touched.
  • node scripts/run-vitest.mjs extensions/memory-wiki/src/query.test.ts: 1 test file passed; 50/50 tests passed.
  • Focused verbose run: reads an exact canonical path without enumerating unrelated pages passed.
  • git diff --check and targeted oxfmt --check passed.
  • The branch is rebased on current origin/main.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@sloptop-the-terrible
sloptop-the-terrible force-pushed the fix/wiki-get-direct-read branch 2 times, most recently from 7822c59 to ac7b5b7 Compare July 30, 2026 20:29
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 30, 2026
@sloptop-the-terrible

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The current head adds an external-directory-symlink containment regression test, and the PR body now includes no-mock before/after proof from an unprivileged real-vault run: current main fails the exact read on an unrelated EACCES page, this branch returns the target, and the outside-vault symlink remains unreadable.

@clawsweeper

clawsweeper Bot commented Jul 30, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed 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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 30, 2026
@sloptop-the-terrible

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (4c331166c40c) — the P1 was the only outstanding item, and the exact-path/containment behavior was re-verified against the new base rather than assumed.

extensions/memory-wiki/src/query.test.ts — 51 passed on the refreshed base. Branch is 0 behind, cleanly mergeable.

No code changes in this refresh; the rebase applied without conflict.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Jul 30, 2026
@clawsweeper clawsweeper Bot removed the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 2, 2026
@sloptop-the-terrible

sloptop-the-terrible commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Curious what maintainers think here. Reading the exact canonical wiki page directly is a lot cleaner than scanning the whole vault for it.

@sloptop-the-terrible

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main to clear the conflict; no other changes.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 7, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 7, 2026
…e vault

wiki.get resolved every lookup by enumerating and parsing all queryable
vault dirs, so an exact page path paid whole-vault I/O and failed outright
when an unrelated page was unreadable (readQueryableWikiPagesByPaths runs
with stopOnError).

Canonical vault-relative Markdown paths now resolve with a single read after
validating the queryable dir, rejecting traversal, empty segments and
symlinked targets; digest and enumeration stay the fallback for claim ids,
titles and ambiguous basenames.

Fixes openclaw#116048
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 17, 2026
steipete added a commit to BsnizND/openclaw that referenced this pull request 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]>
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Superseded by merged #129897, commit 47b8889. Thank you for the original reproduction and direct-read direction; that credit is preserved in the landed PR.

The landed implementation uses the rooted opened-file reader across exact and scanned paths, preserves compiled-claim precedence and the existing large-file/hardlink contract, and also removes repeated warm lifecycle validation. It passed 510 Memory Wiki tests, hosted CI and real CLI/Gateway proof on a 5,001-page synthetic vault, including an unreadable-neighbor case. Cold snapshot validation remains intentional and documented.

Closing this overlapping candidate now that the verified replacement is on main.

@steipete steipete closed this Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-wiki merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

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