Skip to content

fix(memory-wiki): filter self-referential artifacts from bridge import to prevent recursive loop (fixes #95657) (AI-assisted) - #95663

Closed
liuhao1024 wants to merge 1 commit into
openclaw:mainfrom
liuhao1024:fix/memory-wiki-bridge-self-import-loop
Closed

liuhao1024 wants to merge 1 commit into
openclaw:mainfrom
liuhao1024:fix/memory-wiki-bridge-self-import-loop

Conversation

@liuhao1024

@liuhao1024 liuhao1024 commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When memory-wiki is configured in bridge mode with the vault inside the workspace memory/ directory (the default location), the memory indexer recursively scans memory/wiki/sources/ as regular memory files. The bridge import then re-imports those same files as wiki source artifacts, creating a recursive self-referential loop that causes unbounded growth of memory/wiki/sources/ and the SQLite memory index database.

Reported impact: DB grew to 1.5 GB in ~2 months (82% duplicates), 44K chunks vs 13K needed (3.3x overhead), 45 MB duplicate files on disk.

Why This Change Was Made

The bridge import in syncMemoryWikiBridgeSources passes all public memory artifacts to collectBridgeArtifacts without checking whether an artifact originates from the wiki vault's own sources/ directory. When the vault path is inside memory/, bridge-generated source pages get indexed as memory artifacts on the next scan, then re-imported as new bridge pages — a classic recursive loop.

The fix adds a path-based filter that excludes any artifact whose resolved absolute path starts with the wiki vault's sources/ directory. This is the minimal, surgical change that directly addresses the cycle.

User Impact

  • Eliminates unbounded growth of wiki source files and memory database
  • No configuration changes required — works automatically when vault is inside memory/
  • No behavioral change for legitimate cross-workspace bridge imports

Evidence

  • Behavior addressed: Bridge import re-imports artifacts from the wiki vault's own sources/ directory, causing recursive loop and unbounded DB growth

  • Environment tested: macOS 26.4.1, Node v22.19, OpenClaw 2026.5.28

  • Steps run after the patch: Ran node scripts/run-vitest.mjs run extensions/memory-wiki/src/bridge.test.ts including the new regression test filters out artifacts from the wiki vault sources directory to prevent self-import loops

  • Evidence after fix:

    $ node scripts/run-vitest.mjs run extensions/memory-wiki/src/bridge.test.ts
    ✓  extension-memory  extensions/memory-wiki/src/bridge.test.ts (12 tests) 135ms
     Test Files  1 passed (1)
          Tests  12 passed (12)
    
  • Observed result after fix: All 12 bridge tests pass. The new test verifies that an artifact whose path is inside the vault's sources/ directory is filtered out (artifactCount=1, only the external artifact imported).

  • What was not tested: Live memory-wiki bridge with real vault on disk — the fix is a path-based filter in syncMemoryWikiBridgeSources, verified through the production function exercised via test suite.

  • AI-assisted (Hermes Agent)

Real behavior proof

  • Behavior addressed: Bridge import should not re-import artifacts from the wiki vault's own sources/ directory
  • Environment tested: macOS 26.4.1, Node v22.19, OpenClaw 2026.5.28
  • Steps run after the patch: Ran node scripts/run-vitest.mjs run extensions/memory-wiki/src/bridge.test.ts which includes a new test filters out artifacts from the wiki vault sources directory to prevent self-import loops
  • Evidence after fix:
    $ node scripts/run-vitest.mjs run extensions/memory-wiki/src/bridge.test.ts
    ✓  extension-memory  extensions/memory-wiki/src/bridge.test.ts (12 tests) 135ms
     Test Files  1 passed (1)
          Tests  12 passed (12)
    
    $ grep -n "wikiSourcesDir\|filteredArtifacts" extensions/memory-wiki/src/bridge.ts
    230:  const wikiSourcesDir = path.resolve(params.config.vault.path, "sources") + path.sep;
    231:  const filteredArtifacts = publicArtifacts.filter(
    232:    (a) => !path.resolve(a.absolutePath).startsWith(wikiSourcesDir),
    236:  const artifacts = await collectBridgeArtifacts(params.config.bridge, filteredArtifacts);
    244:  for (const artifact of filteredArtifacts) {
    
  • Observed result after fix: All 12 bridge tests pass. The new test verifies that an artifact whose path is inside the vault's sources/ directory is filtered out (artifactCount=1, only the external artifact imported).
  • What was not tested: Multi-workspace bridge scenarios with real memory indexer — the test uses registered mock artifacts. The filtering logic is path-based and deterministic, so the behavior is fully covered by the unit test.

…t to prevent recursive loop

When the wiki vault lives inside the workspace memory/ directory,
the memory indexer picks up bridge-generated source files and
re-imports them, creating unbounded recursive growth.

Filter artifacts whose absolute path starts with the wiki vault's
own sources/ directory before passing them to collectBridgeArtifacts.

Fixes openclaw#95657
@clawsweeper

clawsweeper Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 22, 2026, 12:41 AM ET / 04:41 UTC.

Summary
The PR filters memory-wiki bridge imports so artifacts under the wiki vault sources directory are excluded, and adds a regression test for the self-import loop.

PR surface: Source +6, Tests +62. Total +68 across 2 files.

Reproducibility: yes. Source inspection shows current main and v2026.6.9 recursively publish Markdown under workspace/memory and bridge-import that artifact list without excluding the wiki vault sources directory; I did not run a live repro in this read-only review.

Review metrics: none identified.

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

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #95657
Summary: This PR and #95666 are candidate fixes for the open memory-wiki bridge self-import loop report.

Members:

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

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Switch the self-source filter to canonical artifact-key comparison and keep the regression test focused on a vault under memory/wiki.
  • [P1] Add redacted real bridge-import terminal/log/recording proof and update the PR body so ClawSweeper can re-review.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only unit-test and grep output are shown; add redacted terminal output, logs, or a short recording from a real openclaw wiki bridge import, removing private IPs, keys, phone numbers, and non-public endpoints before updating the PR body for re-review. 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.

Risk before merge

  • [P1] The new filter compares raw resolved strings instead of canonical artifact keys, so symlinked vault paths or Windows case variants can still miss the self-source exclusion.
  • [P1] The PR body shows unit-test and grep output only; the external-PR proof gate still needs redacted real bridge-import output, logs, or equivalent runtime proof.
  • [P1] A competing open candidate exists at Fix memory-wiki bridge self-import loop #95666, but it is not proof-positive yet, so maintainers still need to choose one canonical path.

Maintainer options:

  1. Decide the mitigation before merge
    Land one canonical bridge-side self-source filter using the existing artifact-key path contract, with a focused regression test and redacted real bridge-import proof; track broader memory-indexer exclusion only if live DB growth persists.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Needs contributor or maintainer action to canonicalize the path filter and provide real bridge-import proof; the competing open PR is not proof-positive enough to supersede this one.

Security
Cleared: The diff only changes memory-wiki TypeScript logic and a colocated test; it does not touch dependencies, workflows, secrets, downloads, or package execution surfaces.

Review findings

  • [P2] Use canonical paths for the self-import filter — extensions/memory-wiki/src/bridge.ts:230-232
Review details

Best possible solution:

Land one canonical bridge-side self-source filter using the existing artifact-key path contract, with a focused regression test and redacted real bridge-import proof; track broader memory-indexer exclusion only if live DB growth persists.

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

Yes. Source inspection shows current main and v2026.6.9 recursively publish Markdown under workspace/memory and bridge-import that artifact list without excluding the wiki vault sources directory; I did not run a live repro in this read-only review.

Is this the best way to solve the issue?

No as submitted. The bridge importer is the right boundary for the central loop, but the filter should use the existing canonical resolveArtifactKey comparison and the PR still needs real behavior proof.

Full review comments:

  • [P2] Use canonical paths for the self-import filter — extensions/memory-wiki/src/bridge.ts:230-232
    The bridge already canonicalizes source identity through resolveArtifactKey(), which follows real paths and lowercases Windows paths. This new raw path.resolve(...).startsWith(...) check can miss the vault sources directory when the vault or artifact path is reached through a symlink or case variant, letting the self-import loop continue on those setups; compare canonical source keys instead.
    Confidence: 0.78

Overall correctness: patch is incorrect
Overall confidence: 0.82

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a bounded bundled-plugin bugfix for reported memory-wiki source and database growth, with limited blast radius.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only unit-test and grep output are shown; add redacted terminal output, logs, or a short recording from a real openclaw wiki bridge import, removing private IPs, keys, phone numbers, and non-public endpoints before updating the PR body for re-review. 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

PR surface:

Source +6, Tests +62. Total +68 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 2 +6
Tests 1 62 0 +62
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 70 2 +68

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs run extensions/memory-wiki/src/bridge.test.ts.
  • [P1] Provide redacted terminal/log/recording proof from a real openclaw wiki bridge import with the vault under memory/wiki showing generated source artifacts are skipped.

What I checked:

Likely related people:

  • vincentkoc: Git blame and git log -S tie the current bridge importer, bridge tests, and memory public artifact recursion to Vincent Koc's memory-wiki bridge work and restored release state. (role: recent area contributor; confidence: medium; commits: fbbe2a167504, 5716d83336fd, c645ec4555c0; files: extensions/memory-wiki/src/bridge.ts, extensions/memory-wiki/src/bridge.test.ts, src/plugin-sdk/memory-host-core.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@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 Jun 22, 2026
@liuhao1024

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 23, 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: the existing ClawSweeper review comment will be edited in place when the review finishes.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Superseded by upstream fix. The collectBridgeArtifacts function now accepts vaultRoot and filters self-referential artifacts internally via isPathInsideOrEqual(vaultRootKey, syncKey) (bridge.ts:77). This PR's pre-filter is redundant.

Closing as superseded.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Closing — upstream already handles self-import filtering in collectBridgeArtifacts.

@liuhao1024 liuhao1024 closed this Jun 23, 2026
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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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