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(session): validate archive names when loading history (#3922)
Jiajie - He/him/his6a252eba1868
diff --git a/openviking/session/session.py b/openviking/session/session.pyindex cd92be373..603cf9a4e 100644--- a/openviking/session/session.py+++ b/openviking/session/session.py@@ -664,13 +664,15 @@ class Session:# Restore compression_index (scan history directory)try:history_items = await self._viking_fs.ls(f"{self._session_uri}/history", ctx=self.ctx)- archives = [- item["name"] for item in history_items if item["name"].startswith("archive_")+ archive_indices = [+ int(match.group(1))+ for item in history_items+ if (match := re.fullmatch(r"archive_(\d+)", item["name"]))]- if archives:- max_index = max(int(a.split("_")[1]) for a in archives)+ if archive_indices:+ max_index = max(archive_indices)self._compression.compression_index = max_index- self._stats.compression_count = len(archives)+ self._stats.compression_count = len(archive_indices)logger.debug(f"Restored compression_index: {max_index}")except Exception as exc:if not _is_storage_not_found(exc):diff --git a/tests/session/test_session_lifecycle.py b/tests/session/test_session_lifecycle.pyindex 3eb343b32..cee4844e2 100644--- a/tests/session/test_session_lifecycle.py+++ b/tests/session/test_session_lifecycle.py@@ -67,6 +67,21 @@ class TestSessionLoad:# Nonexistent session should be empty after loadingassert len(session.messages) == 0+ async def test_load_ignores_non_archive_history_entries(self, client: AsyncOpenViking):+ session = client.session(session_id="archive_name_validation_test")+ for name in ("archive_001", "archive_002", "archive_001.bak.20260628"):+ await session._viking_fs.mkdir(+ f"{session.uri}/history/{name}",+ exist_ok=True,+ ctx=session.ctx,+ )++ loaded = client.session(session_id=session.session_id)+ await loaded.load()++ assert loaded.compression.compression_index == 2+ assert loaded.stats.compression_count == 2+async def test_session_properties(self, session: Session):"""Test session properties"""assert hasattr(session, "uri")