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): activate config after runtime install (#1539)
rkrkrkk07ecd6f71887
diff --git a/core/memory/process.py b/core/memory/process.pyindex a30bcf7d2..66349a4d9 100644--- a/core/memory/process.py+++ b/core/memory/process.py@@ -608,6 +608,33 @@ class EverOSProcess:def down(self) -> bool:return self._down+ @property+ def restart_authorized(self) -> bool:+ """Whether this supervisor still owns a current or future launch."""++ watch_task = self._watch_task+ restart_task = self._restart_task+ return bool(+ self._desired_running+ and not self._down+ and (+ self.running+ or self._starting+ or (watch_task is not None and not watch_task.done())+ or (restart_task is not None and not restart_task.done())+ )+ )++ @property+ def retains_active_config(self) -> bool:+ """Whether owned execution can still use this supervisor's settings."""++ return bool(+ self._process is not None+ or self._owned_processes+ or self.restart_authorized+ )+@propertydef last_error(self) -> MemoryErrorCode | None:return self._last_error@@ -4042,7 +4069,7 @@ class _SystemProcessHost:class EverOSProcessPort(Protocol):"""What the runtime needs from a supervised sidecar, and nothing more.- Deliberately five members over ``EverOSProcess``'s ~990 lines: the runtime+ Deliberately seven members over ``EverOSProcess``'s ~990 lines: the runtimenever inspects the child tree, the generated config, or the signal handling.Keeping those out of this interface is what lets tests substitute a fakeinstead of patching ``psutil``, ``os``, and private attributes.@@ -4054,6 +4081,12 @@ class EverOSProcessPort(Protocol):@propertydef starting(self) -> bool: ...+ @property+ def restart_authorized(self) -> bool: ...++ @property+ def retains_active_config(self) -> bool: ...+async def start(self) -> bool: ...async def stop(self) -> None: ...@@ -4110,6 +4143,10 @@ class FakeEverOSProcess:stopped: bool = False_running: bool = True_starting: bool = False+ _down: bool = False+ _desired_running: bool = True+ _restart_pending: bool = False+ _process_tree_retained: bool = False@propertydef running(self) -> bool:@@ -4119,14 +4156,36 @@ class FakeEverOSProcess:def starting(self) -> bool:return self._starting+ @property+ def down(self) -> bool:+ return self._down++ @property+ def restart_authorized(self) -> bool:+ return bool(+ self._desired_running+ and not self._down+ and (self._running or self._starting or self._restart_pending)+ )++ @property+ def retains_active_config(self) -> bool:+ return self._running or self._process_tree_retained or self.restart_authorized+async def start(self) -> bool:self.starts += 1+ self._desired_running = True+ self._down = False+ self._restart_pending = False+ self._process_tree_retained = Falsebefore_start = self.before_startif before_start is not None:result = before_start()if inspect.isawaitable(result):await resultif self.start_failure is not None:+ self._desired_running = False+ self._down = Trueself._running = Falseawait self._notify_reaped()raise self.start_failure@@ -4136,16 +4195,22 @@ class FakeEverOSProcess:if started:await self.ready()else:+ self._restart_pending = Trueawait self._notify_reaped()return startedasync def stop(self) -> None:self.stops += 1self.stopped = True+ owned_execution = self._running or self._process_tree_retained+ self._desired_running = False+ self._restart_pending = Falseself._running = Falseself._starting = Falseif self.stop_failure is not None:+ self._process_tree_retained = owned_executionraise self.stop_failure+ self._process_tree_retained = Falseawait self._notify_reaped()async def _notify_reaped(self) -> None:diff --git a/core/memory/runtime.py b/core/memory/runtime.pyindex 5cd615459..a100bf38e 100644--- a/core/memory/runtime.py+++ b/core/memory/runtime.py@@ -1097,16 +1097,10 @@ class MemoryRuntime:claims_paused = Trueembedding_guard_rejected = Falsetry:- if await asyncio.to_thread(self._provider_data_exists_strict):+ if not await self._embedding_change_is_admissible(self._config, config):embedding_guard_rejected = Trueself._runtime_error = "memory_clear_failed"return {"ok": False, "error": self._runtime_error}- except Exception:- # An indeterminate root/queue state cannot safely accept an- # embedding change because it could mix vector spaces.- embedding_guard_rejected = True- self._runtime_error = "memory_clear_failed"- return {"ok": False, "error": self._runtime_error}finally:if embedding_guard_rejected and resume_claims_on_failure:self.module.resume_claims()@@ -1125,7 +1119,12 @@ class MemoryRuntime:python = await asyncio.to_thread(self._artifact_manager.resolve_python)if python is None:error = _runtime_error_for_status(await asyncio.to_thread(self._artifact_manager.status))- if not (self._process and self._process.running):+ if not self._sidecar.snapshot().retains_active_config:+ # No retained supervisor can run now or relaunch with the prior+ # settings, including one that exhausted its restart budget.+ # Retain the desired config so a first artifact install can+ # activate it without waiting for another reconciliation.+ self._config = configself._runtime_error = errorif claims_paused and resume_claims_on_failure:self.module.resume_claims()@@ -2402,10 +2401,10 @@ class MemoryRuntime:# including its terminal "down" state, while claims are fenced so a# repair can safely replace the executable it might otherwise relaunch.supervisor = self._process- # A HEALTHY running sidecar must not be force-stopped/replaced through- # Repair — that requires a coordinated disable first. Only a retained- # supervisor in its terminal "down" state (no live child) may be stopped- # here so Repair can recover enabled/down Memory.+ # A healthy running sidecar must not be force-stopped/replaced through+ # Repair — that requires a coordinated disable first. Any retained+ # supervisor without a live child can be stopped here: Stop revokes+ # delayed-retry authority before Repair adopts the durable config.if supervisor is not None and supervisor.running:return {"ok": False,@@ -2425,6 +2424,20 @@ class MemoryRuntime:"reason": self._runtime_error,"download_error": None,}+ try:+ activation_config = await asyncio.to_thread(+ lambda: V2Config.load().memory+ )+ except Exception:+ logger.exception(+ "Memory Runtime repair could not load the durable config"+ )+ self._runtime_error = "memory_runtime_install_failed"+ return {+ "ok": False,+ "reason": self._runtime_error,+ "download_error": None,+ }try:await supervisor.stop()except Exception:@@ -2437,6 +2450,23 @@ class MemoryRuntime:self._process = Noneself._process_records_calls = Falseself._ensure_call_log_retention()+ if (+ activation_config.recovery_intent is None+ and not await self._embedding_change_is_admissible(+ self._config,+ activation_config,+ )+ ):+ self._runtime_error = "memory_clear_failed"+ return {+ "ok": False,+ "reason": self._runtime_error,+ "download_error": None,+ }+ # The prior supervisor's launch authority is now retired.+ # Artifact activation must use the durable desired settings,+ # not the active snapshot that was kept while it could retry.+ self._config = deepcopy(activation_config)self._artifact_installing = Trueensure_task = asyncio.create_task(asyncio.to_thread(self._artifact_manager.ensure, force=True)@@ -3471,6 +3501,9 @@ class MemoryRuntime:meta,candidate,)+ previous_python = await asyncio.to_thread(+ self._artifact_manager.resolve_python+ )commit()result = await self._reconcile_locked(self._config,@@ -3479,6 +3512,14 @@ class MemoryRuntime:resume_claims_on_failure=False,)if result.get("ok") is not True:+ if previous_python is None:+ # First artifact admission is durable even when+ # its desired config cannot activate immediately.+ # Publish restart authority only when the failed+ # start retained a supervisor carrying that config.+ if self._sidecar.snapshot().supervisor_can_restart:+ self._restart_config = deepcopy(self._config)+ returnraise MemoryRuntimeActivationError("candidate runtime reconciliation failed")self._restart_config = deepcopy(self._config)return@@ -3728,6 +3769,22 @@ class MemoryRuntime:stats = self._store.queue_stats()return bool(root_has_data or stats.pending or stats.processing or stats.dead or self._store.has_provider_data_history())+ async def _embedding_change_is_admissible(+ self,+ current: MemoryConfig,+ candidate: MemoryConfig,+ ) -> bool:+ """Require a freshly proven-empty vector surface for an embedding change."""++ if not _embedding_configuration_changed(current, candidate):+ return True+ try:+ return not await asyncio.to_thread(self._provider_data_exists_strict)+ except Exception:+ # An indeterminate root/queue state cannot safely accept an+ # embedding change because it could mix vector spaces.+ return False+def _settle_rebuild_intent(self, candidate: MemoryConfig) -> MemoryConfig | None:"""Clear a rebuild intent when the durable vector-space identity still matches.diff --git a/core/memory/sidecar_lifecycle.py b/core/memory/sidecar_lifecycle.pyindex 1d0bf4f38..a4057d854 100644--- a/core/memory/sidecar_lifecycle.py+++ b/core/memory/sidecar_lifecycle.py@@ -28,6 +28,18 @@ class SidecarSnapshot:def running(self) -> bool:return bool(self.process and self.process.running)+ @property+ def supervisor_can_restart(self) -> bool:+ """Whether retained launch authority can still produce a child."""++ return bool(self.process and self.process.restart_authorized)++ @property+ def retains_active_config(self) -> bool:+ """Whether this supervisor can still execute under captured settings."""++ return bool(self.process and self.process.retains_active_config)+@dataclass(frozen=True, slots=True)class RecorderAdmission:diff --git a/tests/test_memory_process.py b/tests/test_memory_process.pyindex 18aff2668..87fa15532 100644--- a/tests/test_memory_process.py+++ b/tests/test_memory_process.py@@ -613,7 +613,9 @@ async def test_sidecar_rejects_sun_path_overflow_without_launching_child(tmp_patassert await process.start() is Falseassert process.last_error == "memory_sidecar_unavailable"assert process.consecutive_failures == 1+ assert process.restart_authorized is Trueawait process.stop()+ assert process.restart_authorized is Falseasync def test_sidecar_start_failure_never_relaunches_beside_an_unreaped_child(monkeypatch, tmp_path: Path) -> None:@@ -2449,6 +2451,83 @@ def _supervising(process: EverOSProcess, child: _ExitedChild) -> None:process._owned_processes = {_ORPHAN_PID: _ORPHAN_CREATE_TIME}+async def test_exited_child_watcher_retains_restart_authority_until_retry_is_scheduled(+ monkeypatch: pytest.MonkeyPatch,+ tmp_path: Path,+) -> None:+ """An exit watcher owns the old settings until it chooses a terminal state."""++ process = EverOSProcess(+ sys.executable,+ effective_home=tmp_path,+ settings=_settings(),+ )+ child = _ExitedChild()+ _supervising(process, child)+ process._desired_running = True+ cleanup_started = asyncio.Event()+ release_cleanup = asyncio.Event()++ async def terminate(*_args, **_kwargs) -> None:+ cleanup_started.set()+ await release_cleanup.wait()++ monkeypatch.setattr(process, "_terminate_owned_tree", terminate)+ watch_task = asyncio.create_task(process._watch_child(child))+ process._watch_task = watch_task++ await asyncio.wait_for(cleanup_started.wait(), timeout=0.5)+ assert process.running is False+ assert process._restart_task is None+ assert process.restart_authorized is True++ release_cleanup.set()+ await asyncio.wait_for(watch_task, timeout=0.5)+ assert process._restart_task is not None+ assert process.restart_authorized is True+ await process.stop()+ assert process.restart_authorized is False+++async def test_unreaped_descendants_retain_active_config_until_stop(+ monkeypatch: pytest.MonkeyPatch,+ tmp_path: Path,+) -> None:+ """Captured settings remain authoritative while any owned tree may survive."""++ process = EverOSProcess(+ sys.executable,+ effective_home=tmp_path,+ settings=_settings(),+ )+ child = _ExitedChild()+ _supervising(process, child)+ process._owned_processes[_ORPHAN_DESCENDANT_PID] = _ORPHAN_CREATE_TIME + 1+ process._desired_running = True+ cleanup_attempts = 0++ async def terminate(*_args, **_kwargs) -> None:+ nonlocal cleanup_attempts+ cleanup_attempts += 1+ if cleanup_attempts == 1:+ raise RuntimeError("descendant tree still alive")++ monkeypatch.setattr(process, "_terminate_owned_tree", terminate)+ monkeypatch.setattr(process._ownership, "retire_if_group_is_clear", lambda *_args: None)++ await process._watch_child(child)++ assert process.running is False+ assert process.restart_authorized is False+ assert process.retains_active_config is True+ assert process._process is child+ assert _ORPHAN_DESCENDANT_PID in process._owned_processes++ await process.stop()+ assert cleanup_attempts == 2+ assert process.retains_active_config is False++def test_sidecar_notifies_reaped_callback_only_after_tree_cleanup(monkeypatch: pytest.MonkeyPatch,tmp_path: Path,@@ -2567,6 +2646,7 @@ async def test_unplanned_sidecar_signals_still_consume_crash_budget(assert process.consecutive_failures == 5assert process.down is Trueassert process._restart_task is None+ assert process.restart_authorized is Falseasync def test_planned_reap_from_exited_issuer_cannot_exempt_same_generation(@@ -4261,6 +4341,7 @@ async def test_sidecar_stop_and_cancellation_end_a_busy_root_wait(assert process.last_error is Noneassert process.down is Falseassert process.starting is False+ assert process.restart_authorized is Falseassert host.spawn_calls == []lock_attempted.clear()@@ -4273,6 +4354,7 @@ async def test_sidecar_stop_and_cancellation_end_a_busy_root_wait(assert process.last_error is Noneassert process.down is Falseassert process.starting is False+ assert process.restart_authorized is Falseassert host.spawn_calls == []finally:await process.stop()@@ -4421,6 +4503,7 @@ async def test_cancelled_sidecar_start_holds_root_lock_through_owned_cleanup(assert retention_started.is_set()assert process.consecutive_failures == 0assert process.starting is False+ assert process.restart_authorized is Falserebuild_child = _RebuildChild(0, pid=_ORPHAN_DESCENDANT_PID)rebuild_identities = {diff --git a/tests/test_memory_runtime.py b/tests/test_memory_runtime.pyindex bfe171527..8ee0802ed 100644--- a/tests/test_memory_runtime.py+++ b/tests/test_memory_runtime.py@@ -132,6 +132,60 @@ def _installed_artifact(**overrides) -> FakeMemoryArtifactManager:return FakeMemoryArtifactManager(**defaults)+class _FirstInstallArtifact(FakeMemoryArtifactManager):+ """Commit a fake first-install pointer through the real activation bridge."""++ def __init__(self) -> None:+ super().__init__(+ python=None,+ root_format=None,+ fingerprint=None,+ compatible_formats=frozenset(),+ )+ self.commits = 0+ self.rollbacks = 0++ def ensure(self, *, force: bool = False) -> dict:+ self.ensure_calls.append(force)+ assert self.activation_coordinator is not None++ def commit() -> None:+ self.commits += 1+ self.python = Path(sys.executable)+ self.root_format = "everos-1.2.3"+ self.fingerprint = "first-install"+ self.compatible_formats = frozenset({"everos-1.2.3"})+ self.status_payload = {+ "installed": True,+ "status": "ready",+ "reason": None,+ }++ def rollback() -> None:+ self.rollbacks += 1+ self.python = None+ self.root_format = None+ self.fingerprint = None+ self.compatible_formats = frozenset()+ self.status_payload = {+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ }++ self.activation_coordinator(+ MemoryArtifactCandidate(+ provider_root_format="everos-1.2.3",+ compatible_provider_root_formats=frozenset({"everos-1.2.3"}),+ artifact_fingerprint="first-install",+ ),+ MemoryProviderRootState(exists=False),+ commit,+ rollback,+ )+ return dict(self.ensure_payload)++@pytest.fixture(autouse=True)def _preflight_passes_by_default(monkeypatch: pytest.MonkeyPatch) -> None:"""Keep runtime lifecycle tests hermetic unless they exercise preflight."""@@ -2668,6 +2722,573 @@ async def test_runtime_install_artifact_uses_controller_owned_manager(await memory_runtime_factory.close(runtime)+async def test_runtime_install_activates_config_retained_after_missing_artifact(+ tmp_path: Path,+ memory_runtime_factory,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A first install must not wait for another process to retry reconciliation."""++ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ durable = MemoryConfig(enabled=True, processing=_processing_config())+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=durable,+ ).save()+ artifact = _FirstInstallArtifact()+ artifact.status_payload = {+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ }+ process_factory = FakeEverOSProcessFactory()+ runtime = memory_runtime_factory(+ MemoryConfig(enabled=False),+ artifact_manager=artifact,+ process_factory=process_factory,+ effective_home=tmp_path,+ )++ reconcile_result = await runtime.reconcile(MemoryConfig(enabled=False))++ assert reconcile_result == {"ok": False, "error": "memory_runtime_missing"}+ assert runtime._config == durable+ assert runtime._restart_config.enabled is False+ assert process_factory.supervised == []++ install_result = await runtime.install_artifact()++ assert install_result == {"ok": True, "reason": None, "download_error": None}+ assert artifact.commits == 1+ assert artifact.rollbacks == 0+ assert runtime._config == durable+ assert runtime._restart_config == durable+ assert len(process_factory.supervised) == 1+ assert process_factory.supervised[0].starts == 1+ await memory_runtime_factory.close(runtime)+++async def test_missing_artifact_defers_config_until_repair_retires_restart_authority(+ tmp_path: Path,+ memory_runtime_factory,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A childless retained supervisor still owns its previous launch settings."""++ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ active = MemoryConfig(enabled=True, processing=_processing_config())+ candidate = replace(+ active,+ processing=replace(+ active.processing,+ embedding=replace(active.processing.embedding, model="embed-v2"),+ ),+ )+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=candidate,+ ).save()+ artifact = _FirstInstallArtifact()+ artifact.status_payload = {+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ }+ process_factory = FakeEverOSProcessFactory()+ runtime = memory_runtime_factory(+ active,+ artifact_manager=artifact,+ process_factory=process_factory,+ effective_home=tmp_path,+ )+ restarting = FakeEverOSProcess(+ _running=False,+ _down=False,+ _desired_running=True,+ _restart_pending=True,+ )+ runtime._process = restarting+ monkeypatch.setattr(runtime, "_provider_data_exists_strict", lambda: False)++ assert await runtime.reconcile(active) == {+ "ok": False,+ "error": "memory_runtime_missing",+ }+ assert runtime._config == active+ assert runtime._restart_config == active+ assert runtime._process is restarting+ assert restarting.stopped is False++ assert await runtime.install_artifact() == {+ "ok": True,+ "reason": None,+ "download_error": None,+ }+ assert restarting.stopped is True+ assert runtime._config == candidate+ assert runtime._restart_config == candidate+ assert process_factory.supervised[0].settings is not None+ assert process_factory.supervised[0].settings.embedding_model == "embed-v2"+ await memory_runtime_factory.close(runtime)+++async def test_repair_rechecks_vectors_after_retiring_restart_authority(+ tmp_path: Path,+ memory_runtime_factory,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A delayed old-model write must block durable embedding adoption."""++ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ active = MemoryConfig(enabled=True, processing=_processing_config())+ durable = replace(+ active,+ processing=replace(+ active.processing,+ embedding=replace(active.processing.embedding, model="embed-v2"),+ ),+ )+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=durable,+ ).save()+ artifact = _FirstInstallArtifact()+ artifact.status_payload = {+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ }+ runtime = memory_runtime_factory(+ active,+ artifact_manager=artifact,+ effective_home=tmp_path,+ )+ restarting = FakeEverOSProcess(+ _running=False,+ _down=False,+ _desired_running=True,+ _restart_pending=True,+ )+ runtime._process = restarting+ vector_state = {"exists": False}+ monkeypatch.setattr(+ runtime,+ "_provider_data_exists_strict",+ lambda: vector_state["exists"],+ )++ assert await runtime.reconcile(active) == {+ "ok": False,+ "error": "memory_runtime_missing",+ }+ assert runtime._config == active++ # The retained supervisor can resume and write with the old embedding before+ # exhausting its restart budget. Repair must inspect that newer state only+ # after it has retired the supervisor and fenced claims.+ vector_state["exists"] = True+ assert await runtime.install_artifact() == {+ "ok": False,+ "reason": "memory_clear_failed",+ "download_error": None,+ }+ assert restarting.stopped is True+ assert runtime._process is None+ assert runtime._config == active+ assert runtime._restart_config == active+ assert artifact.ensure_calls == []+ await memory_runtime_factory.close(runtime)+++async def test_repair_rechecks_vectors_after_retiring_owned_descendants(+ tmp_path: Path,+ memory_runtime_factory,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """An unreaped old-model tree keeps its config until Stop proves it gone."""++ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ active = MemoryConfig(enabled=True, processing=_processing_config())+ durable = replace(+ active,+ processing=replace(+ active.processing,+ embedding=replace(active.processing.embedding, model="embed-v2"),+ ),+ )+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=durable,+ ).save()+ artifact = _FirstInstallArtifact()+ artifact.status_payload = {+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ }+ runtime = memory_runtime_factory(+ active,+ artifact_manager=artifact,+ effective_home=tmp_path,+ )+ retained_tree = FakeEverOSProcess(+ _running=False,+ _down=True,+ _desired_running=False,+ )+ retained_tree._process_tree_retained = True+ runtime._process = retained_tree+ vector_state = {"exists": False}+ monkeypatch.setattr(+ runtime,+ "_provider_data_exists_strict",+ lambda: vector_state["exists"],+ )++ assert await runtime.reconcile(active) == {+ "ok": False,+ "error": "memory_runtime_missing",+ }+ assert retained_tree.restart_authorized is False+ assert runtime._sidecar.snapshot().retains_active_config is True+ assert runtime._config == active++ vector_state["exists"] = True+ assert await runtime.install_artifact() == {+ "ok": False,+ "reason": "memory_clear_failed",+ "download_error": None,+ }+ assert retained_tree.stopped is True+ assert retained_tree.retains_active_config is False+ assert runtime._process is None+ assert runtime._config == active+ assert runtime._restart_config == active+ assert artifact.ensure_calls == []+ await memory_runtime_factory.close(runtime)+++async def test_missing_artifact_retains_active_config_until_rejected_child_is_gone(+ tmp_path: Path,+ memory_runtime_factory,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A live child keeps its captured config after restart authority is revoked."""++ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ active = MemoryConfig(enabled=True, processing=_processing_config())+ durable = replace(+ active,+ processing=replace(+ active.processing,+ embedding=replace(active.processing.embedding, model="embed-v2"),+ ),+ )+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=durable,+ ).save()+ artifact = _FirstInstallArtifact()+ artifact.status_payload = {+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ }+ process_factory = FakeEverOSProcessFactory()+ runtime = memory_runtime_factory(+ active,+ artifact_manager=artifact,+ process_factory=process_factory,+ effective_home=tmp_path,+ )+ rejected = FakeEverOSProcess(+ _running=True,+ _down=True,+ _desired_running=False,+ )+ runtime._process = rejected+ monkeypatch.setattr(runtime, "_provider_data_exists_strict", lambda: False)++ assert await runtime.reconcile(active) == {+ "ok": False,+ "error": "memory_runtime_missing",+ }+ assert rejected.restart_authorized is False+ assert runtime._sidecar.snapshot().retains_active_config is True+ assert runtime._config == active+ assert runtime._restart_config == active++ assert await runtime.install_artifact() == {+ "ok": False,+ "reason": "memory_runtime_install_requires_disabled_memory",+ "download_error": None,+ }+ assert rejected.stopped is False++ rejected._running = False+ assert await runtime.install_artifact() == {+ "ok": True,+ "reason": None,+ "download_error": None,+ }+ assert rejected.stopped is True+ assert runtime._config == durable+ assert runtime._restart_config == durable+ assert process_factory.supervised[0].settings is not None+ assert process_factory.supervised[0].settings.embedding_model == "embed-v2"+ await memory_runtime_factory.close(runtime)+++async def test_missing_artifact_publishes_config_from_cancelled_supervisor(+ tmp_path: Path,+ memory_runtime_factory,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A retained supervisor without launch authority cannot keep stale settings."""++ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ active = MemoryConfig(enabled=True, processing=_processing_config())+ durable = replace(+ active,+ processing=replace(+ active.processing,+ embedding=replace(active.processing.embedding, model="embed-v2"),+ ),+ )+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=durable,+ ).save()+ artifact = FakeMemoryArtifactManager(+ python=None,+ status_payload={+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ },+ )+ runtime = memory_runtime_factory(+ active,+ artifact_manager=artifact,+ effective_home=tmp_path,+ )+ cancelled = FakeEverOSProcess(+ _running=False,+ _down=False,+ _desired_running=False,+ )+ runtime._process = cancelled+ monkeypatch.setattr(runtime, "_provider_data_exists_strict", lambda: False)++ assert await runtime.reconcile(active) == {+ "ok": False,+ "error": "memory_runtime_missing",+ }+ assert cancelled.restart_authorized is False+ assert runtime._config == durable+ assert runtime._restart_config == active+ assert runtime._process is cancelled+ await memory_runtime_factory.close(runtime)+++async def test_missing_artifact_publishes_config_from_terminal_supervisor_for_install(+ tmp_path: Path,+ memory_runtime_factory,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A terminal supervisor cannot retain launch authority over desired config."""++ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ active = MemoryConfig(enabled=True, processing=_processing_config())+ durable = replace(+ active,+ processing=replace(+ active.processing,+ embedding=replace(active.processing.embedding, model="embed-v2"),+ ),+ )+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=durable,+ ).save()+ artifact = _FirstInstallArtifact()+ artifact.status_payload = {+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ }+ process_factory = FakeEverOSProcessFactory()+ runtime = memory_runtime_factory(+ active,+ artifact_manager=artifact,+ process_factory=process_factory,+ effective_home=tmp_path,+ )+ terminal = FakeEverOSProcess(_running=False, _down=True)+ runtime._process = terminal+ monkeypatch.setattr(runtime, "_provider_data_exists_strict", lambda: False)++ assert await runtime.reconcile(active) == {+ "ok": False,+ "error": "memory_runtime_missing",+ }+ assert runtime._config == durable+ assert runtime._restart_config == active+ assert runtime._process is terminal++ assert await runtime.install_artifact() == {+ "ok": True,+ "reason": None,+ "download_error": None,+ }+ assert terminal.stopped is True+ assert runtime._config == durable+ assert runtime._restart_config == durable+ assert process_factory.supervised[0].settings is not None+ assert process_factory.supervised[0].settings.embedding_model == "embed-v2"+ await memory_runtime_factory.close(runtime)+++async def test_first_install_keeps_artifact_when_immediate_config_probe_fails(+ tmp_path: Path,+ memory_runtime_factory,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Artifact admission and immediate desired-config activation are independent."""++ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ durable = MemoryConfig(enabled=True, processing=_processing_config())+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=durable,+ ).save()+ artifact = _FirstInstallArtifact()+ artifact.status_payload = {+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ }+ process_factory = FakeEverOSProcessFactory()+ runtime = memory_runtime_factory(+ MemoryConfig(enabled=False),+ artifact_manager=artifact,+ process_factory=process_factory,+ effective_home=tmp_path,+ )+ assert await runtime.reconcile(MemoryConfig(enabled=False)) == {+ "ok": False,+ "error": "memory_runtime_missing",+ }+ monkeypatch.setattr(+ runtime,+ "_probe_processing",+ lambda *_args: asyncio.sleep(0, result=False),+ )++ assert await runtime.install_artifact() == {+ "ok": True,+ "reason": None,+ "download_error": None,+ }+ assert artifact.commits == 1+ assert artifact.rollbacks == 0+ assert artifact.resolve_python() == Path(sys.executable)+ assert artifact.status()["installed"] is True+ assert runtime._config == durable+ assert runtime._restart_config.enabled is False+ assert runtime._runtime_error == "memory_processing_failed"+ assert process_factory.supervised == []+ await memory_runtime_factory.close(runtime)+++async def test_first_install_admits_retry_from_retained_supervisor(+ tmp_path: Path,+ memory_runtime_factory,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A first launch failure may recover under the retained desired settings."""++ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ durable = MemoryConfig(enabled=True, processing=_processing_config())+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=durable,+ ).save()+ artifact = _FirstInstallArtifact()+ artifact.status_payload = {+ "installed": False,+ "status": "missing",+ "reason": "memory_runtime_missing",+ }+ process_factory = FakeEverOSProcessFactory(+ template=lambda: FakeEverOSProcess(start_results=deque((False, True)))+ )+ runtime = memory_runtime_factory(+ MemoryConfig(enabled=False),+ artifact_manager=artifact,+ process_factory=process_factory,+ effective_home=tmp_path,+ )+ assert await runtime.reconcile(MemoryConfig(enabled=False)) == {+ "ok": False,+ "error": "memory_runtime_missing",+ }++ assert await runtime.install_artifact() == {+ "ok": True,+ "reason": None,+ "download_error": None,+ }+ recovering = process_factory.supervised[0]+ assert recovering.running is False+ assert runtime._config == durable+ assert runtime._restart_config == durable+ assert runtime.module._worker._claims_paused is True++ assert await recovering.start() is True+ await asyncio.wait_for(runtime._sidecar._ready_task, timeout=1.0)+ assert runtime._runtime_error is None+ assert runtime.module._worker._claims_paused is False+ assert runtime._worker_task is not None+ await memory_runtime_factory.close(runtime)++@pytest.mark.parametrize("recovery_intent", sorted(MEMORY_RECOVERY_INTENTS))async def test_runtime_repairs_artifact_without_activating_pending_recovery(tmp_path: Path,@@ -3177,8 +3798,17 @@ async def test_runtime_repair_stops_retained_down_supervisor_before_replacing_arllm=MemoryEndpointConfig("https://llm.example.test/v1", "chat", "llm-key"),embedding=MemoryEndpointConfig("https://embed.example.test/v1", "embed", "embed-key"),)+ config = MemoryConfig(enabled=True, processing=processing)+ V2Config(+ mode="self_host",+ version="v2",+ slack=SlackConfig(bot_token=""),+ runtime=RuntimeConfig(default_cwd="."),+ agents=AgentsConfig(),+ memory=config,+ ).save()runtime = memory_runtime_factory(- MemoryConfig(enabled=True, processing=processing),+ config,artifact_manager=_Artifact(root_format=None, fingerprint=None),effective_home=tmp_path,)