Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(parse): stop silently dropping markdown YAML frontmatter (#3929)
Zayn Jarvisdcca29364c1a
diff --git a/openviking/parse/parsers/markdown.py b/openviking/parse/parsers/markdown.pyindex 2000f4ef3..4d267aa54 100644--- a/openviking/parse/parsers/markdown.py+++ b/openviking/parse/parsers/markdown.py@@ -177,12 +177,15 @@ class MarkdownParser(BaseParser):Initialize the enhanced markdown parser.Args:- extract_frontmatter: Whether to extract YAML frontmatter. When None, uses config.+ extract_frontmatter: Whether to REMOVE YAML frontmatter from the stored+ document body. Frontmatter is parsed into the parse result metadata+ either way. Defaults to False (lossless ingestion); when None, uses+ config.config: Parser configuration (uses default if None)"""self.config = config or ParserConfig()if extract_frontmatter is None:- extract_frontmatter = getattr(self.config, "extract_frontmatter", True)+ extract_frontmatter = getattr(self.config, "extract_frontmatter", False)self.extract_frontmatter = extract_frontmatter# Compile regex patterns for better performance@@ -369,11 +372,16 @@ class MarkdownParser(BaseParser):meta: Dict[str, Any] = {}warnings: List[str] = []- # Extract frontmatter if present+ # Frontmatter is ALWAYS parsed into ``meta`` (it drives doc_title below), but+ # it is only removed from the stored body when explicitly configured.+ # ``meta`` is transient — it is returned in the parse result and never written+ # to VikingFS — so stripping by default silently destroyed the frontmatter of+ # every ingested markdown file with no way to read those fields back.+ stripped_content, frontmatter = self._extract_frontmatter(content)+ if frontmatter:+ meta["frontmatter"] = frontmatterif self.extract_frontmatter:- content, frontmatter = self._extract_frontmatter(content)- if frontmatter:- meta["frontmatter"] = frontmatter+ content = stripped_contentexplicit_name = kwargs.get("resource_name")if not explicit_name and kwargs.get("source_name"):diff --git a/openviking_cli/utils/config/parser_config.py b/openviking_cli/utils/config/parser_config.pyindex e7dfe3e10..83fd271c2 100644--- a/openviking_cli/utils/config/parser_config.py+++ b/openviking_cli/utils/config/parser_config.py@@ -439,13 +439,16 @@ class MarkdownConfig(ParserConfig):Attributes:preserve_links: Whether to preserve hyperlinks in output- extract_frontmatter: Whether to extract YAML frontmatter+ extract_frontmatter: Whether to REMOVE YAML frontmatter from the stored+ document body. Frontmatter is parsed into the parse result metadata+ regardless. Off by default: the parsed metadata is never persisted, so+ removing the block would silently lose those fields.include_metadata: Whether to include file metadatamax_heading_depth: Maximum heading depth to include in structure"""preserve_links: bool = True- extract_frontmatter: bool = True+ extract_frontmatter: bool = Falseinclude_metadata: bool = Truemax_heading_depth: int = 3diff --git a/tests/parse/test_markdown_frontmatter.py b/tests/parse/test_markdown_frontmatter.pynew file mode 100644index 000000000..847d1ced6--- /dev/null+++ b/tests/parse/test_markdown_frontmatter.py@@ -0,0 +1,84 @@+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.+# SPDX-License-Identifier: AGPL-3.0+"""Tests for YAML frontmatter handling in MarkdownParser.++Frontmatter is parsed into ``ParseResult.meta`` but that metadata is never written+to VikingFS, so removing the block from the stored body loses the fields for good.+These tests pin the contract: parse always, remove only when explicitly configured.+"""++import pytest++from openviking.parse.parsers.markdown import MarkdownParser+from openviking_cli.utils.config.parser_config import MarkdownConfig, ParserConfig++FRONTMATTER = """---+id: stuck-pr-watch+name: PR watch+---+"""++BODY = """+# Guide++body text+"""++DOCUMENT = FRONTMATTER + BODY+++def _written(layout) -> list[str]:+ return [op.content for op in layout.ops if op.kind == "write"]+++async def test_frontmatter_is_kept_in_stored_body_by_default() -> None:+ layout = await MarkdownParser()._compute_layout(+ DOCUMENT, "viking://temp/test", source_path="/tmp/stuck-pr-watch.md"+ )++ assert _written(layout) == [DOCUMENT]+ assert layout.meta["frontmatter"] == {"id": "stuck-pr-watch", "name": "PR watch"}+++async def test_frontmatter_is_kept_when_config_omits_the_option() -> None:+ # The registry passes a bare ParserConfig when no [parsers.markdown] section+ # exists; that must not silently enable removal.+ layout = await MarkdownParser(config=ParserConfig())._compute_layout(+ DOCUMENT, "viking://temp/test", source_path="/tmp/stuck-pr-watch.md"+ )++ assert _written(layout) == [DOCUMENT]+ assert layout.meta["frontmatter"] == {"id": "stuck-pr-watch", "name": "PR watch"}+++ "parser",+ [+ MarkdownParser(extract_frontmatter=True),+ MarkdownParser(config=MarkdownConfig(extract_frontmatter=True)),+ ],+)+async def test_frontmatter_is_removed_only_when_explicitly_requested(+ parser: MarkdownParser,+) -> None:+ layout = await parser._compute_layout(+ DOCUMENT, "viking://temp/test", source_path="/tmp/stuck-pr-watch.md"+ )++ assert _written(layout) == [BODY]+ assert layout.meta["frontmatter"] == {"id": "stuck-pr-watch", "name": "PR watch"}+++async def test_frontmatter_title_still_names_the_document_when_kept() -> None:+ document = "---\ntitle: Release Notes\n---\n\n# Guide\n\nbody text\n"++ layout = await MarkdownParser()._compute_layout(+ document, "viking://temp/test", source_path="/tmp/whatever.md"+ )++ assert layout.doc_title == "Release Notes"+ assert _written(layout) == [document]