From 27c649f5c1316062ea369a2d55710cfe2aa80d8d Mon Sep 17 00:00:00 2001 From: 4byounth <1187256439@qq.com> Date: Sun, 29 Mar 2026 00:16:42 +0800 Subject: [PATCH] fix: correct context_type classification for memories during reindex When reindexing via `/api/v1/content/reindex`, all memories under `viking://user/*/memories/*` and `viking://agent/*/memories/*` were incorrectly classified as `context_type="resource"` instead of `"memory"`. This caused downstream consumers (e.g. OpenClaw auto-recall) that filter by `context_type=="memory"` to miss all reindexed memories. Two root causes: 1. `summarizer.py` checked `uri.startswith("viking://memory/")` which never matches real memory URIs (actual paths use `/memories/` as a path segment, not a top-level scheme). Fixed by using substring match `"/memories" in uri`, consistent with `core/directories.get_context_type_for_uri()`. 2. `semantic_dag.py` propagated the root URI's `context_type` to all child nodes during recursive traversal. When reindexing from `viking://`, the root has no `/memories/` segment, so all children inherited `"resource"`. Fixed by calling `get_context_type_for_uri()` per node. Normal memory creation via auto-capture is unaffected (it uses `memory_updater.py` which hardcodes `"memory"`), so this bug only manifests during reindex operations. Closes #1060 --- openviking/storage/queuefs/semantic_dag.py | 5 +++-- openviking/utils/summarizer.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/openviking/storage/queuefs/semantic_dag.py b/openviking/storage/queuefs/semantic_dag.py index 55cacc691..db8137b8d 100644 --- a/openviking/storage/queuefs/semantic_dag.py +++ b/openviking/storage/queuefs/semantic_dag.py @@ -6,6 +6,7 @@ from dataclasses import dataclass, field from typing import Awaitable, Callable, Dict, List, Optional +from openviking.core.directories import get_context_type_for_uri from openviking.server.identity import RequestContext from openviking.storage.viking_fs import get_viking_fs from openviking_cli.utils import VikingURI @@ -440,7 +441,7 @@ async def _file_summary_task(self, parent_uri: str, file_path: str) -> None: task = VectorizeTask( task_type="file", uri=file_path, - context_type=self._context_type, + context_type=get_context_type_for_uri(file_path), ctx=self._ctx, semantic_msg_id=self._semantic_msg_id, file_path=file_path, @@ -560,7 +561,7 @@ async def _overview_task(self, dir_uri: str) -> None: task = VectorizeTask( task_type="directory", uri=dir_uri, - context_type=self._context_type, + context_type=get_context_type_for_uri(dir_uri), ctx=self._ctx, semantic_msg_id=self._semantic_msg_id, abstract=abstract, diff --git a/openviking/utils/summarizer.py b/openviking/utils/summarizer.py index dff099e62..6f3c2dcd4 100644 --- a/openviking/utils/summarizer.py +++ b/openviking/utils/summarizer.py @@ -57,10 +57,11 @@ async def summarize( telemetry = get_current_telemetry() for uri, temp_uri in zip(resource_uris, temp_uris): # Determine context_type based on URI + # Use the same logic as core/directories.get_context_type_for_uri() context_type = "resource" - if uri.startswith("viking://memory/"): + if "/memories" in uri: context_type = "memory" - elif uri.startswith("viking://agent/skills/"): + elif "/skills" in uri: context_type = "skill" msg = SemanticMsg(