Skip to content

The agent that grows with you

fix(agent): a memory provider that is installed but fails to load says so

Tekniume75f6675ac80
diff --git a/agent/agent_init.py b/agent/agent_init.py
index f7b33f58754..b7e66eedd83 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -37,9 +37,7 @@ from agent.agent_init_ollama import _clamp_compressor_to_ollama_num_ctx, _config
from agent.primary_runtime_snapshot import _snapshot_primary_runtime
from agent.process_bootstrap import _install_safe_stdio
from agent.subdirectory_hints import SubdirectoryHintTracker
-from agent.agent_init_memory_warnings import (
- _unavailable_warning_key, _warn_memory_provider_unavailable, _warn_once, _warned_unavailable_providers,
-)
+from agent.agent_init_memory_provider import resolve_memory_provider
from agent.think_scrubber import StreamingThinkScrubber
from agent.tool_guardrails import (
ToolCallGuardrailConfig, ToolCallGuardrailController
@@ -1325,27 +1323,10 @@ def _init_memory(agent, _agent_cfg, skip_memory, platform, memory_manager=None):
_mem_provider_name = mem_config.get("provider", "") if mem_config else ""
if not is_core_memory_provider(_mem_provider_name):
from agent.memory_manager import MemoryManager as _MemoryManager
- from plugins.memory import load_memory_provider as _load_mem, parked_provider_notice
agent._memory_manager = _MemoryManager()
- _mp = _load_mem(_mem_provider_name)
- _parked = _mp is None and parked_provider_notice(_mem_provider_name)
- if _parked:
- # Installed but turned off (by the user or by an update): say so, never re-install it.
- _warn_once(_mem_provider_name, _parked, say=agent._emit_startup_warning)
- elif _mp is None:
- # The provider left core for the catalog (or was never installed): fetch it once.
- from hermes_cli.memory_provider_migration import recover_at_startup
- if recover_at_startup(_mem_provider_name, say=agent._emit_startup_warning):
- _mp = _load_mem(_mem_provider_name)
- if _mp and _mp.is_available():
+ _mp = resolve_memory_provider(_mem_provider_name, say=agent._emit_startup_warning)
+ if _mp is not None:
agent._memory_manager.add_provider(_mp)
- elif _mp is not None and _unavailable_warning_key(_mem_provider_name) not in _warned_unavailable_providers:
- # unavailable_reason() reads config/probes importlib — skip it once warned.
- _unavailable_reason = ""
- with suppress(Exception):
- _unavailable_reason = _mp.unavailable_reason()
- _warn_memory_provider_unavailable(
- _mem_provider_name, _unavailable_reason, say=agent._emit_startup_warning)
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)
diff --git a/agent/agent_init_memory_provider.py b/agent/agent_init_memory_provider.py
new file mode 100644
index 00000000000..432e11003ee
--- /dev/null
+++ b/agent/agent_init_memory_provider.py
@@ -0,0 +1,85 @@
+"""Resolve the configured memory provider at agent init, telling the user once why it will not run."""
+
+from __future__ import annotations
+
+import logging
+
+logger = logging.getLogger("run_agent")
+
+
+# Deduped: the gateway builds a fresh AIAgent per message, so it would warn every turn.
+_warned_unavailable_providers: set[tuple[str, str]] = set()
+
+
+def _unavailable_warning_key(name: str) -> tuple[str, str]:
+ """Once per profile home and provider: one multiplexed gateway/Desktop backend serves several
+ profiles, and each one running without its memory must be told."""
+ from hermes_constants import get_hermes_home, hermes_home_key
+ return hermes_home_key(get_hermes_home()), name
+
+
+def _warn_once(name: str, message: str, say=None) -> None:
+ """Log *message* and hand it to the user's sink once per home and provider."""
+ key = _unavailable_warning_key(name)
+ if key in _warned_unavailable_providers:
+ return
+ _warned_unavailable_providers.add(key)
+ logger.warning(message)
+ if say is not None:
+ say(message)
+
+
+def _warn_memory_provider_unavailable(name: str, reason: str = "", say=None) -> None:
+ """Warn once per home and provider that a configured memory provider is unavailable.
+
+ ``is_available()`` is a side-effect-free hot-path check and can't log itself; without this
+ the provider is silently dropped. ``reason`` (the provider's ``unavailable_reason()`` hint)
+ can only reach the user here, so it is appended when present. *say* is the agent's
+ user-facing sink: a log line alone leaves the user running without memory unaware.
+ """
+ _warn_once(name, (
+ f"⚠ Memory provider {name!r} is selected but reports unavailable — external memory "
+ "is disabled for this session (built-in memory still works). Check the "
+ "provider's credentials/config with 'hermes memory status'. Note: "
+ "systemd/gateway services do not inherit ~/.hermes/.env automatically; set "
+ f"any required variables in the service environment.{f' {reason}' if reason else ''}"
+ ), say=say)
+
+
+def resolve_memory_provider(name: str, say=None):
+ """The configured provider ready to add, or None after telling the user why not (once per home)."""
+ from plugins.memory import find_provider_dir, load_memory_provider, parked_provider_notice
+
+ provider = load_memory_provider(name)
+ if provider is None:
+ parked = parked_provider_notice(name)
+ if parked:
+ # Installed but turned off (by the user or by an update): say so, never re-install it.
+ _warn_once(name, parked, say=say)
+ return None
+ # The provider left core for the catalog (or was never installed): fetch it once.
+ from hermes_cli.memory_provider_migration import recover_at_startup
+ reported: list[str] = []
+
+ def relay(message: str) -> None:
+ reported.append(message)
+ if say is not None:
+ say(message)
+
+ if recover_at_startup(name, say=relay):
+ provider = load_memory_provider(name)
+ if provider is None and not reported and find_provider_dir(name) is not None:
+ _warn_once(name, f"⚠ Memory provider '{name}' is installed but failed to load, so external memory is off "
+ "for this session (built-in memory still works). The log names the error; "
+ "`hermes memory status` shows the plugin's state.", say=say)
+ if provider is None or provider.is_available():
+ return provider
+ if _unavailable_warning_key(name) not in _warned_unavailable_providers:
+ # unavailable_reason() reads config/probes importlib — skip it once warned.
+ reason = ""
+ try:
+ reason = provider.unavailable_reason()
+ except Exception: # health: allow BLE001 -- a provider's own hint must never break agent init
+ logger.debug("unavailable_reason() failed for %s", name, exc_info=True)
+ _warn_memory_provider_unavailable(name, reason, say=say)
+ return None
diff --git a/agent/agent_init_memory_warnings.py b/agent/agent_init_memory_warnings.py
deleted file mode 100644
index b334fe93afd..00000000000
--- a/agent/agent_init_memory_warnings.py
+++ /dev/null
@@ -1,46 +0,0 @@
-"""Startup warnings for a configured memory provider that will not run this session."""
-
-from __future__ import annotations
-
-import logging
-
-logger = logging.getLogger("run_agent")
-
-
-# Deduped: the gateway builds a fresh AIAgent per message, so it would warn every turn.
-_warned_unavailable_providers: set[tuple[str, str]] = set()
-
-
-def _unavailable_warning_key(name: str) -> tuple[str, str]:
- """Once per profile home and provider: one multiplexed gateway/Desktop backend serves several
- profiles, and each one running without its memory must be told."""
- from hermes_constants import get_hermes_home, hermes_home_key
- return hermes_home_key(get_hermes_home()), name
-
-
-def _warn_once(name: str, message: str, say=None) -> None:
- """Log *message* and hand it to the user's sink once per home and provider."""
- key = _unavailable_warning_key(name)
- if key in _warned_unavailable_providers:
- return
- _warned_unavailable_providers.add(key)
- logger.warning(message)
- if say is not None:
- say(message)
-
-
-def _warn_memory_provider_unavailable(name: str, reason: str = "", say=None) -> None:
- """Warn once per home and provider that a configured memory provider is unavailable.
-
- ``is_available()`` is a side-effect-free hot-path check and can't log itself; without this
- the provider is silently dropped. ``reason`` (the provider's ``unavailable_reason()`` hint)
- can only reach the user here, so it is appended when present. *say* is the agent's
- user-facing sink: a log line alone leaves the user running without memory unaware.
- """
- _warn_once(name, (
- f"⚠ Memory provider {name!r} is selected but reports unavailable — external memory "
- "is disabled for this session (built-in memory still works). Check the "
- "provider's credentials/config with 'hermes memory status'. Note: "
- "systemd/gateway services do not inherit ~/.hermes/.env automatically; set "
- f"any required variables in the service environment.{f' {reason}' if reason else ''}"
- ), say=say)
diff --git a/tests/agent/test_memory_provider_unavailable_warning.py b/tests/agent/test_memory_provider_unavailable_warning.py
index 653f285a1e2..e1d8e9e0bff 100644
--- a/tests/agent/test_memory_provider_unavailable_warning.py
+++ b/tests/agent/test_memory_provider_unavailable_warning.py
@@ -8,7 +8,9 @@ service that didn't inherit ``~/.hermes/.env``) used to be dropped silently.
import logging
-from agent import agent_init_memory_warnings as agent_init
+import pytest
+
+from agent import agent_init_memory_provider as agent_init
def test_warns_once_and_dedupes(caplog):
@@ -44,3 +46,27 @@ def test_provider_reason_is_appended(caplog):
warnings = [r for r in caplog.records if "unavailable" in r.getMessage()]
assert len(warnings) == 1
assert hint in warnings[0].getMessage()
+
+
+def test_parked_provider_is_reported_and_never_reinstalled(monkeypatch):
+ """A provider that plugins.disabled parks (by the user, or by an update that could not install it)
+ is reported once with how to turn it back on and the update's reason; it is never re-installed."""
+ from hermes_cli import memory_provider_migration
+ from hermes_constants import get_hermes_home
+
+ home = get_hermes_home()
+ plugin = home / "plugins" / "parkedmem"
+ plugin.mkdir(parents=True)
+ (plugin / "__init__.py").write_text("from agent.memory_provider import MemoryProvider\n", encoding="utf-8")
+ (home / "config.yaml").write_text(
+ "memory:\n provider: parkedmem\nplugins:\n disabled: [parkedmem]\n disabled_by_update:\n"
+ " parkedmem: {enabled: true, reason: requires Python <3.14}\n", encoding="utf-8")
+ monkeypatch.setattr(memory_provider_migration, "recover_at_startup",
+ lambda *args, **kwargs: pytest.fail("a parked provider must not be re-installed"))
+ agent_init._warned_unavailable_providers.clear()
+ said: list[str] = []
+
+ assert agent_init.resolve_memory_provider("parkedmem", say=said.append) is None
+ assert agent_init.resolve_memory_provider("parkedmem", say=said.append) is None
+ assert len(said) == 1
+ assert "hermes plugins enable parkedmem" in said[0] and "requires Python <3.14" in said[0]