OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: OpenVikingStore rejects slash-containing LangGraph keys

Open Mchenr opened this issue 3 months ago • 1 comments

Issue Origin

Observed or reproduced in a real environment

Bug Description

OpenVikingStore percent-encodes a LangGraph store key as one URI segment. Filesystem-style backends such as Deep Agents use virtual absolute paths as keys, so /AGENTS.md becomes %2FAGENTS.md. The OpenViking server rejects that URI with Unsafe relative path rejected, preventing direct use of langchain-openviking as a persistent Deep Agents store.

Steps to Reproduce

  1. Start an OpenViking server.
  2. Install and configure langchain-openviking.
  3. Run:
from langchain_openviking import OpenVikingStore

store = OpenVikingStore(url="http://127.0.0.1:1933")
store.put(
    ("filesystem", "user-a"),
    "/AGENTS.md",
    {"content": "Persistent agent instructions"},
)
  1. Observe that the adapter sends a data URI ending in /data/filesystem/user-a/%2FAGENTS.md.json and the server rejects it.

Expected Behavior

Slash-containing keys should round-trip through put, get, search, list_namespaces, and delete without sending encoded path separators to OpenViking. Keys without slashes should keep their current URI layout.

Actual Behavior

The leading slash is encoded as %2F inside one URI segment. OpenViking's URI safety validation rejects the request with Unsafe relative path rejected.

Minimal Reproducible Example

from langchain_openviking import OpenVikingStore

store = OpenVikingStore(url="http://127.0.0.1:1933")
store.put(("filesystem", "user-a"), "/AGENTS.md", {"content": "hello"})

Error Logs

Unsafe relative path rejected

OpenViking Version

main @ 3964d8685c8e35ca778abacdce2b76dc295e1a2c

Python Version

3.11

Operating System

Linux

Model Backend

None

Additional Context

Proposed adapter mapping:

/AGENTS.md       -> .../__openviking_path_key_v1__/abs/AGENTS.md.json
/docs/readme.md  -> .../__openviking_path_key_v1__/abs/docs/readme.md.json
notes/todo.md    -> .../__openviking_path_key_v1__/rel/notes/todo.md.json

This keeps ordinary keys unchanged, represents separators as real URI hierarchy, reconstructs the original key during list/search, and permits legacy percent-encoded read/delete fallback. Ambiguous non-canonical paths can be rejected at the adapter boundary.

I have implemented this with round-trip, semantic-search, namespace-listing, deletion, validation, and legacy-read tests, and will open a linked PR.

Mchenr avatar Aug 26 '26 02:08 Mchenr

I traced this to the exact line and I think the server is right, so the whole fix belongs in the adapter. Before writing it I would rather you pick the encoding than have me guess, because it is a wire format and the wrong choice is expensive to undo.

Why the server rejects it

openviking/utils/path_safety.py:

decoded = unquote(segment)
if decoded != segment and (decoded in {".", ".."} or "/" in decoded or "\\" in decoded):
    raise ValueError(f"Unsafe relative path rejected: {path}")

Checked against the reported key:

key '/AGENTS.md'  ->  _segment()  ->  '%2FAGENTS.md'
                      unquote     ->  '/AGENTS.md'
                      decoded != segment: True, contains '/': True  ->  rejected

That guard is deliberate and I would not touch it: an encoded separator must not be able to create a new path segment. The bug is that _segment in integrations/langchain/src/langchain_openviking/store.py is quote(value, safe=""), which turns a key separator into exactly the thing the guard exists to stop.

Two encodings, and one property that decides it

A — the sentinel directory from the issue. /AGENTS.md becomes .../__openviking_path_key_v1__/abs/AGENTS.md.json, so a key with slashes maps onto real directories.

  • Readable in a file browser, and the version tag leaves room to change it later.
  • A key becomes more than one path segment, so _parse_record_uri has to learn where a namespace stops and a key begins. list_namespaces walks those same URIs, so __openviking_path_key_v1__ has to be filtered out of every namespace result or it shows up as a namespace of its own.
  • The sentinel is a literal name. A key that legitimately contains __openviking_path_key_v1__ collides.

B — escape the separator inside the one segment. The key stays one segment; only the separator changes shape:

key without '/' or '\'   ->  quote(key, safe="")            # byte-identical to today
key with a separator     ->  "!" + quote(key, safe="") with %2F -> !s and %5C -> !b

The property that makes this safe is that quote always escapes !:

'!' -> '%21'      '~' -> '~'       '/' -> '%2F'
'%' -> '%25'      '.' -> '.'       '\' -> '%5C'

So a bare ! cannot occur in anything the current encoder produces, which means the marker cannot be confused with existing data and a literal ! in a key is still %21. And unquote("!sAGENTS.md") returns itself, so the guard never fires.

  • No URI changes for any key that works today — the issue's "keys without slashes should keep their current URI layout" holds literally, not approximately.
  • Keys containing separators could never be stored before, so there is no old data in the escaped form to collide with.
  • _parse_record_uri and list_namespaces are untouched: still one segment per namespace element, one for the key.
  • Less readable in a file browser. !s means nothing to a human reading the tree.

What I would do

I lean to B, mostly because it keeps list_namespaces out of it — that is where A's cost lands, and a namespace listing that silently grows a __openviking_path_key_v1__ entry is the kind of bug that surfaces long after the change.

But readability is a real argument for A, and the versioned name is a real argument too. Say which one you want and I will send it with round-trip coverage for put, get, search, list_namespaces and delete, including a key that is exactly /, one with a trailing slash, and one containing the marker itself.

ntdat812 avatar Aug 27 '26 07:08 ntdat812