Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(reindex): stop embedding not-ready directory placeholders as L0/L1 vectors (#2434) (#2496)

Evo1e731c7659c9
diff --git a/openviking/service/reindex_executor.py b/openviking/service/reindex_executor.py
index 4a1988d05..bbaf70ea0 100644
--- a/openviking/service/reindex_executor.py
+++ b/openviking/service/reindex_executor.py
@@ -48,6 +48,30 @@ logger = get_logger(__name__)
REINDEX_TASK_TYPE = "admin_reindex"
+
+# Trailing markers VikingFS appends when a directory has no generated .abstract.md/.overview.md
+# (see openviking/storage/viking_fs.py). The rendered value is a placeholder, not semantic
+# content, and must never be embedded as an ABSTRACT (L0) / OVERVIEW (L1) vector (issue #2434).
+_ABSTRACT_NOT_READY_SUFFIX = "[Directory abstract is not ready]"
+_OVERVIEW_NOT_READY_SUFFIX = "[Directory overview is not ready]"
+
+
+def _is_not_ready_sentinel(text: str, suffix: str) -> bool:
+ """Return True if *text* is a VikingFS not-ready directory placeholder.
+
+ VikingFS renders these as a single ``# <uri>`` header followed only by the not-ready marker.
+ Match that exact shape (a ``#`` header with no substantive body before the trailing marker)
+ so the check is uri-agnostic yet never drops real directory content that merely ends with,
+ or mentions, the user-facing marker phrase.
+ """
+ if not text:
+ return False
+ head = text.rstrip()
+ if not head.endswith(suffix):
+ return False
+ head = head[: -len(suffix)].strip()
+ return head.startswith("#") and "\n" not in head
+
_reindex_executor: "ReindexExecutor | None" = None
@@ -1150,15 +1174,17 @@ class ReindexExecutor:
async def _read_directory_abstract(self, uri: str, *, ctx: RequestContext) -> str:
try:
- return await get_viking_fs().abstract(uri, ctx=ctx)
+ value = await get_viking_fs().abstract(uri, ctx=ctx)
except Exception:
return ""
+ return "" if _is_not_ready_sentinel(value, _ABSTRACT_NOT_READY_SUFFIX) else value
async def _read_directory_overview(self, uri: str, *, ctx: RequestContext) -> str:
try:
- return await get_viking_fs().overview(uri, ctx=ctx)
+ value = await get_viking_fs().overview(uri, ctx=ctx)
except Exception:
return ""
+ return "" if _is_not_ready_sentinel(value, _OVERVIEW_NOT_READY_SUFFIX) else value
async def _best_file_summary(self, uri: str, *, ctx: RequestContext) -> str:
parent_uri = VikingURI(uri).parent.uri
diff --git a/tests/service/test_reindex_placeholder.py b/tests/service/test_reindex_placeholder.py
new file mode 100644
index 000000000..260ee8eea
--- /dev/null
+++ b/tests/service/test_reindex_placeholder.py
@@ -0,0 +1,49 @@
+"""Regression tests for directory-meta placeholder filtering in reindex (issue #2434).
+
+VikingFS.abstract()/overview() render a ``# <uri>`` header followed only by a
+``[Directory ... is not ready]`` marker for directories without a generated
+``.abstract.md``/``.overview.md``. Before this fix the reindex executor embedded those
+placeholders as real ABSTRACT (L0) / OVERVIEW (L1) vectors, so they surfaced in
+search/memory-prefetch and displaced genuine memories. Detection is uri-agnostic and
+shape-anchored so legitimate directory content is never dropped.
+"""
+
+from openviking.service.reindex_executor import (
+ _ABSTRACT_NOT_READY_SUFFIX,
+ _OVERVIEW_NOT_READY_SUFFIX,
+ _is_not_ready_sentinel,
+)
+
+
+def test_real_abstract_sentinel_is_detected():
+ rendered = "# viking://memory/projects/foo [Directory abstract is not ready]"
+ assert _is_not_ready_sentinel(rendered, _ABSTRACT_NOT_READY_SUFFIX)
+
+
+def test_real_overview_sentinel_is_detected():
+ rendered = "# viking://memory/projects/foo\n\n[Directory overview is not ready]"
+ assert _is_not_ready_sentinel(rendered, _OVERVIEW_NOT_READY_SUFFIX)
+
+
+def test_sentinel_detection_is_uri_agnostic():
+ for uri in ("viking://a/b/", "viking://x%20y/z", "viking://"):
+ assert _is_not_ready_sentinel(f"# {uri} [Directory abstract is not ready]", _ABSTRACT_NOT_READY_SUFFIX)
+
+
+def test_content_mentioning_phrase_mid_body_is_preserved():
+ real = "# Notes\n\nWe used to show '[Directory abstract is not ready]' here, but now it has content."
+ assert not _is_not_ready_sentinel(real, _ABSTRACT_NOT_READY_SUFFIX)
+
+
+def test_authored_content_ending_with_marker_is_preserved():
+ # multi-line authored body that ends with the exact user-facing marker must survive
+ real = "# Project notes\n\nCurrent CLI output: [Directory abstract is not ready]"
+ assert not _is_not_ready_sentinel(real, _ABSTRACT_NOT_READY_SUFFIX)
+
+
+def test_real_content_preserved():
+ assert not _is_not_ready_sentinel("# Project\n\nReal abstract body.", _ABSTRACT_NOT_READY_SUFFIX)
+
+
+def test_empty_is_not_a_sentinel():
+ assert not _is_not_ready_sentinel("", _ABSTRACT_NOT_READY_SUFFIX)