Skip to content

Commit c3f9bea

Browse files
committed
fix(memory-wiki): filter self-referential artifacts from bridge import 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 #95657
1 parent a594d2c commit c3f9bea

2 files changed

Lines changed: 70 additions & 2 deletions

File tree

‎extensions/memory-wiki/src/bridge.test.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,66 @@ describe("syncMemoryWikiBridgeSources", () => {
551551
"# Deep Unicode Note",
552552
);
553553
});
554+
555+
it("filters out artifacts from the wiki vault sources directory to prevent self-import loops", async () => {
556+
const workspaceDir = await createBridgeWorkspace("self-import-workspace");
557+
const { rootDir: vaultDir, config } = await createVault({
558+
rootDir: nextCaseRoot("self-import-vault"),
559+
config: {
560+
vaultMode: "bridge",
561+
bridge: {
562+
enabled: true,
563+
readMemoryArtifacts: true,
564+
indexMemoryRoot: true,
565+
indexDailyNotes: true,
566+
},
567+
},
568+
});
569+
570+
// Simulate: the vault lives inside the workspace memory directory
571+
// and the memory indexer has picked up a bridge-generated source file
572+
const externalMemoryPath = path.join(workspaceDir, "memory", "2026-04-05.md");
573+
await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true });
574+
await fs.writeFile(externalMemoryPath, "# Daily Note\n", "utf8");
575+
576+
// This artifact simulates a bridge-generated file that the memory indexer
577+
// found inside the wiki vault's own sources directory — it should be filtered
578+
const selfReferentialPath = path.join(vaultDir, "sources", "bridge-workspace-abc123.md");
579+
await fs.mkdir(path.join(vaultDir, "sources"), { recursive: true });
580+
await fs.writeFile(selfReferentialPath, "# Bridge Import\n", "utf8");
581+
582+
registerBridgeArtifacts([
583+
{
584+
kind: "daily-note",
585+
workspaceDir,
586+
relativePath: "memory/2026-04-05.md",
587+
absolutePath: externalMemoryPath,
588+
agentIds: ["main"],
589+
contentType: "markdown",
590+
},
591+
{
592+
kind: "daily-note",
593+
workspaceDir,
594+
relativePath: "sources/bridge-workspace-abc123.md",
595+
absolutePath: selfReferentialPath,
596+
agentIds: ["main"],
597+
contentType: "markdown",
598+
},
599+
]);
600+
601+
const appConfig: OpenClawConfig = {
602+
agents: {
603+
list: [{ id: "main", default: true, workspace: workspaceDir }],
604+
},
605+
};
606+
607+
const result = await syncMemoryWikiBridgeSources({ config, appConfig });
608+
609+
// Only the external artifact should be imported; the self-referential one
610+
// from the vault's own sources/ directory must be filtered out.
611+
expect(result.artifactCount).toBe(1);
612+
expect(result.importedCount).toBe(1);
613+
expect(result.pagePaths).toHaveLength(1);
614+
expect(result.pagePaths[0]).not.toContain("bridge-workspace-abc123");
615+
});
554616
});

‎extensions/memory-wiki/src/bridge.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,23 @@ export async function syncMemoryWikiBridgeSources(params: {
225225
}
226226

227227
const publicArtifacts = await listActiveMemoryPublicArtifacts({ cfg: params.appConfig });
228+
// Filter out artifacts from the wiki vault's own sources directory to prevent
229+
// recursive self-import loops when the vault lives inside memory/. See #95657.
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),
233+
);
228234
const results: Array<{ pagePath: string; changed: boolean; created: boolean }> = [];
229235
const activeKeys = new Set<string>();
230-
const artifacts = await collectBridgeArtifacts(params.config.bridge, publicArtifacts);
236+
const artifacts = await collectBridgeArtifacts(params.config.bridge, filteredArtifacts);
231237
const state = await readMemoryWikiSourceSyncState(params.config.vault.path);
232238
assertMemoryWikiSourceSyncStateCapacity({
233239
state,
234240
group: "bridge",
235241
incomingCount: artifacts.length,
236242
});
237243
const agentIdsByWorkspace = new Map<string, string[]>();
238-
for (const artifact of publicArtifacts) {
244+
for (const artifact of filteredArtifacts) {
239245
agentIdsByWorkspace.set(artifact.workspaceDir, artifact.agentIds);
240246
}
241247
const artifactCount = artifacts.length;

0 commit comments

Comments
 (0)