← Back to Pull requests

fix(hermes): give mirrored preferences their embedding template fields #5938

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 12, 2026 07:08 UTC
Author

Description

Hermes memories mirrored from the built-in memory tool (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_write maps target="user" to the preferences subdir and queues the write on NativeMemoryMirror. The add branch in native_memory_mirror.py then posts the bare entry text to /api/v1/content/write with mode: "create". For a memory URI, the server parses the submitted body with MemoryFileUtils.read, so any fields must arrive as a trailing <!-- MEMORY_FIELDS {...} --> comment. After the write, MemoryUpdater.refresh_file_embedding resolves the memory type from the path segment after memories/, which is preferences. _vectorize_memories then renders the schema's embedding_template ({{ user }} / {{ topic }} / {{ content }}) from the file's extra fields. The mirror sent no fields, so user and topic were 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 into MEMORY_FIELDS. Explicit viking_remember calls now go through a one-shot session and commit, so they also use extraction. target="memory" maps to patterns, which has no registered schema, so it never reaches the template branch. That left the built-in-memory mirror's preferences add 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 into native_memory_mirror.py by #5281.

The fix makes the mirror's add path append a MEMORY_FIELDS trailer for preferences writes. user is the confirmed user space already embedded in the URI, and topic is the fixed label hermes_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's replace mode preserves the existing fields, and an embedded trailer would otherwise land inside the body.

The issue also lists missing variables for events, cases and entities. Those files came from the old direct-write viking_remember path, which now goes through session extraction. The mirror never writes those types.

Human Involvement

  • A human participated in the implementation or review loop

  • This PR was generated entirely by AI agents without human participation in the loop
  • 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

  • Bug fix (non-breaking change that fixes an issue)

  • New feature (non-breaking change that adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • Documentation update

  • Refactoring (no functional changes)

  • Performance improvement

  • Test update
  • Changes Made

  • examples/hermes-plugin/native_memory_mirror.py: the add branch now sends preferences mirrors with a MEMORY_FIELDS trailer that carries user and topic. 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 a user add (trailer with user/topic) and a memory add (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.

  • Bump the Hermes plugin version to 2.1.2 (plugin.yaml, pyproject.toml).
  • Testing

  • I have added tests that prove my fix is effective or that my feature works

  • New and existing unit tests pass locally with my changes

  • I have tested this on the following platforms:

  • - [ ] Linux
    - [x] macOS
    - [ ] Windows

    I ran the full examples/hermes-plugin/tests suite through Hermes scripts/run_tests.sh against the CI-pinned host commit 7951ddd7, and all 395 tests passed. With the old native_memory_mirror.py, the new test and the updated replace test fail. I also fed the mirror's payload through the server's own MemoryFileUtils.read/write round trip and TemplateUtils.find_missing_variables against the preferences schema. 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 --check and ruff check pass on the changed source and new test.

    Checklist

  • My code follows the project's coding style

  • I have performed a self-review of my code

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation

  • My changes generate no new warnings

  • Any dependent changes have been merged and published
  • 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 replace from the mirror does not backfill fields, because the server's replace mode keeps the existing (empty) fields. topic is 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. The preferences overview template uses topic as each entry's list label, so mirrored entries in the directory overview are now labelled hermes_user_memory instead of their mem_ file name.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: ehz0ah Review duration: 4381m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%