Skip to content

fix: YAML-escape frontmatter scalars (harvest→review break found in UAT) - #111

Merged
ooiyeefei merged 3 commits into
mainfrom
fix/frontmatter-yaml-escaping
May 29, 2026
Merged

ooiyeefei merged 3 commits into
mainfrom
fix/frontmatter-yaml-escaping

Conversation

@ooiyeefei

@ooiyeefei ooiyeefei commented May 29, 2026 •

Copy link
Copy Markdown
Owner

The bug (found by end-to-end UAT, not unit tests)

Running the full harvest → review → eval chain on real Codex data exposed a break: stage_pending_decisions built YAML frontmatter via raw f-string interpolation, so any value with a colon broke it. Harvest reliably produces such values:

reasoning: Imported from Codex native memory: memory_summary.md
                                            ^ unescaped colon → invalid YAML

spanweave review then crashed (mapping values are not allowed here) and all 80 harvested native-codex records failed to route — Accepted 0. gemma extractions rarely contain colons, so this stayed latent until native-memory harvest (#110) started producing them.

Fix

_yaml_scalar() serializes type / source / reasoning / tags through yaml.safe_dump (flow style) so colons, quotes, and newlines are escaped. Plus a regression test asserting staged frontmatter round-trips through yaml.safe_load with a colon+quote-laden value.

Verification — full UAT now green

Step Before After
review --auto-accept on 82 records (2 gemma + 80 native) crash, Accepted 0 Accepted 82
routed by type none 2 decisions, 76 findings, …
eval dual-track Track A empty Track A=80, Track B=2

326 tests pass · ruff clean · pyright 0 errors.

★ Lesson — this is the "verify at the level the bug manifests" rule in action: harvest's unit tests asserted records were written; only running them through review revealed they couldn't be parsed back.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved YAML frontmatter generation for pending decisions to safely escape and quote values, preventing parse errors when content contains colons, quotes, newlines, or similar characters.
    • Ensured tags are serialized as YAML-safe entries while preserving the existing fallback for empty tag lists.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@ooiyeefei, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 54 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 06a16c45-0fd2-4cf2-82de-f01fd0998fc3

📥 Commits

Reviewing files that changed from the base of the PR and between 5954ede and 529598c.

📒 Files selected for processing (1)
  • tests/test_extractor.py
📝 Walkthrough

Walkthrough

Adds a _yaml_scalar(...) helper to produce single-line YAML-safe scalars and updates stage_pending_decisions() to use it for type, source, reasoning, and tag entries in frontmatter; also adds a regression test validating YAML parseability. Timestamp, filename, and body placement are unchanged.

Changes

YAML Frontmatter Serialization

Layer / File(s) Summary
Add _yaml_scalar helper
spanweave/learning/extractor.py
Adds _yaml_scalar(value: Any) -> str that uses yaml.safe_dump to produce single-line YAML scalars and strips document-end markers and extra whitespace.
Apply helper in pending decision staging and test
spanweave/learning/extractor.py, tests/test_extractor.py
stage_pending_decisions() now serializes type, source, reasoning, and each tag with _yaml_scalar(...), keeping tags: [] fallback behavior; a regression test ensures frontmatter stays parseable when reasoning contains YAML-sensitive characters.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble on colons and quotes at night,
I learned to wrap scalars snug and tight,
_yaml_scalar hums a safe little song,
Frontmatter now stays tidy and strong,
Hooray — no parse errors in sight!


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

…sing

End-to-end UAT (harvest -> review -> eval) surfaced a real break the unit
tests missed: stage_pending_decisions built frontmatter with raw f-string
interpolation, so a value containing a colon — e.g. harvest's
"reasoning: Imported from Codex native memory: memory_summary.md" — produced
invalid YAML. `spanweave review` then crashed with "mapping values are not
allowed here" and ALL 80 harvested native-codex records failed to route
(Accepted 0). gemma extractions rarely contain colons, so this stayed
latent until native-memory harvest (#110) reliably produced them.

Fix: a `_yaml_scalar()` helper serializes type/source/reasoning/tags via
yaml.safe_dump(flow style), so colons, quotes, and newlines are escaped.
Regression test asserts the staged frontmatter round-trips through
yaml.safe_load with a colon+quote-laden reasoning value.

Verified: full UAT now shows review "Accepted 82", records routed by type
(decisions/findings), and eval reports Track A=80 / Track B=2. 326 tests
pass, ruff + pyright clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ooiyeefei
ooiyeefei force-pushed the fix/frontmatter-yaml-escaping branch from a723fbd to 2b8fc79 Compare May 29, 2026 05:47
ooiyeefei and others added 2 commits May 29, 2026 05:49
…mend)

The regression test guarding the colon-in-frontmatter fix didn't make it
into the prior commit (the Edit failed silently, so only extractor.py was
committed). Add it now. RED-proven: fails on raw-interpolation, passes with
_yaml_scalar.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…001)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ooiyeefei
ooiyeefei merged commit 0a8fd42 into main May 29, 2026
7 checks passed
@ooiyeefei
ooiyeefei deleted the fix/frontmatter-yaml-escaping branch May 29, 2026 05:51
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.

1 participant