Skip to content

The agent that grows with you

fix(openviking): start openviking-server from the scrubbed child env

John Paul Solivada1211f27993
diff --git a/plugins/memory/openviking/__init__.py b/plugins/memory/openviking/__init__.py
index c37d15164d4..8e21c70b268 100644
--- a/plugins/memory/openviking/__init__.py
+++ b/plugins/memory/openviking/__init__.py
@@ -979,7 +979,12 @@ def _start_local_openviking_server(endpoint: str) -> tuple[str, str]:
# would import aiohttp and friends from the Hermes venv instead of its own (its venv's site-packages
# are shadowed because PYTHONPATH precedes them) — and on Windows the loaded DLLs then lock the
# Hermes venv, aborting `hermes update` with access-denied on .pyd files. (#78153)
- child_env = os.environ.copy()
+ # The server's embedding/VLM models may read provider keys, so those pass; bot, gateway
+ # and relay tokens never do. HOME stays the user's: ov.conf defaults to ~/.openviking.
+ from tools.environments.local import hermes_subprocess_env
+ child_env = hermes_subprocess_env(inherit_credentials=True)
+ if "HOME" in os.environ:
+ child_env["HOME"] = os.environ["HOME"]
child_env.pop("PYTHONPATH", None)
with log_path.open("ab") as log_file:
subprocess.Popen([server_cmd, "--host", host, "--port", str(port)], stdout=log_file, stderr=log_file,
diff --git a/tests/agent/test_subprocess_env_guard.py b/tests/agent/test_subprocess_env_guard.py
index f0f0396f6ee..a78b4b9ed41 100644
--- a/tests/agent/test_subprocess_env_guard.py
+++ b/tests/agent/test_subprocess_env_guard.py
@@ -56,15 +56,16 @@ ALLOWED_RAW_SPAWN_ENV_FILES = {
"hermes_cli/gateway.py",
"hermes_cli/stderr_timestamp.py",
"hermes_cli/profiles.py",
- # apt/dpkg run as root: sudo resets the environment, and the scrub helpers would point
- # TMPDIR into HERMES_HOME's scratch dir, leaving root-owned files there.
+ # apt/dnf/pacman run as root, through sudo (which resets the environment) or because Hermes
+ # already is root. A root child can read every process's environment anyway, and the scrub
+ # helpers would point TMPDIR into HERMES_HOME's scratch dir, leaving root-owned files there.
"tools/bot_desktop/install.py",
- # The docker/ssh CLIENT process: same as inheriting (``None``) plus the forwarded values;
- # what may be forwarded is decided by the backend's forward/passthrough policy.
+ # The docker/ssh CLIENT process: the user's own backend binary, never code the agent runs,
+ # needing their real HOME for ~/.ssh and ~/.docker. Same as inheriting (``None``) plus the
+ # forwarded values; what crosses into the sandbox is the backend's forward/passthrough policy.
"tools/environments/remote_common.py",
- # openviking-server is the user's own memory server and may read their provider keys for
- # its embedding/VLM models; only the Hermes PYTHONPATH is removed (#78153).
- "plugins/memory/openviking/__init__.py",
+ # Needing provider keys is not a reason to be here: such a child uses
+ # hermes_subprocess_env(inherit_credentials=True), which still drops bot/relay tokens.
}
diff --git a/tests/tools/test_spawn_site_child_env.py b/tests/tools/test_spawn_site_child_env.py
index 45dc1cc04ae..312cd26609c 100644
--- a/tests/tools/test_spawn_site_child_env.py
+++ b/tests/tools/test_spawn_site_child_env.py
@@ -28,23 +28,60 @@ def _probe_script(path: Path, out: Path, names) -> Path:
return path
-def test_compute_host_child_keeps_provider_keys_but_never_tier1_secrets(child_env, monkeypatch):
+def _compute_host_seen(child_env, monkeypatch, names):
from tui_gateway.host_supervisor import HostSupervisor
- _plant(monkeypatch)
- names = [*_TIER1, _PROVIDER, "HERMES_COMPUTE_HOST_HEARTBEAT_SECS"]
hello = ("import json, os, sys; print(json.dumps({'type': 'hello', 'seen': "
f"{{n: os.environ.get(n) for n in {names!r}}}}}), flush=True); sys.stdin.readline()")
sup = HostSupervisor(registry_path=child_env / "host.json", argv=[sys.executable, "-c", hello],
cwd=child_env, expected_build_sha="unknown", autostart=False)
try:
sup.start()
- seen = sup._hello["seen"]
+ return sup._hello["seen"]
finally:
sup.shutdown()
+
+
+def _openviking_server_seen(child_env, monkeypatch, names):
+ import subprocess
+
+ import plugins.memory.openviking as ov
+
+ out = child_env / "seen.json"
+ probe = _probe_script(child_env / "openviking-server", out, names)
+ monkeypatch.setattr(ov, "_local_openviking_port_is_open", lambda host, port: False)
+ monkeypatch.setattr(ov.shutil, "which", lambda name: str(probe))
+ real_popen, children = subprocess.Popen, []
+
+ def _record(*args, **kwargs):
+ children.append(real_popen(*args, **kwargs))
+ return children[-1]
+
+ monkeypatch.setattr(ov.subprocess, "Popen", _record)
+ state, _ = ov._start_local_openviking_server("http://127.0.0.1:1933")
+ assert state == ov._LOCAL_SERVER_STARTED
+ children[0].wait(timeout=30)
+ return json.loads(out.read_text(encoding="utf-8"))
+
+
+ "compute_host", pytest.param("openviking_server", marks=pytest.mark.platforms("posix"))])
+def test_credentialed_children_keep_provider_keys_but_never_tier1_secrets(child_env, monkeypatch, site):
+ # Both children call model providers (the turn process; openviking-server's embedding/VLM
+ # models), so provider keys pass by design. Bot and relay tokens never do.
+ _plant(monkeypatch)
+ if site == "compute_host":
+ own = {"HERMES_COMPUTE_HOST_HEARTBEAT_SECS": "15"}
+ seen = _compute_host_seen(child_env, monkeypatch, [*_TIER1, _PROVIDER, *own])
+ else:
+ # The server finds ov.conf through OPENVIKING_CONFIG_FILE or HOME; Hermes' PYTHONPATH
+ # would shadow its own site-packages (#78153).
+ monkeypatch.setenv("OPENVIKING_CONFIG_FILE", str(child_env / "ov.conf"))
+ monkeypatch.setenv("PYTHONPATH", str(child_env / "hermes-venv"))
+ own = {"OPENVIKING_CONFIG_FILE": str(child_env / "ov.conf"), "HOME": str(child_env), "PYTHONPATH": None}
+ seen = _openviking_server_seen(child_env, monkeypatch, [*_TIER1, _PROVIDER, *own])
assert seen == {"TELEGRAM_BOT_TOKEN": None, "GATEWAY_RELAY_SECRET": None,
- # The turn process drives the model, so provider keys pass by design.
- _PROVIDER: "fake-openai_api_key", "HERMES_COMPUTE_HOST_HEARTBEAT_SECS": "15"}
+ _PROVIDER: "fake-openai_api_key", **own}
@pytest.mark.platforms("posix") # the stand-in binaries are shebang scripts
diff --git a/website/docs/user-guide/features/memory-providers.md b/website/docs/user-guide/features/memory-providers.md
index a2762cacd8e..beae77ee8ab 100644
--- a/website/docs/user-guide/features/memory-providers.md
+++ b/website/docs/user-guide/features/memory-providers.md
@@ -323,6 +323,12 @@ OpenViking server settings live in `ov.conf` (`--config`,
live in `ovcli.conf` (`OPENVIKING_CLI_CONFIG_FILE` or
`~/.openviking/ovcli.conf`).
+When the endpoint is local and nothing is listening, Hermes starts
+`openviking-server` in the background. That server gets your model-provider
+keys (for its embedding and VLM models), your `HOME` and
+`OPENVIKING_CONFIG_FILE`, but never bot, gateway or relay tokens, and not
+Hermes's `PYTHONPATH`. Put anything else the server needs in `ov.conf`.
+
**Key features:**
- Tiered context loading: L0 (~100 tokens) → L1 (~2k) → L2 (full)
- Automatic memory extraction on session commit (profile, preferences, entities, events, cases, patterns)
diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/memory-providers.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/memory-providers.md
index 0f308b59f27..c5b92400366 100644
--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/memory-providers.md
+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/memory-providers.md
@@ -287,6 +287,8 @@ hermes config set memory.provider openviking
echo "OPENVIKING_ENDPOINT=http://localhost:1933" >> ~/.hermes/.env
```
+当端点为本地地址且没有进程在监听时,Hermes 会在后台启动 `openviking-server`。该服务器会获得你的模型提供商密钥(供其嵌入和 VLM 模型使用)、你的 `HOME` 与 `OPENVIKING_CONFIG_FILE`,但绝不会获得机器人、网关或中继令牌,也不会获得 Hermes 的 `PYTHONPATH`。服务器需要的其他设置请写入 `ov.conf`。
+
**主要特性:**
- 分层上下文加载:L0(约 100 tokens)→ L1(约 2k)→ L2(完整)
- 会话提交时自动提取记忆(profile、偏好、实体、事件、案例、模式)