Skip to content

The agent that grows with you

fix(openviking): synchronize setup connection state

ehz0ah64b96bb5d275
diff --git a/plugins/memory/openviking/README.md b/plugins/memory/openviking/README.md
index cf9af8a198d..7bea6ad3ebc 100644
--- a/plugins/memory/openviking/README.md
+++ b/plugins/memory/openviking/README.md
@@ -103,10 +103,15 @@ no peer, remove the peer value from each configured source and start a new
Hermes session.
Upgrades do not move or delete existing memories. Installations that relied
-on the old implicit `hermes` peer now use user memory for new writes. Set
-`agent: hermes` to retain that previous behavior. Without a peer ID, default
-OpenViking search can still find old peer memories, including other peers
-under the same OpenViking user. Keep a peer ID if you need the narrower view.
+on the old implicit `hermes` peer now use user memory for new writes. Without
+a peer ID, default OpenViking search covers user memory and existing peer
+memories under the same OpenViking user. Old peer memories stay at their
+existing paths and remain searchable. Ranking and result limits determine
+which memories are returned. Keep a peer ID if you need the narrower view.
+
+Set `agent: hermes` to restore peer-scoped writes. Memories written at user
+scope before this change stay there and remain searchable. This setting
+changes future writes, not the location of existing memories.
## Tools
diff --git a/plugins/memory/openviking/__init__.py b/plugins/memory/openviking/__init__.py
index 96eff0bc59f..8280977cfed 100644
--- a/plugins/memory/openviking/__init__.py
+++ b/plugins/memory/openviking/__init__.py
@@ -2054,11 +2054,15 @@ def _save_hermes_only_config(
# Non-empty peer values, if supplied, are saved with the connection below.
provider_config.pop("agent", None)
_set_openviking_provider(config, provider_config)
- _write_env_vars(
- env_path,
- _env_writes_from_connection_values(values),
- remove_keys=_OPENVIKING_ENV_KEYS,
- )
+ # Use the file writer's cleaned values in the current process as well.
+ writes = {
+ key: _env_line_safe(value)
+ for key, value in _env_writes_from_connection_values(values).items()
+ }
+ _write_env_vars(env_path, writes, remove_keys=_OPENVIKING_ENV_KEYS)
+ os.environ.update(writes)
+ for key in set(_OPENVIKING_ENV_KEYS) - set(writes):
+ os.environ.pop(key, None)
def _profile_display_name(profile: _OvcliProfile) -> str:
@@ -2504,8 +2508,9 @@ class OpenVikingMemoryProvider(MemoryProvider):
"use_ovcli_config": True,
"ovcli_config_path": str(ovcli_path),
"endpoint": settings.get("endpoint") or _DEFAULT_ENDPOINT,
- "agent": settings.get("agent") or _DEFAULT_AGENT,
}
+ if settings.get("agent"):
+ display["agent"] = settings["agent"]
if settings.get("account"):
display["account"] = settings["account"]
if settings.get("user"):
diff --git a/tests/plugins/memory/test_openviking_optional_peer.py b/tests/plugins/memory/test_openviking_optional_peer.py
index 3c14122407c..281d73077ec 100644
--- a/tests/plugins/memory/test_openviking_optional_peer.py
+++ b/tests/plugins/memory/test_openviking_optional_peer.py
@@ -1,6 +1,7 @@
"""Optional peer identity must agree across setup, requests and memory writes."""
import json
+import os
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
from pathlib import Path
@@ -16,6 +17,8 @@ def isolated_config(tmp_path, monkeypatch):
monkeypatch.setattr(Path, "home", lambda: tmp_path)
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes"))
for key in (*ov._OPENVIKING_ENV_KEYS, "OPENVIKING_CLI_CONFIG_FILE"):
+ # Track absent keys too, so setup's direct environment writes are undone.
+ monkeypatch.setenv(key, "")
monkeypatch.delenv(key, raising=False)
@@ -60,6 +63,24 @@ def test_unconfigured_client_and_schema_do_not_supply_a_peer():
assert "X-OpenViking-Actor-Peer" not in client._multipart_headers()
[email protected]("peer", ["", "hermes"])
+def test_linked_profile_status_only_shows_a_configured_peer(tmp_path, peer):
+ path = tmp_path / "ovcli.conf"
+ path.write_text(
+ json.dumps({"url": "http://localhost:1933", "actor_peer_id": peer}),
+ encoding="utf-8",
+ )
+ display = ov.OpenVikingMemoryProvider().get_status_config({
+ "use_ovcli_config": True,
+ "ovcli_config_path": str(path),
+ })
+
+ if peer:
+ assert display["agent"] == peer
+ else:
+ assert "agent" not in display
+
+
@pytest.mark.parametrize("peer", ["", "hermes"])
def test_memory_uri_uses_captured_peer_even_when_empty(monkeypatch, peer):
client = ov._VikingClient("http://localhost:1933", agent=peer)
@@ -76,11 +97,13 @@ def test_memory_uri_uses_captured_peer_even_when_empty(monkeypatch, peer):
@pytest.mark.parametrize("save_to_store", [False, True])
@pytest.mark.parametrize("credential", ["dev", "user", "root", "service"])
[email protected]("stale_env", [False, True])
def test_new_setup_does_not_ask_for_or_save_peer(
tmp_path,
monkeypatch,
save_to_store,
credential,
+ stale_env,
):
from hermes_cli import memory_setup
@@ -90,6 +113,12 @@ def test_new_setup_does_not_ask_for_or_save_peer(
"OPENVIKING_AGENT=old-peer\nOTHER_KEY=keep\n", encoding="utf-8"
)
config = {"memory": {"openviking": {"agent": "old-peer", "recall_limit": 9}}}
+ if stale_env:
+ for key in ov._OPENVIKING_ENV_KEYS:
+ monkeypatch.setenv(
+ key, "old-peer" if key == "OPENVIKING_AGENT" else "old-value"
+ )
+ monkeypatch.setenv("OTHER_KEY", "keep")
validations = []
def validate(values, **kwargs):
@@ -140,7 +169,14 @@ def test_new_setup_does_not_ask_for_or_save_peer(
assert "OTHER_KEY=keep" in (home / ".env").read_text(encoding="utf-8")
saved_config = ov._load_hermes_openviking_config()
assert saved_config["recall_limit"] == 9
- assert ov._resolve_connection_settings(saved_config)["agent"] == ""
+ settings = ov._resolve_connection_settings(saved_config)
+ assert settings["agent"] == ""
+ assert settings == {
+ key: validations[-1][key]
+ for key in ("endpoint", "api_key", "account", "user", "agent")
+ }
+ assert "OPENVIKING_AGENT" not in os.environ
+ assert os.environ["OTHER_KEY"] == "keep"
if save_to_store:
saved = json.loads(
Path(saved_config["ovcli_config_path"]).read_text(encoding="utf-8")
@@ -149,6 +185,57 @@ def test_new_setup_does_not_ask_for_or_save_peer(
assert "agent_id" not in saved
[email protected]("peer", ["", "work-assistant"])
+def test_hermes_only_save_uses_the_same_clean_values_in_file_and_process(
+ tmp_path, peer
+):
+ from dotenv import dotenv_values
+
+ env_path = tmp_path / ".env"
+ ov._save_hermes_only_config(
+ config={"memory": {}},
+ provider_config={},
+ env_path=env_path,
+ values={
+ "endpoint": "http://localhost:29333",
+ "api_key": "test\r\n-key\x00",
+ "agent": peer,
+ },
+ )
+
+ expected = {
+ "OPENVIKING_ENDPOINT": "http://localhost:29333",
+ "OPENVIKING_API_KEY": "test-key",
+ }
+ if peer:
+ expected["OPENVIKING_AGENT"] = peer
+ assert dict(dotenv_values(env_path)) == expected
+ assert {
+ key: os.environ[key] for key in ov._OPENVIKING_ENV_KEYS if key in os.environ
+ } == expected
+
+
+def test_hermes_only_save_failure_leaves_process_environment_unchanged(
+ tmp_path, monkeypatch
+):
+ for key in ov._OPENVIKING_ENV_KEYS:
+ monkeypatch.setenv(key, "old-value")
+
+ def fail_write(*args, **kwargs):
+ raise OSError("test write failure")
+
+ monkeypatch.setattr(ov, "_write_env_vars", fail_write)
+ with pytest.raises(OSError, match="test write failure"):
+ ov._save_hermes_only_config(
+ config={"memory": {}},
+ provider_config={},
+ env_path=tmp_path / ".env",
+ values={"endpoint": "http://localhost:29333", "api_key": "test-key"},
+ )
+
+ assert all(os.environ[key] == "old-value" for key in ov._OPENVIKING_ENV_KEYS)
+
+
@pytest.mark.parametrize("peer", ["", "hermes"])
def test_wire_requests_keep_writes_and_session_messages_in_the_selected_scope(
tmp_path,
diff --git a/website/docs/user-guide/features/memory-providers.md b/website/docs/user-guide/features/memory-providers.md
index 66c374f17c6..1c35b07589c 100644
--- a/website/docs/user-guide/features/memory-providers.md
+++ b/website/docs/user-guide/features/memory-providers.md
@@ -336,9 +336,12 @@ for a peer ID. For separate assistant context, set
Existing non-empty peer settings keep their peer-scoped writes and recall.
This includes `OPENVIKING_AGENT` and `actor_peer_id` or legacy `agent_id` in a
linked OpenViking config. Existing memories are not moved or deleted.
-Installations that relied on the old implicit `hermes` peer can retain it by
-setting `memory.openviking.agent: hermes`. With no peer ID, default search can
-include all existing peer memories under the same OpenViking user.
+With no peer ID, default search covers user memory and existing peer memories
+under the same OpenViking user. Old peer memories remain searchable at their
+existing paths. Ranking and result limits determine which memories are returned.
+Set `memory.openviking.agent: hermes` to restore the old peer-scoped writes.
+Memories written at user scope before this change stay there and remain
+searchable. The setting changes future writes, not existing memory locations.
Hermes sends `User-Agent: openviking-memory-hermes/<version>` on OpenViking
requests. This standard harness identifier contains no per-user identifier and