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
修复 experience 写入失败后 case 仍生成悬空链接的问题,确保仅链接实际写入成功的 experience。 (#3499)
DuTao4bccb40c27b2
diff --git a/openviking/session/compressor_v3.py b/openviking/session/compressor_v3.pyindex 7ddd0d702..a007ce8af 100644--- a/openviking/session/compressor_v3.py+++ b/openviking/session/compressor_v3.py@@ -1488,7 +1488,7 @@ def _case_experience_links_via_trajectories(if not _plan_item_has_source_trajectory(item, trajectory_uris):continueuri = _experience_plan_item_uri(item, root_uri)- if touched and uri not in touched:+ if uri not in touched:continueif uri in seen:continuediff --git a/tests/session/test_compressor_v3.py b/tests/session/test_compressor_v3.pyindex 941172a6b..0bfabbd08 100644--- a/tests/session/test_compressor_v3.py+++ b/tests/session/test_compressor_v3.py@@ -131,6 +131,51 @@ def test_case_experience_links_require_policy_root_uri():)+def test_case_experience_links_exclude_experiences_that_failed_to_persist():+ traj_uri = "viking://user/u/memories/trajectories/t.md"+ exp_uri = "viking://user/u/memories/experiences/exp.md"+ plan = PolicyUpdatePlan(+ items=[+ PolicyPlanItem(+ kind="upsert",+ memory_type="experiences",+ target_name="exp",+ target_uri=exp_uri,+ before_content=None,+ after_content="exp",+ links=[+ StoredLink(+ from_uri=exp_uri,+ to_uri=traj_uri,+ link_type="derived_from",+ weight=1.0,+ )+ ],+ )+ ]+ )+ apply_result = PolicyApplyResult(+ updated_policy_set=ExperienceSet(+ root_uri="viking://user/u/memories/experiences",+ policies=[],+ ),+ written_uris=[],+ errors=[f"{exp_uri}: failed to acquire encrypted write lock"],+ )++ from openviking.session.compressor_v3 import _case_experience_links_via_trajectories++ assert (+ _case_experience_links_via_trajectories(+ case_uri="viking://user/u/memories/cases/case.md",+ trajectory_uris={traj_uri},+ plan=plan,+ apply_result=apply_result,+ )+ == []+ )++@pytest.mark.asyncioasync def test_train_from_extracted_cases_submits_streaming_rollout(monkeypatch):submitted_gradients = []diff --git a/tests/session/train/test_train_components.py b/tests/session/train/test_train_components.pyindex de346e076..f380ed0c7 100644--- a/tests/session/train/test_train_components.py+++ b/tests/session/train/test_train_components.py@@ -28,6 +28,7 @@ class FakeVikingFS:def __init__(self, files: dict[str, str]):self.files = filesself.rm_lock_handles = []+ self.write_lock_handles = []async def ls(self, uri: str, output: str = "original", ctx=None, **kwargs):del kwargs@@ -46,7 +47,8 @@ class FakeVikingFS:async def read_file(self, uri: str, ctx=None):return self.files[uri]- async def write_file(self, uri: str, content: str, ctx=None):+ async def write_file(self, uri: str, content: str, ctx=None, lock_handle=None):+ self.write_lock_handles.append((uri, lock_handle))self.files[uri] = contentasync def rm(self, uri: str, recursive: bool = False, ctx=None, lock_handle=None):@@ -306,6 +308,30 @@ async def test_memory_file_policy_updater_writes_experience_files():assert '"version": 2' in written+async def test_memory_file_policy_updater_reuses_transaction_lock_for_experience_writes():+ policy_set = _experience_set()+ fs = FakeVikingFS({})+ lock_handle = object()+ gradient = _patch_gradient(+ uri=policy_set.policies[0].uri,+ before="content",+ after="new content",+ )+ plan = _plan_from_gradient(gradient)++ result = await MemoryFilePolicyUpdater(viking_fs=fs).apply(+ plan,+ policy_set,+ fake_request_context(),+ transaction_handle=lock_handle,+ )++ assert result.errors == []+ assert result.written_uris == [policy_set.policies[0].uri]+ assert (policy_set.policies[0].uri, lock_handle) in fs.write_lock_handles++@pytest.mark.asyncioasync def test_memory_file_policy_updater_vectorizes_written_experience_files():policy_set = _experience_set()