Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(auth): align role serialization with string roles (#2728)
Zayn Jarvis79f7bdd18402
diff --git a/openviking/resource/watch_scheduler.py b/openviking/resource/watch_scheduler.pyindex 01f595352..d3aa26fdd 100644--- a/openviking/resource/watch_scheduler.py+++ b/openviking/resource/watch_scheduler.py@@ -239,7 +239,7 @@ class WatchScheduler:account_id=task.account_id,user_id=task.user_id,)- role_value = getattr(task, "original_role", None) or Role.USER.value+ role_value = getattr(task, "original_role", None) or str(Role.USER)try:role = Role(role_value)except Exception:@@ -312,7 +312,7 @@ class WatchScheduler:task_id=task.task_id,account_id=task.account_id,user_id=task.user_id,- role=getattr(task, "original_role", None) or Role.USER.value,+ role=getattr(task, "original_role", None) or str(Role.USER),is_active=False,))diff --git a/openviking/service/fs_service.py b/openviking/service/fs_service.pyindex 945b382d3..1bbcca7d2 100644--- a/openviking/service/fs_service.py+++ b/openviking/service/fs_service.py@@ -331,7 +331,7 @@ class FSService:account_id=ctx.account_id,user_id=ctx.user.user_id,peer_id=ctx.user.user_id,- role=ctx.role.value,+ role=str(ctx.role),skip_vectorization=False,telemetry_id=telemetry_id,coalesce_key=build_semantic_coalesce_key(diff --git a/openviking/service/reindex_executor.py b/openviking/service/reindex_executor.pyindex 199ec08b1..cbec3e912 100644--- a/openviking/service/reindex_executor.py+++ b/openviking/service/reindex_executor.py@@ -565,7 +565,7 @@ class ReindexExecutor:account_id=ctx.account_id,user_id=ctx.user.user_id,peer_id=ctx.user.user_id,- role=ctx.role.value,+ role=str(ctx.role),skip_vectorization=True,)await processor.on_dequeue({"data": msg.to_json()}, lock=lock.as_borrowed())diff --git a/openviking/service/resource_service.py b/openviking/service/resource_service.pyindex 81db4ee3b..3d6b5e0c7 100644--- a/openviking/service/resource_service.py+++ b/openviking/service/resource_service.py@@ -951,7 +951,7 @@ class ResourceService:to_uri=to_uri,account_id=ctx.account_id,user_id=ctx.user.user_id,- role=ctx.role.value,+ role=str(ctx.role),)if existing_task:if existing_task.is_active:@@ -964,7 +964,7 @@ class ResourceService:task_id=existing_task.task_id,account_id=ctx.account_id,user_id=ctx.user.user_id,- role=ctx.role.value,+ role=str(ctx.role),path=path,to_uri=to_uri,parent_uri=parent_uri,@@ -985,7 +985,7 @@ class ResourceService:path=path,account_id=ctx.account_id,user_id=ctx.user.user_id,- original_role=ctx.role.value,+ original_role=str(ctx.role),to_uri=to_uri,parent_uri=parent_uri,reason=reason,@@ -1013,14 +1013,14 @@ class ResourceService:to_uri=to_uri,account_id=ctx.account_id,user_id=ctx.user.user_id,- role=ctx.role.value,+ role=str(ctx.role),)if existing_task:await watch_manager.update_task(task_id=existing_task.task_id,account_id=ctx.account_id,user_id=ctx.user.user_id,- role=ctx.role.value,+ role=str(ctx.role),is_active=False,)logger.info(diff --git a/openviking/session/session.py b/openviking/session/session.pyindex c36c2b483..eb36ebb23 100644--- a/openviking/session/session.py+++ b/openviking/session/session.py@@ -1326,7 +1326,7 @@ class Session:"session_uri": self._session_uri,"account_id": self.ctx.account_id,"user_id": self.ctx.user.user_id,- "role": self.ctx.role.value,+ "role": str(self.ctx.role),},)diff --git a/openviking/storage/content_write.py b/openviking/storage/content_write.pyindex c46d26bc6..111627f3a 100644--- a/openviking/storage/content_write.py+++ b/openviking/storage/content_write.py@@ -466,7 +466,7 @@ class ContentWriteCoordinator:recursive=recursive,account_id=ctx.account_id,user_id=ctx.user.user_id,- role=ctx.role.value,+ role=str(ctx.role),skip_vectorization=False,telemetry_id=telemetry.telemetry_id,coalesce_key=(diff --git a/openviking/storage/queuefs/semantic_processor.py b/openviking/storage/queuefs/semantic_processor.pyindex 73f3f9dbd..7548c2477 100644--- a/openviking/storage/queuefs/semantic_processor.py+++ b/openviking/storage/queuefs/semantic_processor.py@@ -3,7 +3,6 @@"""SemanticProcessor: Processes messages from SemanticQueue, generates .abstract.md and .overview.md."""import asyncio-import jsonimport threadingfrom contextlib import nullcontextfrom dataclasses import dataclass, field@@ -13,6 +12,10 @@ from openviking.observability.context import (bind_root_observability_context,reset_root_observability_context,)+from openviking.parse.image_rewrite import (+ IMAGE_MAPPINGS_FILENAME,+ rewrite_image_uris,+)from openviking.parse.parsers.constants import (CODE_EXTENSIONS,DOCUMENTATION_EXTENSIONS,@@ -20,10 +23,6 @@ from openviking.parse.parsers.constants import (FILE_TYPE_DOCUMENTATION,FILE_TYPE_OTHER,)-from openviking.parse.image_rewrite import (- IMAGE_MAPPINGS_FILENAME,- rewrite_image_uris,-)from openviking.parse.parsers.media.utils import (generate_audio_summary,generate_image_summary,@@ -171,7 +170,7 @@ class SemanticProcessor(DequeueHandlerBase):@staticmethoddef _ctx_from_semantic_msg(msg: SemanticMsg) -> RequestContext:- role = Role(msg.role) if msg.role in {r.value for r in Role} else Role.ROOT+ role = Role(msg.role or Role.ROOT)return RequestContext(user=UserIdentifier(msg.account_id, msg.user_id),role=role,diff --git a/openviking/utils/summarizer.py b/openviking/utils/summarizer.pyindex 88051a85a..50afe9e77 100644--- a/openviking/utils/summarizer.py+++ b/openviking/utils/summarizer.py@@ -118,7 +118,7 @@ class Summarizer:account_id=ctx.account_id,user_id=ctx.user.user_id,peer_id=ctx.user.user_id,- role=ctx.role.value,+ role=str(ctx.role),skip_vectorization=skip_vectorization,telemetry_id=telemetry.telemetry_id,target_uri=target_uri if target_uri != source_uri else None,diff --git a/tests/integration/test_watch_e2e.py b/tests/integration/test_watch_e2e.pyindex 8bc8e23fe..f2eaad5fa 100644--- a/tests/integration/test_watch_e2e.py+++ b/tests/integration/test_watch_e2e.py@@ -23,7 +23,7 @@ async def get_watch_task(client: AsyncOpenViking, to_uri: str):to_uri=to_uri,account_id=client._service.user.account_id,user_id=client._service.user.user_id,- role=Role.USER.value,+ role=str(Role.USER),)diff --git a/tests/server/test_identity.py b/tests/server/test_identity.pyindex 77dae0f79..f412decf9 100644--- a/tests/server/test_identity.py+++ b/tests/server/test_identity.py@@ -12,10 +12,10 @@ from openviking_cli.session.user_id import UserIdentifierdef test_role_values():- """Role enum should have correct string values."""- assert Role.ROOT.value == "root"- assert Role.ADMIN.value == "admin"- assert Role.USER.value == "user"+ """Built-in roles should expose stable string values."""+ assert str(Role.ROOT) == "root"+ assert str(Role.ADMIN) == "admin"+ assert str(Role.USER) == "user"def test_role_from_string():@@ -25,6 +25,19 @@ def test_role_from_string():assert Role("user") == Role.USER+def test_custom_role_value():+ """Custom roles should behave like strings and support registered ranks."""+ role = Role("reviewer")+ assert str(role) == "reviewer"+ assert role == "reviewer"++ try:+ Role.register("reviewer", 1)+ assert Role("reviewer").rank == 1+ finally:+ Role._CUSTOM_RANK.pop("reviewer", None)++def test_resolved_identity_defaults():"""ResolvedIdentity optional fields should default to None."""identity = ResolvedIdentity(role=Role.ROOT)diff --git a/tests/service/test_resource_service_watch.py b/tests/service/test_resource_service_watch.pyindex 20ef4a150..613f4f328 100644--- a/tests/service/test_resource_service_watch.py+++ b/tests/service/test_resource_service_watch.py@@ -22,7 +22,7 @@ async def get_task_by_uri(service: ResourceService, to_uri: str, ctx: RequestConto_uri=to_uri,account_id=ctx.account_id,user_id=ctx.user.user_id,- role=ctx.role.value,+ role=str(ctx.role),)@@ -441,7 +441,7 @@ class TestWatchTaskConflict:task_id=task_id,account_id=request_context.account_id,user_id=request_context.user.user_id,- role=request_context.role.value,+ role=str(request_context.role),is_active=False,)@@ -590,7 +590,7 @@ class TestWatchTaskUpdate:task_id=task.task_id,account_id=request_context.account_id,user_id=request_context.user.user_id,- role=request_context.role.value,+ role=str(request_context.role),is_active=False,)diff --git a/tests/storage/test_semantic_processor_identity.py b/tests/storage/test_semantic_processor_identity.pynew file mode 100644index 000000000..2e8b766b1--- /dev/null+++ b/tests/storage/test_semantic_processor_identity.py@@ -0,0 +1,34 @@+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.+# SPDX-License-Identifier: Apache-2.0+"""Tests for SemanticProcessor identity reconstruction."""++from openviking.storage.queuefs.semantic_msg import SemanticMsg+from openviking.storage.queuefs.semantic_processor import SemanticProcessor+++def test_ctx_from_semantic_msg_preserves_custom_role():+ msg = SemanticMsg(+ uri="viking://resources/doc",+ context_type="resource",+ account_id="acme",+ user_id="alice",+ role="reviewer",+ )++ ctx = SemanticProcessor._ctx_from_semantic_msg(msg)++ assert ctx.account_id == "acme"+ assert ctx.user.user_id == "alice"+ assert str(ctx.role) == "reviewer"+++def test_ctx_from_semantic_msg_defaults_empty_role_to_root():+ msg = SemanticMsg(+ uri="viking://resources/doc",+ context_type="resource",+ role="",+ )++ ctx = SemanticProcessor._ctx_from_semantic_msg(msg)++ assert str(ctx.role) == "root"