OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: GET /api/v1/fs/stat rejects vector record IDs (URI must start with 'viking://')

Open aduoge opened this issue 1 month ago • 1 comments

Issue Origin

Observed or reproduced in a real environment

Bug Description

GET /api/v1/fs/stat rejects a vector record ID with INVALID_ARGUMENT: URI must start with 'viking://', although the docs (docs/en/api/03-filesystem.md) and the router accept a 32-character hex record ID. GET /api/v1/content/read with the same ID works.

The router keeps the ID unchanged (is_vector_record_id branch in openviking/server/routers/filesystem.py), but FSService.stat calls namespace_policy_for_uri(uri) before VikingFS.stat resolves the ID. namespace_policy_for_uri → is_system_uri → uri_parts, and uri_parts raises ValueError("URI must start with 'viking://'") for a bare ID.

tests/server/test_filesystem_router.py::test_http_stat_by_record_id_returns_resolved_uri replaces service.fs.stat with a fake, so the service-level path is not covered.

Steps to Reproduce

  1. Start a local server (local embedding, no VLM is enough) and add any file, e.g. ov add-resource ./payment-api.md --to viking://resources/payment-demo --wait.
  2. curl "http://127.0.0.1:1933/api/v1/fs/stat?uri=viking://resources/payment-demo/payment-api.md" → returns "id": "56a9e047479a5d538cbf0f1190febee7".
  3. curl "http://127.0.0.1:1933/api/v1/content/read?uri=56a9e047479a5d538cbf0f1190febee7" → 200, file content.
  4. curl "http://127.0.0.1:1933/api/v1/fs/stat?uri=56a9e047479a5d538cbf0f1190febee7" → error below.

Expected Behavior

stat resolves the record ID and returns the file metadata with the canonical viking:// URI, the same way read does.

Actual Behavior

{"status":"error","result":null,"error":{"code":"INVALID_ARGUMENT","message":"URI must start with 'viking://'","details":{"resource":"56a9e047479a5d538cbf0f1190febee7"}}}

Minimal Reproducible Example

Against current main (012e1f0) source, with a stub VikingFS:

import asyncio
from openviking.service.fs_service import FSService

ID = "56a9e047479a5d538cbf0f1190febee7"

class StubVikingFS:
    async def stat(self, uri, **kwargs):
        return {"uri": "viking://resources/demo/a.md", "id": ID}

svc = FSService.__new__(FSService)
svc._ensure_initialized = lambda: StubVikingFS()
asyncio.run(svc.stat("viking://resources/demo/a.md", ctx=None))  # ok
asyncio.run(svc.stat(ID, ctx=None))  # ValueError: URI must start with 'viking://'

A possible fix is to resolve the ID (viking_fs.resolve_uri) before computing the namespace policy in FSService.stat; I have not opened a PR for it yet.

Related: #6857 (Go/TypeScript SDKs now pass record IDs through to read/stat).

OpenViking Version

0.5.2.1 (PyPI) for the HTTP reproduction; the service-level reproduction above uses main@012e1f0

Python Version

3.13.15

Operating System

Linux

Model Backend

Local embedding (bge-small-zh-v1.5-f16), no VLM

aduoge avatar Nov 01 '26 11:11 aduoge

Hi, I'd like to take this one. The root cause analysis is spot on: FSService.stat unconditionally calls namespace_policy_for_uri(uri) before VikingFS.stat gets a chance to resolve a vector record ID, and uri_parts rejects the bare hex ID.

Plan: mirror the read path's record-ID handling in FSService.stat — resolve/defer the policy lookup until the URI is canonical (same as content/read does), and add a service-level regression test with a stub VikingFS (the existing router-level test fakes the service and misses this path). PR to follow.

lester076 avatar Nov 01 '26 12:11 lester076