OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: MemorySearchTool passes ToolContext to viking_fs.search

Open ehz0ah opened this issue 7 months ago • 1 comments

Bug Description

MemorySearchTool.execute forwards ToolContext into viking_fs.search, but viking_fs.search expects RequestContext and accesses namespace_policy while canonicalizing and access-checking scoped URIs. In session memory extraction and prefetch flows this raises an attribute error and the search step falls back to a degraded read-only path.

Steps to Reproduce

  1. Use OpenViking through the Hermes HTTP integration so session commit triggers OpenViking memory extraction.
  2. Hit a flow that performs directory-scoped memory search via MemorySearchTool, for example the extraction prefetch path with default_search_uris.
  3. MemorySearchTool calls viking_fs.search(ctx=ToolContext).
  4. viking_fs.search reaches namespace handling and tries to read ctx.namespace_policy.

Expected Behavior

MemorySearchTool should unwrap ToolContext and pass ctx.request_ctx into viking_fs.search while preserving ctx.default_search_uris for target scoping.

Actual Behavior

The search step fails with an attribute error similar to:

'ToolContext' object has no attribute 'namespace_policy'

This can surface in customer-visible memory artifacts as a message like:

search 工具出现 namespace_policy 属性错误 → 停止重试并改用已知 URI 的 read

Minimal Reproducible Example

from openviking.server.identity import RequestContext, Role, ToolContext
from openviking.session.memory.tools import MemorySearchTool
from openviking_cli.session.user_id import UserIdentifier

request_ctx = RequestContext(
    user=UserIdentifier("test-account", "test-user", "test-agent"),
    role=Role.USER,
)
tool_ctx = ToolContext(
    request_ctx=request_ctx,
    default_search_uris=["viking://user/test-account/test-user/memories"],
)

await MemorySearchTool().execute(viking_fs, tool_ctx, query="profile", limit=2)

Error Logs

AttributeError: 'ToolContext' object has no attribute 'namespace_policy'

OpenViking Version

main

Python Version

3.13.12

Operating System

macOS

Model Backend

Other

Additional Context

Relevant code paths:

  • openviking/session/memory/tools.py forwards the wrong context type
  • openviking/storage/viking_fs.py search expects RequestContext
  • openviking/server/identity.py defines ToolContext as a wrapper around request_ctx

A fix branch with regression coverage is ready and linked from the draft PR.

ehz0ah avatar Apr 28 '26 09:04 ehz0ah

Draft fix PR opened: #1777

This PR contains the minimal production fix plus a regression test that reproduces the ToolContext vs RequestContext mismatch.

ehz0ah avatar Apr 28 '26 10:04 ehz0ah