[Bug]: Compact YAML lists in front matter are left behind when a field is rewritten, and the page's metadata gets reset
Description
findFrontmatterFieldEnd in src/okf/frontmatter.ts treats only blank and indented lines as part of a top-level front-matter field. A block sequence written in compact form, with its items at the key's own column, is valid YAML:
sources:
- id: external-policy
resource: https://example.com/policyFor this form the field ends right after sources:. When setOkfSources, setOkfVerified, the tags repair or removeFrontmatterField rewrites or removes the field, the old - ... items are left in place and the front matter no longer parses.
During claim-source synchronization (synchronizeClaimSources -> setOkfSources -> repairOkfFrontmatter), the invalid result falls through to rebuildMinimalConcept. A page that was valid before loses its type, title, custom fields and every source, and is stamped openwiki_generated: true.
The OpenWiki agent template writes indented lists, so this mainly hits front matter written by people or by other tools. Compact lists are also what PyYAML emits by default (yaml.dump({"tags": ["a"]}) gives tags:\n- a).
Steps to Reproduce
- Save this as
repro.tsin the repository root and runpnpm exec tsx repro.ts:
import {
setOkfSources,
validateOkfFrontmatter,
repairOkfFrontmatter,
} from "./src/okf/frontmatter.ts";
const page =
"---\ntype: Guide\ntitle: My Guide\nsources:\n- id: mine\n resource: repo://README.md\ncustom: keep\n---\n\n# Page\n";
console.log(validateOkfFrontmatter(page)); // { valid: true }
const updated = setOkfSources(page, [
{ id: "mine", resource: "repo://README.md" },
{ id: "openwiki-source-one", resource: "repo://src/page.ts" },
]);
console.log(updated);
console.log(validateOkfFrontmatter(updated));
console.log(repairOkfFrontmatter(updated, "docs/page.md").content);- Alternatively, write the page above to
openwiki/page.mdin a repository wiki and runsynchronizeClaimSources(backend, "repository", new Map([["/openwiki/page.md", ["repo://src/a.ts"]]])), which the wiki finalizer calls.
Expected Behavior
Only the sources field is replaced. type: Guide, title and custom: keep stay as they were, and the result is valid front matter with both sources.
This is the documented contract:
setOkfSources"Sets the OKFsourceslist while preserving every unrelated front-matter line byte-for-byte".replaceFrontmatterFieldBlock"Replaces one complete top-level front-matter field, including indented YAML continuation lines".repairOkfFrontmattersays producer extensions survive whenever the original YAML mapping is parseable.
The input passes validateOkfFrontmatter.
Actual Behavior
setOkfSources writes the new sources: block and leaves the old items after it:
type: Guide
title: My Guide
sources:
- id: mine
resource: repo://README.md
- id: openwiki-source-one
resource: repo://src/page.ts
- id: mine
resource: repo://README.md
custom: keepvalidateOkfFrontmatter then reports invalid_yaml: "A block sequence may not be used as an implicit map key at line 9, column 1". repairOkfFrontmatter, and so synchronizeClaimSources, replaces the whole block with:
type: "Reference"
title: "Page"
openwiki_generated: truetype, title, custom and every source are lost, including the claim source that was just projected.
Environment
- OS: macOS 26 (arm64)
- Node.js version: 22.14.0 (the bug is plain string handling and does not depend on the Node version)
- OpenWiki version: main @ 594ef3a (0.6.1)
Additional Context
Suggested fix: also treat column-0 - items (/^-(?:\s|$)/u) as continuation lines in findFrontmatterFieldEnd. The front-matter root is always a mapping, so such a line can only belong to the previous key's compact sequence. --- and keys such as -foo: do not match. I have a patch with regression tests and can open a PR.
AI assistance: drafted with an AI coding assistant (Claude). The reproduction above was run locally against the current default branch.
Source: langchain-ai/openwiki