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(memory): repair multi-block patch regression (#4287)
Wu Shuwendbdb00bb5bbd
diff --git a/openviking/session/memory/merge_op/patch.py b/openviking/session/memory/merge_op/patch.pyindex 3758c68cd..d26c709d1 100644--- a/openviking/session/memory/merge_op/patch.py+++ b/openviking/session/memory/merge_op/patch.py@@ -9,6 +9,7 @@ from openviking.session.memory.merge_op.base import (FieldType,MergeOp,MergeOpBase,+ SearchReplaceBlock,StrPatch,get_python_type_for_field,)diff --git a/tests/unit/session/memory/test_patch_no_original_multiblock.py b/tests/unit/session/memory/test_patch_no_original_multiblock.pyindex db58e86b4..c256488c0 100644--- a/tests/unit/session/memory/test_patch_no_original_multiblock.py+++ b/tests/unit/session/memory/test_patch_no_original_multiblock.py@@ -19,10 +19,11 @@ from openviking.session.memory.merge_op.base import FieldType, SearchReplaceBlocfrom openviking.session.memory.merge_op.patch import PatchOpclass TestNewMemoryMultiBlockPatch:"""PatchOp: all blocks must survive when writing a new memory."""- def test_strpatch_multiblock_no_silent_loss(self):+ async def test_strpatch_multiblock_no_silent_loss(self):"""All StrPatch blocks are joined when current_value is None."""op = PatchOp(FieldType.STRING)patch = StrPatch(@@ -31,11 +32,11 @@ class TestNewMemoryMultiBlockPatch:SearchReplaceBlock(search="", replace="Fact B: user is in Tokyo."),])- result = op.apply(None, patch)+ result = await op.apply(None, patch)assert "Fact A" in result, "block 0 content should be present"assert "Fact B" in result, "block 1 content was silently dropped before the fix"- def test_dict_form_multiblock_no_silent_loss(self):+ async def test_dict_form_multiblock_no_silent_loss(self):"""dict-form blocks (the actual JSON-parsed LLM path) are all joined."""op = PatchOp(FieldType.STRING)patch_value = {@@ -44,23 +45,28 @@ class TestNewMemoryMultiBlockPatch:{"search": "", "replace": "Line 2 fact"},]}- result = op.apply(None, patch_value)+ result = await op.apply(None, patch_value)assert "Line 1" in resultassert "Line 2" in result, "second dict block was silently dropped before the fix"- def test_single_block_behaviour_unchanged(self):+ async def test_dict_form_accepts_model_blocks(self):+ """Model block objects in a dict-form patch are supported."""+ op = PatchOp(FieldType.STRING)+ patch_value = {"blocks": [SearchReplaceBlock(search="", replace="Model block")]}+ result = await op.apply(None, patch_value)+ assert result == "Model block"++ async def test_single_block_behaviour_unchanged(self):"""The common single-block case is unaffected by this change."""op = PatchOp(FieldType.STRING)patch = StrPatch(blocks=[SearchReplaceBlock(search="", replace="Only fact.")])- result = op.apply(None, patch)+ result = await op.apply(None, patch)assert result == "Only fact."- def test_existing_content_path_unaffected(self):+ async def test_existing_content_path_unaffected(self):"""When current_value is NOT None the existing search/replace path runs."""op = PatchOp(FieldType.STRING)- patch = StrPatch(- blocks=[SearchReplaceBlock(search="old text", replace="new text")]- )- result = op.apply("some old text here", patch)+ patch = StrPatch(blocks=[SearchReplaceBlock(search="old text", replace="new text")])+ result = await op.apply("some old text here", patch)assert "new text" in resultassert "old text" not in result