Skip to content

fix(memory-wiki): guard against missing agentIds #92207

Description

@qq230849622-a11y

Bug

All wiki_* tools throw artifact.agentIds is not iterable.

Root cause

listMemoryHostPublicArtifacts() may omit agentIds for some workspaces. Newer code spreads that value directly, crashing on undefined.

Affected code

dist/memory-state-CEaNZbtE.js: cloneMemoryPublicArtifact and .toSorted() comparator
dist/cli-DTDS4VQz.js: agentIdsByWorkspace map population

Fix

Guard artifact.agentIds before cloning and before sort comparators. Use artifact.agentIds ?? [] in bridge map.

Patch

diff --git a/dist/memory-state-CEaNZbtE.js b/dist/memory-state-CEaNZbtE.js
@@ -95,11 +95,14 @@ function getMemoryRuntime() {
 }
 function cloneMemoryPublicArtifact(artifact) {
-	const ids = artifact.agentIds;
+	const ids = artifact.agentIds;
 	return {
 		...artifact,
-		agentIds: [...ids]
+		agentIds: Array.isArray(ids) ? [...ids]
+			: (ids && typeof ids[Symbol.iterator] === "function" ? [...ids] : [])
 	};
 }
 async function listActiveMemoryPublicArtifacts(params) {
 	return (await memoryPluginState.capability?.capability.publicArtifacts?.listArtifacts(params) ?? []).map(cloneMemoryPublicArtifact).toSorted((left, right) => {
+		const workspaceOrder = (left.workspaceDir ?? '').localeCompare(right.workspaceDir ?? '');
+		if (workspaceOrder !== 0) return workspaceOrder;
 		const workspaceOrder = left.workspaceDir.localeCompare(right.workspaceDir);
 		if (workspaceOrder !== 0) return workspaceOrder;
@@ -114,11 +117,11 @@ async function listActiveMemoryPublicArtifacts(params) {
-		const contentTypeOrder = left.contentType.localeCompare(right.contentType);
+		const contentTypeOrder = (left.contentType ?? '').localeCompare(right.contentType ?? '');
 		if (contentTypeOrder !== 0) return contentTypeOrder;
-		const agentOrder = left.agentIds.join("\0").localeCompare(right.agentIds.join("\0"));
+		const agentOrder = (left.agentIds ?? []).join('\0').localeCompare((right.agentIds ?? []).join('\0'));
 		if (agentOrder !== 0) return agentOrder;
-		return left.absolutePath.localeCompare(right.absolutePath);
+		return (left.absolutePath ?? '').localeCompare(right.absolutePath ?? '');
 	});
 }
diff --git a/dist/cli-DTDS4VQz.js b/dist/cli-DTDS4VQz.js
@@ -3597,7 +3597,7 @@ function buildMemoryWikiBridgeSourceIndex(params) {
 	const agentIdsByWorkspace = /* @__PURE__ */ new Map();
-	for (const artifact of publicArtifacts) agentIdsByWorkspace.set(artifact.workspaceDir, artifact.agentIds);
+	for (const artifact of publicArtifacts) agentIdsByWorkspace.set(artifact.workspaceDir, artifact.agentIds ?? []);

Reproduction

Call any wiki_* tool on a workspace whose metadata does not provide agentIds.

Validation

After patching and restarting the gateway, wiki_search returns without throwing.

Reported by OpenClaw user qq230849622-a11y (2026-06-11).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions