Skip to content

Commit 3d9a32f

Browse files
committed
fix(memory): skip memory-wiki vault subtree in workspace memory scan (#95657)
A bridge-mode wiki vault placed inside workspace memory/ (the default layout) had its bridge-generated sources/ pages picked up by the recursive memory scan. Both consumers of that scan -- the lancedb embedding indexer and the wiki bridge import -- then re-ingested the wiki's own output, an unbounded self-import loop that bloated the SQLite index. Detect a vault by its .openclaw-wiki marker and skip the whole subtree during the scan, breaking the cycle at its source.
1 parent a594d2c commit 3d9a32f

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎src/plugin-sdk/memory-host-core.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,35 @@ describe("memory-host-core helpers", () => {
139139
}
140140
});
141141

142+
it("skips a memory-wiki vault nested under memory/ to avoid the bridge self-import loop (#95657)", async () => {
143+
const fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-host-wiki-skip-"));
144+
try {
145+
const workspaceDir = path.join(fixtureRoot, "workspace");
146+
const wikiSources = path.join(workspaceDir, "memory", "wiki", "sources");
147+
const wikiMarker = path.join(workspaceDir, "memory", "wiki", ".openclaw-wiki");
148+
await fs.mkdir(wikiSources, { recursive: true });
149+
await fs.mkdir(wikiMarker, { recursive: true });
150+
await fs.writeFile(path.join(workspaceDir, "memory", "real-note.md"), "# Note\n", "utf8");
151+
// Bridge-generated source pages that must NOT be re-indexed as memory.
152+
await fs.writeFile(
153+
path.join(wikiSources, "bridge-workspace-abc-memory-real-note.md"),
154+
"# Imported\n",
155+
"utf8",
156+
);
157+
158+
const artifacts = await listMemoryHostPublicArtifacts({
159+
cfg: { agents: { list: [{ id: "main", default: true, workspace: workspaceDir }] } },
160+
});
161+
const relativePaths = artifacts.map((artifact) => artifact.relativePath);
162+
expect(relativePaths).toContain("memory/real-note.md");
163+
expect(relativePaths.some((relativePath) => relativePath.includes("wiki/sources"))).toBe(
164+
false,
165+
);
166+
} finally {
167+
await fs.rm(fixtureRoot, { recursive: true, force: true });
168+
}
169+
});
170+
142171
it("keeps the deprecated memory-core alias wired to memory-host-core", () => {
143172
expect(memoryCoreAlias.buildActiveMemoryPromptSection).toBe(buildActiveMemoryPromptSection);
144173
expect(memoryCoreAlias.listActiveMemoryPublicArtifacts).toBe(listActiveMemoryPublicArtifacts);

‎src/plugin-sdk/memory-host-core.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ async function pathExists(filePath: string): Promise<boolean> {
1919
}
2020
}
2121

22+
// A memory-wiki vault marks its root with a `.openclaw-wiki` directory. When a
23+
// vault lives inside `memory/` (the default bridge layout), its `sources/`
24+
// pages are bridge-generated artifacts, not user memory. Indexing them as
25+
// memory would feed the wiki bridge import its own output, an unbounded
26+
// self-import loop (#95657). Skip any vault subtree during the memory scan.
27+
const WIKI_VAULT_MARKER = ".openclaw-wiki";
28+
2229
async function listMarkdownFilesRecursive(rootDir: string): Promise<string[]> {
2330
const entries = await fs.readdir(rootDir, { withFileTypes: true }).catch(() => []);
31+
if (entries.some((entry) => entry.isDirectory() && entry.name === WIKI_VAULT_MARKER)) {
32+
return [];
33+
}
2434
const files: string[] = [];
2535
for (const entry of entries) {
2636
const fullPath = path.join(rootDir, entry.name);

0 commit comments

Comments
 (0)