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(resource): return from on_resource_added once the reason commit is queued (#6077)
马云祥0230cc104b7b
diff --git a/openviking/service/resource_memory_link_service.py b/openviking/service/resource_memory_link_service.pyindex d512fd68d..aa73a77c2 100644--- a/openviking/service/resource_memory_link_service.py+++ b/openviking/service/resource_memory_link_service.py@@ -153,7 +153,12 @@ class ResourceMemoryLinkService:reason: str,source_name: Optional[str] = None,) -> Dict[str, Any]:- """Bridge add-resource reason extraction through normal session commit."""+ """Queue add-resource reason extraction as a normal session commit.++ Returns once the commit is queued. Every reason commit serializes on one+ shared session, so waiting for it here held the caller behind all earlier+ reason commits (one stalled commit could block resource ingestion).+ """reason = (reason or "").strip()if not reason:return {"status": "skipped", "reason": "empty_reason"}@@ -167,7 +172,6 @@ class ResourceMemoryLinkService:session_id = _RESOURCE_REASON_SESSION_IDtarget_peer_id = _resource_reason_peer_id(ctx, resource_uri)commit_result: Dict[str, Any] = {}- task_result: Optional[Dict[str, Any]] = Noneasync with self._reason_session_lock:session = await self._session_service.get(@@ -204,18 +208,11 @@ class ResourceMemoryLinkService:keep_recent_count=0,)- task_id = commit_result.get("task_id")- if task_id:- task_result = await self._wait_for_commit_task(- task_id=str(task_id),- ctx=ctx,- )return {"status": "success","session_id": session_id,- "commit_task_id": task_id,+ "commit_task_id": commit_result.get("task_id"),"archive_uri": commit_result.get("archive_uri"),- "commit_task": task_result,}async def on_resource_deleted(diff --git a/tests/service/test_resource_memory_link_service.py b/tests/service/test_resource_memory_link_service.pyindex 2569371be..51058a8f0 100644--- a/tests/service/test_resource_memory_link_service.py+++ b/tests/service/test_resource_memory_link_service.py@@ -254,6 +254,41 @@ async def test_on_resource_added_bridges_reason_through_fixed_session(request_coassert "动漫角色照片合集" in message_text+async def test_on_resource_added_returns_once_reason_commit_is_queued(request_context, monkeypatch):+ """All reason commits serialize on one session; waiting for each one held the+ caller (an AddResource worker) behind every earlier reason commit."""++ class QueuedSessionService(_FakeSessionService):+ async def commit_async(self, session_id, ctx, keep_recent_count=0):+ result = await super().commit_async(session_id, ctx, keep_recent_count)+ return {**result, "task_id": "reason-task"}++ class NeverFinishingTracker:+ async def wait(self, *args, **kwargs):+ await asyncio.Event().wait()++ monkeypatch.setattr(+ "openviking.service.task_tracker.get_task_tracker", lambda: NeverFinishingTracker()+ )+ service = ResourceMemoryLinkService(+ viking_fs=_FakeVikingFS({}),+ session_service=QueuedSessionService(),+ )++ result = await asyncio.wait_for(+ service.on_resource_added(+ ctx=request_context,+ resource_uri="viking://resources/images/ryoma.jpeg",+ reason="这是越前龙马的照片",+ ),+ timeout=3,+ )++ assert result["status"] == "success"+ assert result["commit_task_id"] == "reason-task"++@pytest.mark.asyncioasync def test_on_resource_added_reuses_same_reason_session(request_context):"""Concurrent queue loops must serialize writes to the shared reason session."""