Skip to content

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

Fix temp cleanup for repository tasks directories (#3630)

zgy48559ab4f16d
diff --git a/openviking/storage/viking_fs.py b/openviking/storage/viking_fs.py
index 00c9ea331..030272a8e 100644
--- a/openviking/storage/viking_fs.py
+++ b/openviking/storage/viking_fs.py
@@ -3635,16 +3635,7 @@ class VikingFS:
path = self._uri_to_path(temp_uri, ctx=ctx)
fs_ctx = self._pathlock_fs_ctx(ctx, lease_ref)
try:
- for entry in await self._ls_entries(path, ctx=ctx):
- name = entry.get("name", "")
- if name in [".", ".."]:
- continue
- entry_path = f"{path}/{name}"
- if entry.get("isDir"):
- await self.delete_temp(f"{temp_uri}/{name}", ctx=ctx, lease_ref=lease_ref)
- else:
- await self._async_agfs.rm(entry_path, fs_ctx=fs_ctx)
- await self._async_agfs.rm(path, fs_ctx=fs_ctx)
+ await self._async_agfs.rm(path, recursive=True, fs_ctx=fs_ctx)
except Exception as e:
logger.warning(f"[VikingFS] Failed to delete temp {temp_uri}: {e}")
diff --git a/tests/server/test_temp_scope_acl.py b/tests/server/test_temp_scope_acl.py
index c30e9708c..6dab96e35 100644
--- a/tests/server/test_temp_scope_acl.py
+++ b/tests/server/test_temp_scope_acl.py
@@ -9,6 +9,7 @@ import pytest
from openviking.server.identity import RequestContext, Role
from openviking.storage.viking_fs import VikingFS
+from openviking_cli.exceptions import NotFoundError
from openviking_cli.session.user_id import UserIdentifier
@@ -207,6 +208,24 @@ async def test_temp_root_destructive_operations_are_blocked_for_non_root_users(v
await viking_fs.delete_temp("viking://temp", ctx=alice_ctx)
+async def test_delete_temp_removes_repository_tasks_directory(viking_fs):
+ ctx = RequestContext(
+ user=UserIdentifier(account_id="acct1", user_id="alice"),
+ role=Role.ROOT,
+ )
+ temp_uri = viking_fs.create_temp_uri(ctx=ctx)
+ tasks_file_uri = f"{temp_uri}/repository/src/tasks/task-registry.ts"
+
+ await viking_fs.mkdir(f"{temp_uri}/repository/src/tasks", exist_ok=True, ctx=ctx)
+ await viking_fs.write(tasks_file_uri, "task registry", ctx=ctx)
+
+ await viking_fs.delete_temp(temp_uri, ctx=ctx)
+
+ with pytest.raises(NotFoundError):
+ await viking_fs.read(tasks_file_uri, ctx=ctx)
+
+
@pytest.mark.asyncio
async def test_legacy_temp_trees_remain_accessible_for_same_account_users(viking_fs):
alice_ctx = RequestContext(