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(queue): stop deduplicating the retries that run before a lease exists (#6197)
ordinary beingfb92347a09d8
diff --git a/openviking/storage/queuefs/semantic_work.py b/openviking/storage/queuefs/semantic_work.pyindex 2ec972a03..3d95de780 100644--- a/openviking/storage/queuefs/semantic_work.py+++ b/openviking/storage/queuefs/semantic_work.py@@ -96,7 +96,11 @@ class SemanticMessageWork:if self.scope is not None and self.scope.lock is not None and self.scope._owned:await self.processor._enqueue_semantic_retry(queue, msg, self.scope)else:- await queue.enqueue(msg)+ # A retry is not a duplicate of the enqueue it is retrying. The+ # circuit-breaker path requeues before a lock is taken, so this+ # is the branch a memory message takes; deduplicating it here+ # would ACK the delivery with no replacement.+ await queue.enqueue(msg, deduplicate_memory=False)await self.processor._reenqueue_semantic_msg(self.msg, enqueue=enqueue)@@ -195,7 +199,9 @@ class SkillSemanticMessageWork(SemanticMessageWork):lambda: self.processor._enqueue_skill_retry(queue, msg, self.scope))else:- await run_to_completion(lambda: queue.enqueue(msg))+ # Same reasoning as SemanticMessageWork.reenqueue: a retry must+ # never be coalesced away by the memory parent window.+ await run_to_completion(lambda: queue.enqueue(msg, deduplicate_memory=False))# The shared circuit-breaker delay remains interruptible. Only the# actual lock handoff and enqueue operation must finish once started.diff --git a/tests/storage/test_memory_semantic_stall.py b/tests/storage/test_memory_semantic_stall.pyindex 98572519f..143fa2519 100644--- a/tests/storage/test_memory_semantic_stall.py+++ b/tests/storage/test_memory_semantic_stall.py@@ -66,7 +66,7 @@ async def test_retry_cancellation_keeps_skill_wait_isolated(monkeypatch, contextentered, release = asyncio.Event(), asyncio.Event()written = []- async def enqueue(msg):+ async def enqueue(msg, *, deduplicate_memory=True):entered.set()await release.wait()written.append(msg.id)diff --git a/tests/storage/test_semantic_queue_memory_dedupe.py b/tests/storage/test_semantic_queue_memory_dedupe.pyindex 6b0775f47..21ecbc274 100644--- a/tests/storage/test_semantic_queue_memory_dedupe.py+++ b/tests/storage/test_semantic_queue_memory_dedupe.py@@ -72,6 +72,41 @@ async def test_memory_semantic_worker_retry_bypasses_dedupe_window():assert named_enqueue.call_count == 2+async def test_worker_without_lock_does_not_dedupe_a_memory_retry(monkeypatch):+ """The circuit-breaker requeue runs before a lease is acquired.++ That is the branch `SemanticMessageWork` takes when it owns no lock, so the+ worker itself - not just the queue API - has to bypass the memory window.+ """+ from openviking.storage.queuefs.semantic_work import SemanticMessageWork++ processor = _processor()+ with patch.object(NamedQueue, "enqueue", new_callable=AsyncMock) as named_enqueue:+ named_enqueue.return_value = "queued-id"+ queue = SemanticQueue(MagicMock(), "/queue", "semantic")+ msg = SemanticMsg(+ uri="viking://user/default/memories/entities",+ context_type="memory",+ account_id="acc",+ user_id="u1",+ peer_id="p1",+ )+ assert await queue.enqueue(msg) == "queued-id"++ monkeypatch.setattr(+ "openviking.storage.queuefs.get_queue_manager",+ lambda: SimpleNamespace(SEMANTIC="semantic", get_queue=lambda _: queue),+ )++ work = SemanticMessageWork(processor, msg, None)+ await work.reenqueue()++ # Without the flag the retry would be coalesced against the enqueue it+ # is retrying, and the delivery would be ACKed with no replacement.+ assert named_enqueue.call_count == 2++@pytest.mark.asyncioasync def test_memory_semantic_enqueue_different_uri_not_deduped():mock_agfs = MagicMock()