fix(memory): replace yaml_quote with sanitize_hint in consolidation frontmatter writers#1388
fix(memory): replace yaml_quote with sanitize_hint in consolidation frontmatter writers#1388ralf003 wants to merge 2 commits into
Conversation
…rontmatter writers
Replace yaml_quote() in fact.rs and quote-replacing sanitize() in
episode.rs with sanitize_hint() that only replaces newlines and ASCII
control chars with spaces, without YAML double-quoting or backslash
escaping.
The hand-rolled frontmatter readers (parse_frontmatter_flat /
extract_title_and_description) use split_once(": ") +
trim_matches('"') and do NOT interpret YAML escapes, so YAML-style
escaping is asymmetric and causes a round-trip regression on Windows
paths containing backslashes.
This aligns with the standard established in PR 1154.
Changes:
- fact.rs: replace yaml_quote() with sanitize_hint()
- episode.rs: update sanitize() to match sanitize_hint() pattern
- Add 10 unit tests: 8 for sanitize_hint edge cases plus 2 for
title/path with special chars in to_markdown()
Code reviewFound 1 issue:
anolisa/src/agent-memory/src/consolidation/fact.rs Lines 268 to 296 in ee95701 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Add frontmatter write->read round-trip assertions to fact_title_with_special_chars and fact_path_with_backslashes tests: - Extract title/paths from to_markdown() output and verify they survive the write->read cycle without escaping artifacts. - Verify no YAML double-quoting artifacts are present. - Addresses review feedback from shiloong on PR alibaba#1388.
|
@shiloong thanks for the review! Addressed in 1c4ee60:
Both tests pass locally (14/14 in |
Add frontmatter write->read round-trip assertions to fact_title_with_special_chars and fact_path_with_backslashes tests: - Extract title/paths from to_markdown() output and verify they survive the write->read cycle without escaping artifacts. - Verify no YAML double-quoting artifacts are present. - Addresses review feedback from shiloong on PR alibaba#1388.
1c4ee60 to
53b99e3
Compare
|
CI fix: cargo fmt --check failure resolved. Amended commit to apply rustfmt formatting on the new round-trip test code in fact.rs. Force-pushed to \ix/consolidation-frontmatter-sanitize. The formatting issue was: multi-line method chains, argument wrapping, and comment formatting in the newly added assertions didn't match the upstream rustfmt config. |
Summary
Apply the sanitize_hint pattern from PR #1154 to the consolidation module frontmatter writers (fact.rs, episode.rs).
Problem
PR #1154 established that
sanitize_hint()is the correct way to sanitize frontmatter values: only replace newlines and ASCII control chars with spaces, without YAML double-quoting or backslash escaping.The consolidation module had two non-compliant sanitizers:
fact.rsyaml_quote(): Applied full YAML double-quoting + backslash escaping + newline replacement — asymmetric with the hand-rolled frontmatter readers that usesplit_once(": ")+trim_matches('"')and do NOT interpret YAML escapes.episode.rssanitize(): Replaced"with'— mangles quotes instead of preserving them, and still misses control char handling.Root Cause
The hand-rolled frontmatter readers (
parse_frontmatter_flatin memory_observe/memory_sovereignty/memory_summary_tool/session_context/session_history/user_profile) use simple string splitting and do not interpret YAML escapes. YAML-style escaping on the write side is therefore asymmetric, causing:yaml_quote)Changes
fact.rsyaml_quote()withsanitize_hint()(same implementation as memory_observe.rs)to_markdown()to callsanitize_hintinstead ofyaml_quoteepisode.rssanitize()to matchsanitize_hint()pattern (no more'replacement)Testing
All 188 tests pass including 10 new tests:
cargo test --libon Alibaba Cloud Linux.Related