Skip to content

fix(s09): parse frontmatter line-by-line instead of splitting on --- - #664

Open
shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s09-frontmatter-parsing
Open

shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s09-frontmatter-parsing

Conversation

@shuhuNB515

Copy link
Copy Markdown

Fixes #663

Problem

parse_frontmatter (s09_memory/code.py:75-88) had two defects, both silently corrupting persisted memory records:

  1. text.split("---", 2) ends the frontmatter at the first --- anywhere. YAML scalars containing --- are legal and yaml.safe_dump writes them unquoted — e.g. description: prefer uv---pip fallback. Verified against the real module: the old parser returns {'description': 'prefer uv'} (rest of the value leaks into the body), and the corruption is served back by rebuild_memory_index() on every later turn.
  2. CRLF files are treated as having no frontmatter — startswith("---\n") is false for "---\r\n", so name/type/description all degrade for a file edited with Windows line endings.

Fix

Switch to the line-based parser s07 already uses for the identical file format (s07_skill_loading/code.py:66-88): the closing delimiter must be a line of its own, and \r\n is tolerated. s09's existing error semantics ({}, text on YAML errors / non-dict metadata) are preserved, with a comment explaining the approach.

Verification (real module)

case old parser new parser
description: prefer uv---pip fallback {'description': 'prefer uv'} + body residue full metadata + clean body
CRLF file no frontmatter at all all fields parsed, body clean
normal LF file ok byte-identical result
unclosed / non-dict frontmatter ({}, text) unchanged

python3 -m pytest tests/ — 503 passed, 118 subtests passed. Embedded s09 source in web/src/data/generated/versions.json synced.


Disclosed AI assistance: found and fixed during an AI-assisted review; all failure modes reproduced against the real module before and after the change, and I stand behind it.

parse_frontmatter had two defects, both silently corrupting persisted
memories:

1. text.split("---", 2) ends the frontmatter at the first "---"
   anywhere -- including inside a legal YAML scalar like
   'description: prefer uv---pip fallback', which safe_dump writes
   unquoted. The value gets truncated and the body picks up residue.
2. startswith("---\n") rejects CRLF files, so every field degrades
   to defaults for a file edited with Windows line endings.

Switch to the line-based parser s07 already uses: the closing
delimiter must be a line of its own ("---" stays inside values), and
\r\n is tolerated. s09's error semantics (return {}, text on YAML
errors / non-dict metadata) are preserved, and normal LF files parse
identically. The embedded s09 source in the web registry is synced.

Fixes shareAI-lab#663

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

s09: parse_frontmatter splits on any "---" occurrence and rejects CRLF files — a value containing --- silently corrupts the memory record

1 participant