fix(memory): migrate OpenViking URIs to the viking://~ home alias
Upstream OpenViking removed the uid-less viking://user/<segment> shorthand (#4196, merged 2026-08-21): reserved segments like memories and peers no longer expand to the caller's space and the server rejects them with HTTP 400 (NamespaceShapeError). First-party clients were migrated to viking://~ in the same change; the Hermes plugin was not (#91995). Migrate every URI the plugin constructs — the profile/preferences/ entities session-start reads, the _build_memory_uri memory-mirroring write path, and the tool-schema example — to viking://~/... README uid-less references updated to match; canonical user-scoped forms (viking://user/default/...) are unchanged. The ~ alias requires OpenViking server >= 0.4.16 (#4167).
This commit is contained in:
@@ -94,8 +94,8 @@ Hermes sends `OPENVIKING_ACCOUNT` and `OPENVIKING_USER` as identity headers.
|
||||
|
||||
`viking_remember` writes directly to OpenViking with `POST /api/v1/content/write`
|
||||
and `mode=create`. It creates peer-scoped memory files under
|
||||
`viking://user/peers/${OPENVIKING_AGENT}/memories/...`; OpenViking may return a
|
||||
canonical user-scoped form such as
|
||||
`viking://~/peers/${OPENVIKING_AGENT}/memories/...` (`~` is the current-user
|
||||
home alias); OpenViking may return a canonical user-scoped form such as
|
||||
`viking://user/default/peers/${OPENVIKING_AGENT}/memories/...` in API-key mode.
|
||||
Explicit remembers do not depend on session commit extraction.
|
||||
|
||||
@@ -113,7 +113,7 @@ memory URI.
|
||||
|
||||
`viking_forget` is intentionally narrow. It only accepts concrete user memory
|
||||
file URIs, such as
|
||||
`viking://user/peers/hermes/memories/preferences/mem_abc123.md` or the canonical
|
||||
`viking://~/peers/hermes/memories/preferences/mem_abc123.md` or the canonical
|
||||
`viking://user/default/peers/hermes/memories/preferences/mem_abc123.md`. Files
|
||||
directly under `memories/`, such as `viking://user/default/memories/profile.md`,
|
||||
are also allowed because OpenViking supports them. The tool rejects directories,
|
||||
|
||||
@@ -93,9 +93,13 @@ _RECALL_QUERY_MIN_CHARS = 5
|
||||
_RECALL_MIN_TIMEOUT_SECONDS = 0.05
|
||||
_READ_BATCH_LIMIT = 3
|
||||
_READ_BATCH_FULL_LIMIT = 2500
|
||||
_PROFILE_URI = "viking://user/memories/profile.md"
|
||||
_PREFERENCES_URI = "viking://user/memories/preferences"
|
||||
_ENTITIES_URI = "viking://user/memories/entities"
|
||||
# `viking://~` is the current-user home alias (OpenViking #4167, server 0.4.16+).
|
||||
# The uid-less `viking://user/<segment>` shorthand was removed upstream (#4196,
|
||||
# 2026-08-21): reserved segments like `memories`/`peers` no longer expand to the
|
||||
# caller's space and the server rejects them with HTTP 400.
|
||||
_PROFILE_URI = "viking://~/memories/profile.md"
|
||||
_PREFERENCES_URI = "viking://~/memories/preferences"
|
||||
_ENTITIES_URI = "viking://~/memories/entities"
|
||||
_SESSION_START_LIST_PARAMS = {
|
||||
"output": "agent",
|
||||
"recursive": True,
|
||||
@@ -573,7 +577,7 @@ BROWSE_SCHEMA = {
|
||||
},
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "Viking URI path (default: viking://). Examples: 'viking://resources/', 'viking://user/memories/'.",
|
||||
"description": "Viking URI path (default: viking://). Examples: 'viking://resources/', 'viking://~/memories/'.",
|
||||
},
|
||||
},
|
||||
"required": ["action"],
|
||||
@@ -4779,7 +4783,9 @@ class OpenVikingMemoryProvider(MemoryProvider):
|
||||
def _build_memory_uri(self, subdir: str) -> str:
|
||||
"""Build a viking:// memory URI under the configured peer namespace."""
|
||||
slug = uuid.uuid4().hex[:12]
|
||||
return f"viking://user/peers/{self._agent}/memories/{subdir}/mem_{slug}.md"
|
||||
# `~` home alias: `viking://user/peers/...` is uid-less and was removed
|
||||
# upstream (#4196) — the memory-mirroring write path 400s on new servers.
|
||||
return f"viking://~/peers/{self._agent}/memories/{subdir}/mem_{slug}.md"
|
||||
|
||||
def on_memory_write(
|
||||
self,
|
||||
|
||||
@@ -657,7 +657,7 @@ class TestOpenVikingAutoRecallPrefetch:
|
||||
if parsed.path == "/api/v1/content/read":
|
||||
query = parse_qs(parsed.query)
|
||||
uri = query.get("uri", [""])[0]
|
||||
if uri == "viking://user/memories/profile.md":
|
||||
if uri == "viking://~/memories/profile.md":
|
||||
self._send_json({"result": "E2E user profile."})
|
||||
return
|
||||
records["reads"].append(uri)
|
||||
@@ -667,7 +667,7 @@ class TestOpenVikingAutoRecallPrefetch:
|
||||
query = {key: values[0] for key, values in parse_qs(parsed.query).items()}
|
||||
records["listings"].append(query)
|
||||
uri = query.get("uri")
|
||||
if uri == "viking://user/memories/preferences":
|
||||
if uri == "viking://~/memories/preferences":
|
||||
self._send_json({
|
||||
"result": [
|
||||
{"isDir": True, "rel_path": "owner", "abstract": "ignored"},
|
||||
@@ -679,7 +679,7 @@ class TestOpenVikingAutoRecallPrefetch:
|
||||
]
|
||||
})
|
||||
return
|
||||
if uri == "viking://user/memories/entities":
|
||||
if uri == "viking://~/memories/entities":
|
||||
self._send_json({
|
||||
"result": [
|
||||
{
|
||||
@@ -758,8 +758,8 @@ class TestOpenVikingAutoRecallPrefetch:
|
||||
assert "E2E abstract should not be injected." not in block
|
||||
assert records["reads"] == ["viking://user/peers/hermes/memories/e2e-full.md"]
|
||||
assert [listing["uri"] for listing in records["listings"]] == [
|
||||
"viking://user/memories/preferences",
|
||||
"viking://user/memories/entities",
|
||||
"viking://~/memories/preferences",
|
||||
"viking://~/memories/entities",
|
||||
]
|
||||
assert all(listing["output"] == "agent" for listing in records["listings"])
|
||||
assert all(listing["recursive"].lower() == "true" for listing in records["listings"])
|
||||
@@ -818,7 +818,7 @@ class TestOpenVikingMemoryUriBuilder:
|
||||
"""Regression tests for _build_memory_uri — fixes #36969.
|
||||
|
||||
OpenViking's current memory layout stores peer-scoped memories under
|
||||
viking://user/peers/{peer_id}/...
|
||||
viking://~/peers/{peer_id}/...
|
||||
"""
|
||||
|
||||
def _make_provider(self, user="alice", agent="coder"):
|
||||
@@ -831,7 +831,7 @@ class TestOpenVikingMemoryUriBuilder:
|
||||
"""URI must contain /peers/{peer_id}/ between user and memories."""
|
||||
p = self._make_provider(user="alice", agent="coder")
|
||||
uri = p._build_memory_uri("preferences")
|
||||
assert uri.startswith("viking://user/peers/coder/memories/preferences/mem_")
|
||||
assert uri.startswith("viking://~/peers/coder/memories/preferences/mem_")
|
||||
assert uri.endswith(".md")
|
||||
|
||||
|
||||
@@ -921,7 +921,7 @@ class TestEnsureClientReloadsEnv:
|
||||
assert instances[1].posts[0][1]["content"] == "stable fact"
|
||||
assert instances[1].posts[0][1]["mode"] == "create"
|
||||
assert instances[1].posts[0][1]["uri"].startswith(
|
||||
"viking://user/peers/hermes/memories/"
|
||||
"viking://~/peers/hermes/memories/"
|
||||
)
|
||||
|
||||
def test_concurrent_refresh_does_not_return_stale_client(self, monkeypatch):
|
||||
|
||||
@@ -753,18 +753,18 @@ def test_viking_client_delete_uses_identity_headers(monkeypatch):
|
||||
return SimpleNamespace(
|
||||
status_code=200,
|
||||
text="",
|
||||
json=lambda: {"status": "ok", "result": {"uri": "viking://user/memories/x.md"}},
|
||||
json=lambda: {"status": "ok", "result": {"uri": "viking://~/memories/x.md"}},
|
||||
raise_for_status=lambda: None,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(client._httpx, "delete", capture_delete)
|
||||
|
||||
assert client.delete("/api/v1/fs", params={"uri": "viking://user/memories/x.md"}) == {
|
||||
assert client.delete("/api/v1/fs", params={"uri": "viking://~/memories/x.md"}) == {
|
||||
"status": "ok",
|
||||
"result": {"uri": "viking://user/memories/x.md"},
|
||||
"result": {"uri": "viking://~/memories/x.md"},
|
||||
}
|
||||
assert captured["url"] == "https://example.com/api/v1/fs"
|
||||
assert captured["kwargs"]["params"] == {"uri": "viking://user/memories/x.md"}
|
||||
assert captured["kwargs"]["params"] == {"uri": "viking://~/memories/x.md"}
|
||||
assert captured["kwargs"]["headers"]["Authorization"] == "Bearer test-key"
|
||||
assert captured["kwargs"]["headers"]["X-OpenViking-Actor-Peer"] == "hermes"
|
||||
|
||||
@@ -1369,10 +1369,10 @@ def test_prefetch_prepends_session_start_memory_context_once_per_session():
|
||||
calls = _mock_session_start_reads(
|
||||
provider,
|
||||
{
|
||||
("/api/v1/content/read", "viking://user/memories/profile.md"): (
|
||||
("/api/v1/content/read", "viking://~/memories/profile.md"): (
|
||||
"User prefers concise answers."
|
||||
),
|
||||
("/api/v1/fs/ls", "viking://user/memories/preferences"): _memory_listing(
|
||||
("/api/v1/fs/ls", "viking://~/memories/preferences"): _memory_listing(
|
||||
{"isDir": True, "rel_path": "owner"},
|
||||
{
|
||||
"isDir": False,
|
||||
@@ -1386,7 +1386,7 @@ def test_prefetch_prepends_session_start_memory_context_once_per_session():
|
||||
},
|
||||
{"isDir": False, "rel_path": "owner/ignored.txt", "abstract": "ignore"},
|
||||
),
|
||||
("/api/v1/fs/ls", "viking://user/memories/entities"): _memory_listing(
|
||||
("/api/v1/fs/ls", "viking://~/memories/entities"): _memory_listing(
|
||||
{
|
||||
"isDir": False,
|
||||
"rel_path": "people/ada.md",
|
||||
@@ -1400,13 +1400,13 @@ def test_prefetch_prepends_session_start_memory_context_once_per_session():
|
||||
first = provider.prefetch("What should we recall?", session_id="sid-123")
|
||||
second = provider.prefetch("What should we recall?", session_id="sid-123")
|
||||
|
||||
assert '<user-profile uri="viking://user/memories/profile.md">' in first
|
||||
assert '<user-profile uri="viking://~/memories/profile.md">' in first
|
||||
assert "User prefers concise answers." in first
|
||||
assert "<available-memories>" in first
|
||||
assert "viking://user/memories/preferences/" in first
|
||||
assert "viking://~/memories/preferences/" in first
|
||||
assert "owner/z-last.md — Keep replies compact." in first
|
||||
assert first.index("owner/a-first.md") < first.index("owner/z-last.md")
|
||||
assert "viking://user/memories/entities/" in first
|
||||
assert "viking://~/memories/entities/" in first
|
||||
assert "people/ada.md — Ada Lovelace is a collaborator." in first
|
||||
assert "owner/ignored.txt" not in first
|
||||
assert "<preferences" not in first
|
||||
@@ -1415,14 +1415,14 @@ def test_prefetch_prepends_session_start_memory_context_once_per_session():
|
||||
assert "<user-profile" not in second
|
||||
assert "recalled context" in second
|
||||
assert [(path, params) for path, params, _timeout in calls] == [
|
||||
("/api/v1/content/read", {"uri": "viking://user/memories/profile.md"}),
|
||||
("/api/v1/content/read", {"uri": "viking://~/memories/profile.md"}),
|
||||
(
|
||||
"/api/v1/fs/ls",
|
||||
{"uri": "viking://user/memories/preferences", **_SESSION_START_LIST_PARAMS},
|
||||
{"uri": "viking://~/memories/preferences", **_SESSION_START_LIST_PARAMS},
|
||||
),
|
||||
(
|
||||
"/api/v1/fs/ls",
|
||||
{"uri": "viking://user/memories/entities", **_SESSION_START_LIST_PARAMS},
|
||||
{"uri": "viking://~/memories/entities", **_SESSION_START_LIST_PARAMS},
|
||||
),
|
||||
]
|
||||
assert provider._search_prefetch_context.call_count == 2
|
||||
@@ -1435,7 +1435,7 @@ def test_prefetch_reinjects_after_in_place_compression_same_session():
|
||||
|
||||
def fake_get(path, params=None, **kwargs):
|
||||
uri = (params or {}).get("uri", "")
|
||||
if uri == "viking://user/memories/profile.md":
|
||||
if uri == "viking://~/memories/profile.md":
|
||||
return {"result": next(profiles)}
|
||||
return {"result": []}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user