The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(memory): tell the user when a shared provider instance is dropped for their profile
unsupportedpastels4007e7b76f68
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex 027ff1dad02..80fa34d9242 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -1368,8 +1368,8 @@ def _init_memory(agent, _agent_cfg, skip_memory, platform, memory_manager=None):_unavailable_reason = _mp.unavailable_reason()_warn_memory_provider_unavailable(_mem_provider_name, _unavailable_reason, say=agent._emit_startup_warning)- if agent._memory_manager.providers:- agent._memory_manager.initialize_all(**_memory_provider_init_kwargs(agent, platform))+ if agent._memory_manager.providers and agent._memory_manager.initialize_for_agent(+ say=agent._emit_startup_warning, **_memory_provider_init_kwargs(agent, platform)):_ra().logger.info("Memory provider '%s' activated", _mem_provider_name)else:_ra().logger.debug("Memory provider '%s' not found or not available", _mem_provider_name)diff --git a/agent/memory_manager.py b/agent/memory_manager.pyindex f27fe5ec9e2..a9956ef888d 100644--- a/agent/memory_manager.py+++ b/agent/memory_manager.py@@ -852,6 +852,19 @@ class MemoryManager:_SYNC_DRAIN_TIMEOUT_S, abandoned_writes, abandoned_prefetches, active_tasks,)+ def initialize_for_agent(self, say: Optional[Callable[[str], None]] = None, **kwargs) -> bool:+ """``initialize_all`` for an agent build; True while an external provider is still served. One+ refused as another profile's shared instance is dropped, and ``say`` (the agent's startup+ warning sink) tells the user this profile now runs without it."""+ before = [p for p in self._providers if p.name != "builtin"]+ self.initialize_all(**kwargs)+ for provider in (p for p in before if not any(p is kept for kept in self._providers)):+ message = (f"⚠ Memory provider {provider.name!r} is disabled for this profile: it handed out the "+ "provider instance another profile already uses. Built-in memory still works; the "+ "operator can see why with `hermes logs errors`.")+ (say or logger.warning)(message)+ return self._has_external+def initialize_all(self, session_id: str, **kwargs) -> None:"""Initialize all providers, injecting ``hermes_home`` so they resolve profile-scoped paths."""if "hermes_home" not in kwargs:diff --git a/tests/agent/test_memory_provider_caller_profile.py b/tests/agent/test_memory_provider_caller_profile.pyindex 439d72467b5..19100b049de 100644--- a/tests/agent/test_memory_provider_caller_profile.py+++ b/tests/agent/test_memory_provider_caller_profile.py@@ -421,6 +421,31 @@ def test_one_provider_instance_is_never_served_to_a_second_profile(homes, multipassert "memory_provider_instance_shared" in logged and str(beta_home) in logged, logged+def test_agent_whose_provider_instance_is_refused_is_told_and_runs_without_it(homes, multiplexed, monkeypatch, caplog):+ # The real agent-build path: the refused provider is dropped, the user sees a startup warning, and+ # nothing claims the provider "activated".+ import logging++ from agent import agent_init+ from tests.agent.test_memory_migration_notifications import StartupAgent+ alpha_home, beta_home = homes+ shared = _InstanceScopedProvider()+ _manager(alpha_home, shared)+ monkeypatch.setattr("plugins.memory.load_memory_provider", lambda name: shared)+ monkeypatch.setattr(agent_init, "_memory_provider_init_kwargs", lambda agent, platform: {+ "session_id": "s-beta", "platform": platform, "hermes_home": str(beta_home)})+ agent = StartupAgent("api_server")+ with _Scope(beta_home), caplog.at_level(logging.DEBUG):+ agent_init._init_memory(agent, {"memory": {"provider": "instancescoped"}}, False, "api_server")+ assert agent._memory_manager is None+ assert not any("activated" in r.getMessage() for r in caplog.records)+ notices = []+ agent.notice_callback = notices.append+ agent._replay_startup_warnings()+ assert len(notices) == 1 and notices[0].level == "warn" and "instancescoped" in notices[0].text, notices+ assert str(alpha_home) not in notices[0].text and str(beta_home) not in notices[0].text++class _UnhashableProvider(_InstanceScopedProvider):__hash__ = None