Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(memory): preserve recovery ownership boundaries
cyh80aff547a28c
diff --git a/config/v2_config.py b/config/v2_config.pyindex f5d10acf8..9228cf13a 100644--- a/config/v2_config.py+++ b/config/v2_config.py@@ -1059,6 +1059,8 @@ def _recovery_section_for_error(error: BaseException) -> Optional[str]:match = re.search(r"Config '([^']+)'", message)if match:path = match.group(1)+ if path == "memory.cloud" or path.startswith("memory.cloud."):+ return "memory.cloud"if path.startswith("memory.processing.rerank"):return "memory.rerank"if path.startswith("memory.processing.multimodal"):@@ -1207,6 +1209,12 @@ def _reset_recoverable_config_section(return Falseprocessing.pop("multimodal", None)return True+ if section == "memory.cloud":+ memory = payload.get("memory")+ if not isinstance(memory, dict):+ return False+ memory["cloud"] = {}+ return Trueif section == "runtime":# Keep this in sync with ``V2Config.default``. RuntimeConfig has a# required cwd, so an empty object would make the recovery loop fail a@@ -1721,13 +1729,19 @@ class MemoryEndpointConfig:api_key: Optional[str] = field(default=None, repr=False)def validate(self, *, name: str) -> None:- self.base_url = _validate_memory_url(self.base_url, name=name)+ self.base_url = _validate_memory_url(+ self.base_url,+ path=f"memory.processing.{name}.base_url",+ )self.model = _validate_memory_text(self.model,name=f"memory.processing.{name}.model",maximum=_MEMORY_MAX_MODEL_BYTES,)- self.api_key = _validate_memory_key(self.api_key, name=name)+ self.api_key = _validate_memory_key(+ self.api_key,+ path=f"memory.processing.{name}.api_key",+ )def complete(self) -> bool:return bool(self.base_url and self.model and self.api_key)@@ -1842,12 +1856,12 @@ class MemoryCloudConfig:if self.proxy_base_url is not None:self.proxy_base_url = _validate_memory_url(self.proxy_base_url,- name="cloud.proxy",+ path="memory.cloud.proxy_base_url",)if self.model_access_key is not None:self.model_access_key = _validate_memory_key(self.model_access_key,- name="cloud.model_access_key",+ path="memory.cloud.model_access_key",)if not self.model_access_key.startswith("mak_"):raise ValueError("Config 'memory.cloud.model_access_key' is invalid")@@ -1924,6 +1938,14 @@ class MemoryConfig:def custom_processing_complete(self) -> bool:return self.processing.llm.complete() and self.processing.embedding.complete()+ def arm_rebuild_if_idle(self) -> bool:+ """Request an embedding rebuild without downgrading a stronger recovery."""++ if self.recovery_intent is not None:+ return False+ self.recovery_intent = "rebuild"+ return True+def cloud_runtime_selected(self) -> bool:if self.cloud.scope == "organization":# A pending enterprise transition is deliberately fenced on the@@ -2009,18 +2031,18 @@ class MemoryConfig:return bool(self.processing.multimodal and self.processing.multimodal.complete())-def _validate_memory_url(value: object, *, name: str) -> Optional[str]:+def _validate_memory_url(value: object, *, path: str) -> Optional[str]:if value is None or value == "":return Noneif not isinstance(value, str):- raise ValueError(f"Config 'memory.processing.{name}.base_url' must be a string")+ raise ValueError(f"Config '{path}' must be a string")candidate = value.strip()if (not candidateor len(candidate.encode("utf-8")) > _MEMORY_MAX_URL_BYTESor any(ord(character) < 32 or ord(character) == 127 for character in candidate)):- raise ValueError(f"Config 'memory.processing.{name}.base_url' is invalid")+ raise ValueError(f"Config '{path}' is invalid")parsed = urlsplit(candidate)if (parsed.scheme not in {"http", "https"}@@ -2030,20 +2052,20 @@ def _validate_memory_url(value: object, *, name: str) -> Optional[str]:or parsed.queryor parsed.fragment):- raise ValueError(f"Config 'memory.processing.{name}.base_url' is invalid")+ raise ValueError(f"Config '{path}' is invalid")try:port = parsed.portexcept ValueError as exc:- raise ValueError(f"Config 'memory.processing.{name}.base_url' is invalid") from exc+ raise ValueError(f"Config '{path}' is invalid") from excif port is not None and not 1 <= port <= 65535:- raise ValueError(f"Config 'memory.processing.{name}.base_url' is invalid")+ raise ValueError(f"Config '{path}' is invalid")if parsed.scheme == "http":try:loopback = ipaddress.ip_address(parsed.hostname).is_loopbackexcept ValueError:loopback = Falseif not loopback:- raise ValueError(f"Config 'memory.processing.{name}.base_url' requires HTTPS")+ raise ValueError(f"Config '{path}' requires HTTPS")return urlunsplit((parsed.scheme, parsed.netloc, parsed.path.rstrip("/"), "", ""))@@ -2063,17 +2085,17 @@ def _validate_memory_text(value: object, *, name: str, maximum: int) -> Optionalreturn candidate-def _validate_memory_key(value: object, *, name: str) -> Optional[str]:+def _validate_memory_key(value: object, *, path: str) -> Optional[str]:if value is None or value == "":return Noneif not isinstance(value, str):- raise ValueError(f"Config 'memory.processing.{name}.api_key' must be a string")+ raise ValueError(f"Config '{path}' must be a string")if (len(value.encode("utf-8")) > _MEMORY_MAX_API_KEY_BYTESor any(ord(character) < 32 or ord(character) == 127 for character in value)or _looks_like_ui_mask(value)):- raise ValueError(f"Config 'memory.processing.{name}.api_key' is invalid")+ raise ValueError(f"Config '{path}' is invalid")return valuediff --git a/tests/test_memory_config.py b/tests/test_memory_config.pyindex b73188b19..4da0f513c 100644--- a/tests/test_memory_config.py+++ b/tests/test_memory_config.py@@ -10,8 +10,10 @@ import pytestfrom config.v2_config import (AgentsConfig,CONFIG_LOCK,+ MemoryCloudConfig,MemoryConfig,MemoryEndpointConfig,+ MemoryRecoveryIntent,RuntimeConfig,SlackConfig,V2Config,@@ -328,6 +330,67 @@ def test_memory_config_accepts_factory_reset_recovery_intent() -> None:assert config.memory.recovery_intent == "factory_reset"+ ("initial", "expected", "armed"),+ [+ (None, "rebuild", True),+ ("rebuild", "rebuild", False),+ ("factory_reset", "factory_reset", False),+ ],+)+def test_memory_rebuild_request_never_downgrades_recovery(+ initial: MemoryRecoveryIntent | None,+ expected: MemoryRecoveryIntent,+ armed: bool,+) -> None:+ memory = MemoryConfig(recovery_intent=initial)++ assert memory.arm_rebuild_if_idle() is armed+ assert memory.recovery_intent == expected+++ "cloud",+ [+ [],+ {"capabilities": []},+ {"scope": "unsupported"},+ {"proxy_base_url": 7},+ {"model_access_key": 7},+ {"transition_rebuild_owned": True},+ ],+)+def test_disk_load_recovers_only_a_malformed_memory_cloud_cache(+ tmp_path,+ cloud: object,+) -> None:+ config_path = tmp_path / "config.json"+ memory = {+ "enabled": True,+ "mode": "custom",+ "recovery_intent": "factory_reset",+ "processing": _complete_processing(),+ "cloud": cloud,+ }+ payload = _payload(memory)++ with pytest.raises((TypeError, ValueError)):+ V2Config.from_payload(payload)+ config_path.write_text(json.dumps(payload), encoding="utf-8")++ loaded = V2Config.load(config_path)++ assert loaded.memory.enabled is True+ assert loaded.memory.mode == "custom"+ assert loaded.memory.custom_processing_complete() is True+ assert loaded.memory.processing.llm.api_key == "llm-key"+ assert loaded.memory.processing.embedding.api_key == "embed-key"+ assert loaded.memory.recovery_intent == "factory_reset"+ assert loaded.memory.cloud == MemoryCloudConfig()+ assert any("memory.cloud" in warning for warning in loaded.load_warnings)+ assert json.loads(config_path.read_text(encoding="utf-8"))["memory"]["cloud"] == cloud++def test_memory_transition_rebuild_owner_round_trips(tmp_path) -> None:config_path = tmp_path / "config.json"config = V2Config.from_payload(diff --git a/tests/test_model_service.py b/tests/test_model_service.pyindex a56e87abe..d7d0253d0 100644--- a/tests/test_model_service.py+++ b/tests/test_model_service.py@@ -784,6 +784,36 @@ def test_capability_removal_pauses_and_resume_checks_last_applied_identity() ->assert changed_identity.recovery_intent == "rebuild"[email protected]("scope", ["platform", "organization"])+def test_cloud_identity_adoption_preserves_a_pending_factory_reset(+ scope: str,+) -> None:+ current = MemoryConfig(+ enabled=True,+ mode="platform",+ recovery_intent="factory_reset",+ cloud=MemoryCloudConfig(+ scope=scope,+ capabilities=MemoryCloudCapabilities(chat=True, embedding=True),+ embedding_identity="emb-v1",+ applied_embedding_identity="emb-v1",+ model_access_key="mak_first",+ proxy_base_url="https://backend.example.test/v1/model",+ source_instance_id="instance-1",+ organization_attached=scope == "organization",+ ),+ )++ changed_identity = _resolved(+ current,+ _status(scope=scope, identity="emb-v2", revision=2),+ )++ assert changed_identity.cloud.applied_embedding_identity == "emb-v2"+ assert changed_identity.recovery_intent == "factory_reset"+ assert changed_identity.cloud.runtime_apply_pending is True++def test_platform_to_organization_upstream_change_is_an_identity_change() -> None:platform = MemoryConfig(enabled=True,diff --git a/vibe/model_service.py b/vibe/model_service.pyindex f09d7348d..56517fc79 100644--- a/vibe/model_service.py+++ b/vibe/model_service.py@@ -198,7 +198,7 @@ def _adopt_cloud_embedding_identity(baseline = previous.cloud.applied_embedding_identityfirst_activation = baseline is Noneif previous.cloud_runtime_selected() and baseline is not None and baseline != identity:- candidate.recovery_intent = "rebuild"+ candidate.arm_rebuild_if_idle()candidate.cloud.applied_embedding_identity = identityreturn first_activation@@ -244,13 +244,11 @@ def _resolved_memory(if first_managed_activation:candidate.enabled = Trueelif candidate.cloud.transition_notice_pending:- if candidate.recovery_intent is None:- candidate.recovery_intent = "rebuild"+ if candidate.arm_rebuild_if_idle():candidate.cloud.transition_rebuild_owned = Trueelif candidate.mode == "custom" and previous.custom_processing_complete():candidate.cloud.transition_notice_pending = True- if candidate.recovery_intent is None:- candidate.recovery_intent = "rebuild"+ if candidate.arm_rebuild_if_idle():candidate.cloud.transition_rebuild_owned = Trueelse:candidate.cloud.organization_attached = True@@ -286,7 +284,7 @@ def _resolved_memory(if first_platform_activation:candidate.enabled = Trueelif was_organization_cloud:- candidate.recovery_intent = "rebuild"+ candidate.arm_rebuild_if_idle()candidate.cloud.applied_embedding_identity = Nonecandidate.cloud.runtime_apply_pending = (