Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

fix(memory): centralize cloud lifecycle transitions

cyhad2787bdf111
diff --git a/tests/test_model_service.py b/tests/test_model_service.py
index 4945e810c..b3ed3f596 100644
--- a/tests/test_model_service.py
+++ b/tests/test_model_service.py
@@ -354,16 +354,36 @@ def test_enterprise_attachment_pauses_custom_until_acknowledged() -> None:
)
-def test_canceling_enterprise_attachment_resumes_the_preserved_custom_runtime() -> None:
+ "event",
+ ["scope_release", "capability_removal", "unpair"],
+)
+def test_canceling_enterprise_attachment_resumes_the_preserved_custom_runtime(
+ event: str,
+) -> None:
pending = _resolved(
_manual_memory(),
_status(scope="organization"),
)
- canceled = _resolved(
- pending,
- _status(scope="platform", revision=2),
- )
+ if event == "scope_release":
+ canceled = _resolved(
+ pending,
+ _status(scope="platform", revision=2),
+ )
+ elif event == "capability_removal":
+ canceled = _resolved(
+ pending,
+ _status(
+ scope="organization",
+ chat=False,
+ embedding=False,
+ identity=None,
+ revision=2,
+ ),
+ )
+ else:
+ canceled = model_service._unpaired_memory(pending) # noqa: SLF001
assert canceled.cloud.transition_notice_pending is False
assert canceled.cloud.organization_attached is False
@@ -372,6 +392,22 @@ def test_canceling_enterprise_attachment_resumes_the_preserved_custom_runtime()
assert canceled.cloud.runtime_apply_pending is True
+def test_canceling_enterprise_attachment_preserves_an_unrelated_recovery_fence() -> None:
+ pending = _resolved(
+ _manual_memory(),
+ _status(scope="organization"),
+ )
+ pending.recovery_intent = "factory_reset"
+
+ canceled = _resolved(
+ pending,
+ _status(scope="platform", revision=2),
+ )
+
+ assert canceled.cloud.transition_notice_pending is False
+ assert canceled.recovery_intent == "factory_reset"
+
+
def test_enterprise_transition_acknowledgement_cannot_edit_custom_endpoints() -> None:
pending = _resolved(
_manual_memory(),
@@ -580,6 +616,78 @@ def test_platform_to_organization_upstream_change_is_an_identity_change() -> Non
assert organization.recovery_intent == "rebuild"
[email protected]("old_scope", ["platform", "organization"])
[email protected]("new_scope", ["platform", "organization"])
+ ("new_identity", "expected_recovery"),
+ [("emb-old", None), ("emb-new", "rebuild")],
+)
+def test_pairing_a_different_instance_preserves_the_cloud_identity_baseline(
+ old_scope: str,
+ new_scope: str,
+ new_identity: str,
+ expected_recovery: str | None,
+) -> None:
+ current = MemoryConfig(
+ enabled=True,
+ mode="platform",
+ cloud=MemoryCloudConfig(
+ scope=old_scope,
+ capabilities=MemoryCloudCapabilities(chat=True, embedding=True),
+ embedding_identity="emb-old",
+ applied_embedding_identity="emb-old",
+ model_access_key="mak_old",
+ proxy_base_url="https://old.example.test/v1/model",
+ source_instance_id="instance-old",
+ organization_attached=old_scope == "organization",
+ ),
+ )
+
+ repaired = _resolved(
+ current,
+ _status(scope=new_scope, identity=new_identity, revision=2),
+ minted=_mint("mak_new"),
+ )
+
+ assert repaired.cloud.applied_embedding_identity == new_identity
+ assert repaired.recovery_intent == expected_recovery
+ assert repaired.runtime_source() == "cloud"
+
+
+def test_platform_mode_acknowledgement_records_the_confirmed_cloud_identity() -> None:
+ memory = _manual_memory()
+ memory.mode = "custom"
+ memory.cloud = MemoryCloudConfig(
+ scope="platform",
+ capabilities=MemoryCloudCapabilities(chat=True, embedding=True),
+ embedding_identity="emb-cloud",
+ applied_embedding_identity="emb-previous-cloud",
+ model_access_key="mak_first",
+ proxy_base_url="https://backend.example.test/v1/model",
+ source_instance_id="instance-1",
+ )
+ current = _paired_config(memory)
+
+ target, confirm_rebuild = ui_memory_routes._memory_settings_patch( # noqa: SLF001
+ current,
+ {"mode": "platform", "confirm_rebuild": True},
+ )
+ candidate = ui_memory_routes._memory_candidate_config( # noqa: SLF001
+ current,
+ target,
+ )
+
+ assert confirm_rebuild is True
+ assert candidate.memory.cloud.applied_embedding_identity == "emb-cloud"
+ assert (
+ ui_memory_routes._memory_embedding_configuration_changed( # noqa: SLF001
+ current,
+ candidate,
+ )
+ is True
+ )
+
+
@pytest.mark.parametrize("dedicated_multimodal", [False, True])
def test_cloud_aliases_and_mak_flow_through_existing_everos_environment(
dedicated_multimodal: bool,
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 0f28bf3c7..12483d933 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -4483,8 +4483,8 @@
"organizationTransitionTitle": "Your organization now manages Memory models",
"organizationTransitionDescription": "Memory processing is paused. Confirm the change to rebuild the local index with your organization's embedding model; queued messages are kept.",
"organizationTransitionAction": "Review and rebuild",
- "cloudPausedTitle": "Organization Memory models are unavailable",
- "cloudPausedDescription": "Memory processing is paused and new messages keep queuing. It resumes after your organization restores both chat and embedding models.",
+ "cloudPausedTitle": "Cloud Memory models are unavailable",
+ "cloudPausedDescription": "Memory processing is paused and new messages keep queuing. It resumes automatically when both cloud chat and embedding models are available.",
"dependencyNotReady": "The memory-runtime dependency isn't ready yet. Install or repair it from Settings → Dependencies, then try enabling Memory again.",
"goToDependencies": "Open Dependencies",
"llmTitle": "Language model (LLM)",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 711fcb9f5..db24a03dc 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -4483,8 +4483,8 @@
"organizationTransitionTitle": "你的组织现在统一管理记忆模型",
"organizationTransitionDescription": "记忆处理已暂停。确认后将使用组织的向量模型重建本地索引;排队中的消息会保留。",
"organizationTransitionAction": "确认并重建",
- "cloudPausedTitle": "组织的记忆模型暂不可用",
- "cloudPausedDescription": "记忆处理已暂停,新消息会继续排队。组织恢复聊天和向量模型后将自动继续。",
+ "cloudPausedTitle": "云端记忆模型暂不可用",
+ "cloudPausedDescription": "记忆处理已暂停,新消息会继续排队。云端聊天和向量模型都恢复可用后将自动继续。",
"dependencyNotReady": "memory-runtime 依赖尚未就绪。请先在「设置 → 依赖」中安装或修复,然后重新尝试启用记忆。",
"goToDependencies": "前往依赖页面",
"llmTitle": "语言模型(LLM)",
diff --git a/vibe/model_service.py b/vibe/model_service.py
index da40e330b..076a586b0 100644
--- a/vibe/model_service.py
+++ b/vibe/model_service.py
@@ -173,6 +173,32 @@ def _runtime_state_signature(memory: MemoryConfig) -> tuple[object, ...]:
)
+def _cancel_organization_transition(memory: MemoryConfig) -> bool:
+ """Cancel only the rebuild fence owned by a pending org transition."""
+
+ if not memory.cloud.transition_notice_pending:
+ return False
+ memory.cloud.transition_notice_pending = False
+ if memory.recovery_intent == "rebuild":
+ memory.recovery_intent = None
+ return True
+
+
+def _adopt_cloud_embedding_identity(
+ candidate: MemoryConfig,
+ previous: MemoryConfig,
+ identity: str,
+) -> bool:
+ """Record one cloud target while checking the prior runtime baseline."""
+
+ baseline = previous.cloud.applied_embedding_identity
+ first_activation = baseline is None
+ if previous.cloud_runtime_selected() and baseline is not None and baseline != identity:
+ candidate.recovery_intent = "rebuild"
+ candidate.cloud.applied_embedding_identity = identity
+ return first_activation
+
+
def _resolved_memory(
current: MemoryConfig,
*,
@@ -185,10 +211,9 @@ def _resolved_memory(
previous = deepcopy(current)
first_resolution = candidate.cloud.source_instance_id != instance_id
if first_resolution:
+ _cancel_organization_transition(candidate)
candidate.cloud.model_access_key = None
candidate.cloud.organization_attached = False
- candidate.cloud.transition_notice_pending = False
- candidate.cloud.applied_embedding_identity = None
if candidate.mode is None:
candidate.mode = _memory_mode_after_initialization(candidate)
@@ -204,17 +229,14 @@ def _resolved_memory(
if status.scope == "organization":
if status.memory_available():
+ assert status.embedding_identity is not None
if candidate.cloud.organization_attached:
- first_managed_activation = (
- candidate.cloud.applied_embedding_identity is None
- )
- if (
- candidate.cloud.applied_embedding_identity is not None
- and candidate.cloud.applied_embedding_identity != status.embedding_identity
- ):
- candidate.recovery_intent = "rebuild"
if candidate.cloud.model_access_key:
- candidate.cloud.applied_embedding_identity = status.embedding_identity
+ first_managed_activation = _adopt_cloud_embedding_identity(
+ candidate,
+ previous,
+ status.embedding_identity,
+ )
if first_managed_activation:
candidate.enabled = True
elif candidate.cloud.transition_notice_pending:
@@ -223,52 +245,36 @@ def _resolved_memory(
candidate.cloud.transition_notice_pending = True
candidate.recovery_intent = "rebuild"
else:
- if (
- previous.cloud.scope == "platform"
- and previous.cloud.applied_embedding_identity is not None
- and previous.cloud.applied_embedding_identity != status.embedding_identity
- ):
- candidate.recovery_intent = "rebuild"
candidate.cloud.organization_attached = True
if candidate.cloud.model_access_key:
- candidate.cloud.applied_embedding_identity = status.embedding_identity
+ _adopt_cloud_embedding_identity(
+ candidate,
+ previous,
+ status.embedding_identity,
+ )
candidate.enabled = True
- elif candidate.cloud.organization_attached:
- # Keep the last applied identity while paused so re-enable can
- # distinguish an unchanged provider from one that needs rebuild.
- candidate.cloud.transition_notice_pending = False
- elif not (
- candidate.mode == "custom" and previous.custom_processing_complete()
- ):
- # Scope binding remains managed even with no Memory pair. Only a
- # complete configuration that was actively custom is grandfathered;
- # every other installation pauses instead of falling back.
- candidate.cloud.organization_attached = True
- candidate.cloud.applied_embedding_identity = (
- previous.cloud.applied_embedding_identity
- )
+ else:
+ _cancel_organization_transition(candidate)
+ if not candidate.cloud.organization_attached and not (
+ candidate.mode == "custom" and previous.custom_processing_complete()
+ ):
+ # Scope binding remains managed even with no Memory pair. Only a
+ # complete configuration that was actively custom is grandfathered;
+ # every other installation pauses instead of falling back. Attached
+ # runtimes keep their identity baseline for a checked resume.
+ candidate.cloud.organization_attached = True
+ candidate.cloud.applied_embedding_identity = previous.cloud.applied_embedding_identity
else:
was_organization_cloud = previous.cloud.scope == "organization" and previous.cloud.organization_attached
- canceled_organization_transition = previous.cloud.transition_notice_pending
+ _cancel_organization_transition(candidate)
candidate.cloud.organization_attached = False
- candidate.cloud.transition_notice_pending = False
- if canceled_organization_transition and candidate.recovery_intent == "rebuild":
- candidate.recovery_intent = None
- if (
- candidate.mode == "platform"
- and status.memory_available()
- and candidate.cloud.model_access_key
- ):
- first_platform_activation = (
- candidate.cloud.applied_embedding_identity is None
+ if candidate.mode == "platform" and status.memory_available() and candidate.cloud.model_access_key:
+ assert status.embedding_identity is not None
+ first_platform_activation = _adopt_cloud_embedding_identity(
+ candidate,
+ previous,
+ status.embedding_identity,
)
- if (
- (was_organization_cloud or previous.cloud.scope == "platform")
- and previous.cloud.applied_embedding_identity is not None
- and previous.cloud.applied_embedding_identity != status.embedding_identity
- ):
- candidate.recovery_intent = "rebuild"
- candidate.cloud.applied_embedding_identity = status.embedding_identity
if first_platform_activation:
candidate.enabled = True
elif was_organization_cloud:
@@ -299,16 +305,13 @@ def _unpaired_memory(current: MemoryConfig) -> MemoryConfig:
return current
candidate = deepcopy(current)
- canceled_organization_transition = cloud.transition_notice_pending
candidate.cloud.capabilities = MemoryCloudCapabilities()
candidate.cloud.embedding_identity = None
candidate.cloud.revision = None
candidate.cloud.quota_enforced = False
candidate.cloud.model_access_key = None
candidate.cloud.proxy_base_url = None
- candidate.cloud.transition_notice_pending = False
- if canceled_organization_transition and candidate.recovery_intent == "rebuild":
- candidate.recovery_intent = None
+ _cancel_organization_transition(candidate)
candidate.cloud.runtime_apply_pending = (
current.cloud.runtime_apply_pending
or _runtime_state_signature(candidate) != _runtime_state_signature(current)
diff --git a/vibe/ui_memory_routes.py b/vibe/ui_memory_routes.py
index 53b0b03fd..2bbd7effc 100644
--- a/vibe/ui_memory_routes.py
+++ b/vibe/ui_memory_routes.py
@@ -192,6 +192,7 @@ def _memory_settings_patch(current: V2Config, patch_payload: object) -> tuple[di
raise ValueError("invalid_memory_patch")
target = memory_config_to_payload(current.memory, include_secrets=True)
endpoints = ("llm", "embedding", "rerank", "multimodal")
+ adopt_cloud_identity = False
for endpoint in endpoints:
if endpoint in target["processing"]:
target["processing"][endpoint].pop("has_api_key", None)
@@ -212,6 +213,8 @@ def _memory_settings_patch(current: V2Config, patch_payload: object) -> tuple[di
):
raise ValueError("memory_cloud_unavailable")
target["mode"] = mode
+ if mode == "platform":
+ adopt_cloud_identity = True
if "acknowledge_transition" in patch_payload:
if (
patch_payload["acknowledge_transition"] is not True
@@ -222,6 +225,8 @@ def _memory_settings_patch(current: V2Config, patch_payload: object) -> tuple[di
raise ValueError("invalid_memory_patch")
target["cloud"]["organization_attached"] = True
target["cloud"]["transition_notice_pending"] = False
+ adopt_cloud_identity = True
+ if adopt_cloud_identity:
target["cloud"]["applied_embedding_identity"] = (
current.memory.cloud.embedding_identity
)