fix(frontmatter): defense-in-depth against JSON-style arrays in YAML#1238
Closed
garrytan-agents wants to merge 1 commit into
Closed
fix(frontmatter): defense-in-depth against JSON-style arrays in YAML#1238garrytan-agents wants to merge 1 commit into
garrytan-agents wants to merge 1 commit into
Conversation
Three layers to stop NESTED_QUOTES from recurring:
1. **autoFixFrontmatter (brain-writer.ts):** New step 3a detects and
rewrites JSON-style arrays (`["x", "y"]` → `['x', 'y']`) before
the existing nested-quote scalar fix. Handles apostrophes in values
by falling back to double quotes. Runs on `frontmatter validate --fix`
and `writeBrainPage({autoFix: true})`.
2. **Validator (markdown.ts):** NESTED_QUOTES detection now has two
sub-patterns — 5a catches JSON-style arrays specifically (with a
clearer error message: "use single quotes") and 5b catches the
original nested scalar quotes.
3. **put_page normalization (operations.ts):** Every `put_page` call now
runs `autoFixFrontmatter()` on incoming content before import.
Non-blocking — if normalization throws, original content is used.
This means agent-written pages with JSON arrays are silently fixed
on write instead of accumulating thousands of validation errors.
4. **Agent guidance (frontmatter-guard SKILL.md):** New "Prevention"
section with correct/incorrect YAML examples, explaining WHY
JSON.stringify causes the bug and what to do instead. Agents that
read this skill before writing frontmatter will avoid the pattern.
Root cause: LLMs and ingestion code use JSON.stringify for YAML array
items, producing `tags: ["yc", "w2025"]` which breaks YAML parsing.
This caused 6,981 errors across a 105K-page brain.
Companion to PR garrytan#1217 (serializer fix in frontmatter-inference.ts).
Owner
|
Superseded by #1252 (v0.37.6.0 wave). This PR's four-layer defense-in-depth was reviewed against the already-merged PR #1229 (validator fix, shipped as v0.37.5.0) and absorbed into the wave with two changes: Kept (with refinements):
Dropped:
Thank you @garrytan-agents — Layer 1 + Layer 4 + the original framing made it into v0.37.6.0 via #1252. Attribution preserved via |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The #1 source of
NESTED_QUOTESfrontmatter errors is JSON-style arrays in YAML:JSON.stringify()wraps values in double quotes. When code doestags: [${items.map(t => JSON.stringify(t)).join(', ')}], it produces broken YAML. This caused 6,981 validation errors across a 105K-page brain — the single largest contributor to the frontmatter integrity health score.Fix: Four Layers
1. Auto-fix on
frontmatter validate --fix(brain-writer.ts)New step 3a in
autoFixFrontmatter()detects JSON-style arrays and rewrites them to single-quoted YAML. Handles apostrophes by falling back to double quotes.2. Better detection in validator (markdown.ts)
NESTED_QUOTESdetection now has two sub-patterns:3. Auto-normalize on
put_page(operations.ts)Every
put_pagecall now runsautoFixFrontmatter()on incoming content before import. Non-blocking — if normalization throws, original content passes through. Agent-written pages with JSON arrays are silently fixed on write.4. Agent guidance (frontmatter-guard SKILL.md)
New "Prevention" section with correct/incorrect YAML examples, explaining WHY
JSON.stringifycauses the bug and what to do instead.Companion PRs
frontmatter-inference.ts(the source of the pattern when gbrain itself infers frontmatter)Impact