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(auth): refuse account mutations without a registry baseline (#5483)
Evo1092643a622d
diff --git a/openviking/server/api_keys/legacy.py b/openviking/server/api_keys/legacy.pyindex e5f5e8ef8..c5ddcaa38 100644--- a/openviking/server/api_keys/legacy.py+++ b/openviking/server/api_keys/legacy.py@@ -658,7 +658,7 @@ class LegacyAPIKeyManager:conflict_type="account_registry_busy",) from exctry:- accounts_data = await self._read_json(ACCOUNTS_PATH) or {"accounts": {}}+ accounts_data = await self._read_accounts_for_update()persisted_accounts = accounts_data.setdefault("accounts", {})for account_id in normalized:if account_id not in persisted_accounts:@@ -1441,6 +1441,14 @@ class LegacyAPIKeyManager:)self._prefix_index = prefix_index+ async def _read_accounts_for_update(self) -> dict:+ data = await self._read_json(ACCOUNTS_PATH)+ if data is None:+ raise FailedPreconditionError(+ "Account registry is missing; refusing to overwrite it with account changes."+ )+ return data+async def _save_accounts_json(self,*,@@ -1458,7 +1466,7 @@ class LegacyAPIKeyManager:conflict_type="account_registry_busy",) from exctry:- data = await self._read_json(ACCOUNTS_PATH) or {"accounts": {}}+ data = await self._read_accounts_for_update()accounts = data.setdefault("accounts", {})for account_id in reject_existing_account_ids or set():if account_id in accounts:diff --git a/tests/server/test_api_key_manager.py b/tests/server/test_api_key_manager.pyindex dcccef29d..40497bdd7 100644--- a/tests/server/test_api_key_manager.py+++ b/tests/server/test_api_key_manager.py@@ -16,6 +16,7 @@ from openviking.server.api_keys.legacy import ACCOUNTS_PATH, USERS_PATH_TEMPLATEfrom openviking.server.identity import Rolefrom openviking_cli.exceptions import (AlreadyExistsError,+ FailedPreconditionError,InvalidArgumentError,NotFoundError,PermissionDeniedError,@@ -646,6 +647,48 @@ async def test_default_account_exists(manager: APIKeyManager):assert any(a["account_id"] == "default" for a in accounts)[email protected]("operation", ["create", "delete", "trusted"])+async def test_account_mutation_preserves_registry_when_baseline_is_missing(+ manager: APIKeyManager, monkeypatch: pytest.MonkeyPatch, operation: str+):+ survivor = _uid()+ key = await manager.create_account(survivor, "alice")+ target = _uid()+ if operation == "delete":+ await manager.create_account(target, "bob")+ read = manager._legacy._async_agfs.read+ before = await read(ACCOUNTS_PATH)+ missing_reads = 0++ async def missing_once(path, *args, **kwargs):+ nonlocal missing_reads+ if path == ACCOUNTS_PATH and missing_reads == 0:+ missing_reads += 1+ raise AGFSNotFoundError("injected missing registry read")+ return await read(path, *args, **kwargs)++ monkeypatch.setattr(manager._legacy._async_agfs, "read", missing_once)++ async def mutate():+ if operation == "create":+ return await manager.create_account(target, "bob")+ if operation == "delete":+ return await manager.delete_account(target)+ return await manager.ensure_trusted_identities({target: {"bob"}})++ with pytest.raises(FailedPreconditionError, match="Account registry"):+ await mutate()+ assert missing_reads == 1+ assert await read(ACCOUNTS_PATH) == before+ assert manager.resolve(key).account_id == survivor+ await manager.reload()+ assert manager.resolve(key).account_id == survivor+ # The failed mutation must also release its lease and leave retries usable.+ await mutate()+ await manager.reload()+ assert manager.resolve(key).account_id == survivor++# ---- User lifecycle tests ----