Skip to content

fix(openviking): mirror native memory lifecycle - #100187

Closed
ehz0ah wants to merge 6 commits into
NousResearch:mainfrom
ehz0ah:fix/openviking-native-memory-mirror
Closed

ehz0ah wants to merge 6 commits into
NousResearch:mainfrom
ehz0ah:fix/openviking-native-memory-mirror

Conversation

@ehz0ah

@ehz0ah ehz0ah commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Hermes mirrors successful built-in memory additions to OpenViking, but it does not mirror later replace or remove operations. This can leave old native memories searchable in OpenViking after the user updates or deletes them in Hermes.

This PR gives each mirrored native memory a stable OpenViking URI. It stores the URI in a profile-scoped registry, then uses the same URI for later replace and remove operations. Events run through one FIFO worker, destructive operations fail closed when the mapping is missing or ambiguous, and failures are visible at warning level.

The registry is isolated by OpenViking connection and identity. It does not own session-extracted memories or explicit viking_remember results. Those paths remain unchanged.

This work continues and supersedes #85860. It preserves the useful stable-URI design and adds current-main compatibility, connection isolation, shared-profile serialization, lifecycle race protection, and failure-boundary coverage.

Related Issue

Fixes #31000

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Security fix
  • Documentation update
  • Tests (adding or improving test coverage)
  • Refactor (no behavior change)
  • New skill (bundled or hub)

Changes Made

  • Require a server-confirmed user identity before creating a new mirrored URI.
  • Add a profile-scoped registry that maps native memory entries to exact OpenViking URIs.
  • Mirror native add, replace, and remove operations in FIFO order.
  • Forward the supported batch new_text alias to external providers for add and replace operations.
  • Wait for OpenViking semantic cleanup after replace and remove.
  • Isolate mappings by endpoint, credentials, user identity, and actor peer.
  • Serialize registry updates across provider instances in one Hermes process.
  • Keep registry state unchanged after failed remote replace or remove operations.
  • Distinguish unreadable, invalid, and unsupported mirror registries without weakening fail-closed behavior.
  • Log mirror failures at warning level and document fail-closed and recovery boundaries.

How to Test

  1. Configure Hermes to use an OpenViking server.
  2. Add a fact with the built-in memory tool, then replace it by old_text. Confirm that OpenViking updates the same URI and no longer returns the old content.
  3. Remove the fact by old_text. Confirm that the exact URI and its search result are removed.

Validation completed after rebasing onto upstream main 4f6ef8806f:

  • Focused OpenViking provider and mirror tests: 84 passed.
  • Canonical isolated memory-provider suite: 421 passed and 2 skipped.
  • Canonical isolated OpenViking plugin suite: 47 passed.
  • Canonical isolated memory bridge, provider, and run-agent suites: 370 passed.
  • Updated affected suite after review fixes: 502 passed and 2 skipped.
  • Registry failure tests under eight-way contention with retries disabled: 24 of 24 runs passed.
  • The batch new_text bridge test fails on the old forwarding logic and passes with this fix.
  • FIFO lifecycle regression test: 20 consecutive standalone runs passed.
  • Current OpenViking main 2251aa136a confirms the identity, content write, and exact delete API contracts used by the mirror.
  • Earlier live lifecycle test against OpenViking 0.4.18.dev21: server-confirmed user resolution, add, same-URI replace, exact read, exact delete, and empty final registry all passed.
  • Ruff, targeted ty, Python compilation, and Git whitespace checks passed.

Checklist

Code

  • I've read the Contributing Guide.
  • My commit message follows Conventional Commits.
  • I searched for existing PRs and based this work on fix(openviking): mirror native memory replace/remove with stable URIs #85860.
  • My PR contains only changes related to this fix.
  • I have run pytest tests/ -q and all tests pass. The affected suites pass, but the complete repository suite was not rerun locally.
  • I've added tests for my changes.
  • I've tested on macOS.

Documentation & Housekeeping

  • I've updated relevant documentation.
  • cli-config.yaml.example is not affected.
  • CONTRIBUTING.md and AGENTS.md are not affected.
  • I've considered cross-platform impact. Registry writes request mode 0600 on POSIX, and the Windows ACL limitation is documented.
  • Tool descriptions and schemas are not affected.

Screenshots / Logs

Not applicable.

@ehz0ah
ehz0ah marked this pull request as ready for review September 1, 2026 09:53
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins tool/memory Memory tool and memory providers area/memory sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Sep 1, 2026
@ehz0ah
ehz0ah force-pushed the fix/openviking-native-memory-mirror branch from bbec0ee to e7329dd Compare September 1, 2026 10:42
@Enough1122

Copy link
Copy Markdown
Contributor

AI code review — automated review for reference; please use your judgment.

This is a well-designed and unusually thorough PR: it replaces the single-shot add-only mirror with a FIFO worker (native_memory_mirror.py) that keeps a profile-scoped registry mapping native memory text to exact OpenViking URIs, enabling replace/remove to fail closed instead of guessing by similarity. Key mechanics are sound: per-path process-wide registry locks make the remote-mutation + registry-update cycle atomic across provider instances; _resolve_mapping demands exactly one substring match (old_text in entry["content"]) and raises _MappingError otherwise; the connection fingerprint isolates mappings across endpoints/keys without storing raw credentials; the identity probe for add is server-confirmation-only via the new require_confirmed path; shutdown drains the queue before joining; and the local commit-before-remote-order, drift, and 0600-mode caveats are documented. The 554-line test suite covers FIFO ordering, restart persistence, connection isolation, ambiguous/unmapped fail-closed, failed post/delete keeping prior mappings, registry-save failure, concurrent construction (one worker), and serialized shared-registry updates.

Points to verify (non-blocking):

  • The require_confirmed raise in _user_space is placed after the cache-hit return, so a cache hit bypasses the confirmation requirement. Per the docstring the cache only ever stores server-confirmed identities, making this safe — worth confirming the configured-fallback path never writes to _user_space_cache, since a stale confirmed identity for a connection whose server-side user changed would then be reused.
  • In the add path, the mapping is recorded after client.post returns, but the response status isn't validated — if the real client ever returns an error dict instead of raising, a mapping could be registered for a write the server rejected, and a later replace would target a nonexistent URI. (The fake client always returns ok, so this is only relevant if the real client is non-raising on errors.)

Verdict: LGTM

@ehz0ah
ehz0ah force-pushed the fix/openviking-native-memory-mirror branch from dc7c501 to 44acc01 Compare September 6, 2026 19:15
@ehz0ah
ehz0ah force-pushed the fix/openviking-native-memory-mirror branch from a1e388d to 32f75a9 Compare September 8, 2026 07:02
ZaynJarvis pushed a commit to volcengine/OpenViking that referenced this pull request Sep 23, 2026
* fix(hermes): mirror native memory replacements and removals

Port the provider implementation from NousResearch/hermes-agent#100187 at 32f75a9e6728a9a3d2f50a870dab3715a1f34fd7, which continues #85860. Keep the existing profile and connection-generation fixes, use relative imports and context-preserving workers, and cover the external loader and native-memory bridge.

* test(hermes): retain native memory mirror regression coverage

* fix(hermes): require committed entry identity and report indexing failures

* fix(hermes): clarify asynchronous add indexing status
@ehz0ah

ehz0ah commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

This work is now merged into the OpenViking-owned external Hermes plugin in OpenViking #5281.

The adaptation uses the exact committed previous_content from Hermes #118903, landed through #120003, for safe replacement and deletion. It also handles replacement indexing failures without losing the updated URI mapping. External-loader tests and real local OpenViking checks covered replacement, search refresh, restart deletion, batches, and profile isolation.

This covers the feature in OpenViking/examples/hermes-plugin; it does not update the bundled provider in Hermes.

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

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenViking plugin: on_memory_write mirroring silently fails — 3 bugs

3 participants