Skip to content

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

fix: 兼容索引 ACL 列表中的空字符串 (#6067)

chuanbao666ae1e45e00539
diff --git a/openviking/storage/acl.py b/openviking/storage/acl.py
index a097df747..129608b79 100644
--- a/openviking/storage/acl.py
+++ b/openviking/storage/acl.py
@@ -116,6 +116,9 @@ class DirectAcl:
raw_grants = record.get(f"{prefix}_grants") or []
if not isinstance(raw_grants, (list, tuple)):
raise RuntimeError(f"Invalid ACL grants for {prefix}: expected a list")
+ # ponytail: 兼容离线索引将空 ACL list 还原为空字符串元素;只忽略精确空串,
+ # 其他非法 token 仍由 _decode_grant 拒绝。底层稳定保留 [] 后应删除。
+ raw_grants = [grant for grant in raw_grants if grant != ""]
return cls.from_entries(_decode_grant(grant) for grant in raw_grants)
diff --git a/tests/storage/test_acl.py b/tests/storage/test_acl.py
new file mode 100644
index 000000000..2fe13764f
--- /dev/null
+++ b/tests/storage/test_acl.py
@@ -0,0 +1,58 @@
+import pytest
+
+from openviking.storage.acl import AclLevel, DirectAcl
+
+
+ "raw_grants",
+ [
+ [],
+ [""],
+ ["", ""],
+ ("", ""),
+ ],
+)
+def test_context_fields_ignore_empty_grants(raw_grants):
+ acl = DirectAcl.from_context_fields(
+ {"acl_direct_grants": raw_grants},
+ "acl_direct",
+ )
+
+ assert acl.empty
+ assert acl.entries == ()
+
+
+def test_context_fields_ignore_empty_grants_beside_valid_grants():
+ acl = DirectAcl.from_context_fields(
+ {"acl_inherited_grants": ["", "3:user:alice", ""]},
+ "acl_inherited",
+ )
+
+ assert len(acl.entries) == 1
+ assert acl.entries[0].principal == "user:alice"
+ assert acl.entries[0].level == AclLevel.WRITE
+
+
+ "raw_grants",
+ [
+ [" "],
+ ["invalid"],
+ ["", "invalid"],
+ ["", 1],
+ ],
+)
+def test_context_fields_reject_nonempty_invalid_grants(raw_grants):
+ with pytest.raises(RuntimeError, match="Invalid ACL grant token"):
+ DirectAcl.from_context_fields(
+ {"acl_direct_grants": raw_grants},
+ "acl_direct",
+ )
+
+
+def test_context_fields_reject_nonlist_grants():
+ with pytest.raises(RuntimeError, match="expected a list"):
+ DirectAcl.from_context_fields(
+ {"acl_direct_grants": "3:user:alice"},
+ "acl_direct",
+ )