Skip to content

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

fix(grep): propagate later-page ACL denials (#5289)

Lusen Dongaa7a2023121b
diff --git a/openviking/storage/viking_fs/_grep.py b/openviking/storage/viking_fs/_grep.py
index 26a698c70..ba8f503f3 100644
--- a/openviking/storage/viking_fs/_grep.py
+++ b/openviking/storage/viking_fs/_grep.py
@@ -752,7 +752,11 @@ class _GrepMixin:
ctx=ctx,
)
except PermissionDeniedError:
- if current_depth == 0:
+ # A denial on the first page means this child subtree is
+ # no longer visible and can be skipped. Once traversal has
+ # consumed a page, swallowing the error would misreport a
+ # partial result as complete.
+ if current_depth == 0 or offset > 0:
raise
logger.debug(
f"Skipping inaccessible directory during grep: {normalized_current_uri}"
diff --git a/tests/storage/test_viking_fs_grep.py b/tests/storage/test_viking_fs_grep.py
index a4ae3cdf9..280aa2944 100644
--- a/tests/storage/test_viking_fs_grep.py
+++ b/tests/storage/test_viking_fs_grep.py
@@ -246,6 +246,28 @@ async def test_collect_grep_files_propagates_later_page_failure(monkeypatch):
)
+async def test_collect_grep_files_propagates_later_page_acl_denial(monkeypatch):
+ viking_fs = VikingFS(agfs=_DummyAgfs())
+
+ async def fake_ls(uri, node_limit, offset, ctx=None):
+ if uri == "viking://resources":
+ return [{"name": "child", "isDir": True}]
+ if offset:
+ raise PermissionDeniedError("access revoked", resource=uri)
+ return [{"name": f"file_{index:04d}.md", "isDir": False} for index in range(node_limit)]
+
+ monkeypatch.setattr(viking_fs, "stat", AsyncMock(return_value={"isDir": True}))
+ monkeypatch.setattr(viking_fs, "ls", fake_ls)
+
+ with pytest.raises(PermissionDeniedError, match="access revoked"):
+ await viking_fs._collect_grep_files(
+ "viking://resources",
+ excluded_prefix=None,
+ level_limit=1,
+ )
+
+
@pytest.mark.asyncio
async def test_collect_grep_files_propagates_root_stat_failure(monkeypatch):
viking_fs = VikingFS(agfs=_DummyAgfs())