Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(search): return 404 for missing grep URI (#1696)

Qin Haojie08d7e87f0d3d
diff --git a/openviking/server/routers/search.py b/openviking/server/routers/search.py
index 48389f306..5c21f41bc 100644
--- a/openviking/server/routers/search.py
+++ b/openviking/server/routers/search.py
@@ -11,6 +11,7 @@ from pydantic import BaseModel
from openviking.pyagfs.exceptions import AGFSClientError, AGFSNotFoundError
from openviking.server.auth import get_request_context
from openviking.server.dependencies import get_service
+from openviking.server.error_mapping import map_exception
from openviking.server.identity import RequestContext
from openviking.server.models import Response
from openviking.server.telemetry import run_operation
@@ -219,6 +220,11 @@ async def grep(
if "not found" in err_msg or "no such file or directory" in err_msg:
raise NotFoundError(request.uri, "file")
raise
+ except Exception as exc:
+ mapped = map_exception(exc, resource=request.uri, resource_type="file")
+ if mapped is not None:
+ raise mapped from exc
+ raise
return Response(status="ok", result=result)
diff --git a/openviking/storage/viking_fs.py b/openviking/storage/viking_fs.py
index e8454443d..b41c92902 100644
--- a/openviking/storage/viking_fs.py
+++ b/openviking/storage/viking_fs.py
@@ -624,6 +624,7 @@ class VikingFS:
ctx: Request context
"""
self._ensure_access(uri, ctx)
+ await self.stat(uri, ctx=ctx)
flags = re.IGNORECASE if case_insensitive else 0
compiled_pattern = re.compile(pattern, flags)
diff --git a/tests/server/test_api_search.py b/tests/server/test_api_search.py
index abca6ec4d..246f3e0fe 100644
--- a/tests/server/test_api_search.py
+++ b/tests/server/test_api_search.py
@@ -398,6 +398,19 @@ async def test_grep_case_insensitive(client_with_resource):
assert resp.json()["status"] == "ok"
+async def test_grep_missing_uri_returns_not_found(client: httpx.AsyncClient):
+ resp = await client.post(
+ "/api/v1/search/grep",
+ json={
+ "uri": "viking://resources/nonexistent_grep_test_xyz",
+ "pattern": "test",
+ },
+ )
+
+ assert resp.status_code == 404
+ assert resp.json()["status"] == "error"
+
+
async def test_grep_exclude_uri_excludes_specific_uri_range(
client: httpx.AsyncClient,
upload_temp_dir,