fix(hermes): give mirrored preferences their embedding template fields #5938
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #5938"
general
weight: 0.35
ehz0ah
Description
Hermes memories mirrored from the built-in
memorytool (target="user") were indexed with plain-content embeddings. Each write also logged a server warning:Missing embedding template variables for viking://user/<uid>/peers/hermes/memories/preferences/mem_.md, falling back to plain content: ['topic', 'user'].Root cause:
on_memory_writemapstarget="user"to thepreferencessubdir and queues the write onNativeMemoryMirror. The add branch innative_memory_mirror.pythen posts the bare entry text to/api/v1/content/writewithmode: "create". For a memory URI, the server parses the submitted body withMemoryFileUtils.read, so any fields must arrive as a trailing<!-- MEMORY_FIELDS {...} -->comment. After the write,MemoryUpdater.refresh_file_embeddingresolves the memory type from the path segment aftermemories/, which ispreferences._vectorize_memoriesthen renders the schema'sembedding_template({{ user }} / {{ topic }} / {{ content }}) from the file's extra fields. The mirror sent no fields, souserandtopicwere missing and every mirrored preference fell back to plain content.Other write paths behave differently. Session extraction writes memories through
MemoryUpdater, which serializes all schema fields intoMEMORY_FIELDS. Explicitviking_remembercalls now go through a one-shot session and commit, so they also use extraction.target="memory"maps topatterns, which has no registered schema, so it never reaches the template branch. That left the built-in-memory mirror'spreferencesadd path as the only one still producing template-incomplete files. This path has written the plain body since the standalone provider was imported in #5152, and the mirror was later moved intonative_memory_mirror.pyby #5281.The fix makes the mirror's add path append a
MEMORY_FIELDStrailer forpreferenceswrites.useris the confirmed user space already embedded in the URI, andtopicis the fixed labelhermes_user_memory. The server strips the trailer from the body and stores it as fields, so the file body and the local registry entry stay identical to the native entry. Replace keeps sending only the new body: the server'sreplacemode preserves the existing fields, and an embedded trailer would otherwise land inside the body.The issue also lists missing variables for
events,casesandentities. Those files came from the old direct-writeviking_rememberpath, which now goes through session extraction. The mirror never writes those types.Human Involvement
Related Issue
Reported upstream as NousResearch/hermes-agent#86316, which was closed and redirected here because the provider now ships from this repository.
Type of Change
Changes Made
examples/hermes-plugin/native_memory_mirror.py: the add branch now sendspreferencesmirrors with aMEMORY_FIELDStrailer that carriesuserandtopic. Other subdirs, replace and remove are unchanged, and the registry still stores the plain committed entry.examples/hermes-plugin/tests/test_native_memory_mirror.py: new regression test covering auseradd (trailer withuser/topic) and amemoryadd (plain body), and checking that the registry keeps plain content. The existing replace test now checks the create body and its fields the same way.examples/hermes-plugin/tests/test_standalone.py: the fake server strips the trailer when storing a file, matching the real server's body/field split.plugin.yaml,pyproject.toml).Testing
- [ ] Linux
- [x] macOS
- [ ] Windows
I ran the full
examples/hermes-plugin/testssuite through Hermesscripts/run_tests.shagainst the CI-pinned host commit7951ddd7, and all 395 tests passed. With the oldnative_memory_mirror.py, the new test and the updated replace test fail. I also fed the mirror's payload through the server's ownMemoryFileUtils.read/writeround trip andTemplateUtils.find_missing_variablesagainst thepreferencesschema. Before the fix the missing set is['topic', 'user']; after the fix it is empty, and the stored body is still the plain entry.ruff format --checkandruff checkpass on the changed source and new test.Checklist
Screenshots (if applicable)
N/A
Additional Notes
Mirrored preferences created before this change keep their plain-content embeddings until they are next rewritten through extraction. A later
replacefrom the mirror does not backfill fields, because the server'sreplacemode keeps the existing (empty) fields.topicis a fixed label rather than one derived from the content. Fields are immutable on replace, so a content-derived topic would go stale after the first edit. Thepreferencesoverview template usestopicas each entry's list label, so mirrored entries in the directory overview are now labelledhermes_user_memoryinstead of theirmem_file name.