Skip to content

The agent that grows with you

fix(memory): surface startup migration outcomes through warning sink

funky-xamarin80c87376db13
diff --git a/agent/agent_init.py b/agent/agent_init.py
index 4a043f66fdf..c08727d99df 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -1367,7 +1367,7 @@ def _init_memory(agent, _agent_cfg, skip_memory, platform, memory_manager=None):
if _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):
+ if recover_at_startup(_mem_provider_name, say=agent._emit_warning):
_mp = _load_mem(_mem_provider_name)
if _mp and _mp.is_available():
agent._memory_manager.add_provider(_mp)
diff --git a/hermes_cli/memory_provider_migration.py b/hermes_cli/memory_provider_migration.py
index 121a19e7ebc..ef5d262b68a 100644
--- a/hermes_cli/memory_provider_migration.py
+++ b/hermes_cli/memory_provider_migration.py
@@ -126,7 +126,7 @@ def migrate_all_homes(*, say: Callable[[str], None] = print) -> list[str]:
return installed
-def recover_at_startup(name: str) -> bool:
+def recover_at_startup(name: str, *, say: Optional[Callable[[str], None]] = None) -> bool:
"""Agent-init hook for a configured provider that resolved nowhere. One attempt per process per
home and name; honours ``security.allow_lazy_installs`` because it installs code. True when installed."""
from hermes_constants import get_hermes_home, hermes_home_key
@@ -136,9 +136,18 @@ def recover_at_startup(name: str) -> bool:
if key in _attempted:
return False
_attempted.add(key)
+
+ def report(message: str) -> None:
+ logger.warning(message)
+ if say is not None:
+ try:
+ say(message)
+ except Exception:
+ logger.debug("Memory migration notification failed", exc_info=True)
+
from pm.install import lazy_installs_allowed
if not lazy_installs_allowed():
- logger.warning("Memory provider '%s' is not installed; security.allow_lazy_installs is off — "
- "run `hermes plugins install %s`.", name, name)
+ report(f"Memory provider '{name}' is not installed; security.allow_lazy_installs is off — "
+ f"run `hermes plugins install {name}`.")
return False
- return migrate_home(home, install=_install_into(home), say=logger.warning) == name
+ return migrate_home(home, install=_install_into(home), say=report) == name
diff --git a/tests/agent/test_memory_migration_notifications.py b/tests/agent/test_memory_migration_notifications.py
new file mode 100644
index 00000000000..0896f893c1f
--- /dev/null
+++ b/tests/agent/test_memory_migration_notifications.py
@@ -0,0 +1,85 @@
+"""Startup migration outcomes reach the existing gated warning sink."""
+import pytest
+
+from agent.agent_init import _init_memory
+from agent.status_output import StatusOutputMixin
+from hermes_cli import memory_provider_migration as mig
+
+
+class StartupAgent(StatusOutputMixin):
+ enabled_toolsets = []
+ disabled_toolsets = []
+ platform = "cli"
+ log_prefix = ""
+ quiet_mode = False
+ status_callback = None
+ tools = []
+ valid_tool_names = set()
+
+ def _vprint(self, message, **kwargs):
+ print(message)
+
+
+def startup_home(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ monkeypatch.setattr(mig, "_attempted", set())
+ (tmp_path / "config.yaml").write_text(
+ "security:\n allow_lazy_installs: false\nmemory:\n provider: scout_missing_provider\n",
+ encoding="utf-8",
+ )
+ return tmp_path
+
+
[email protected]("show", [True, False])
+def test_startup_refusal_reaches_gated_cli_sink(startup_home, capsys, monkeypatch, show):
+ agent = StartupAgent()
+ monkeypatch.setattr(agent, "_warning_presentation_enabled", lambda: show)
+ _init_memory(agent, {"memory": {"provider": "scout_missing_provider"}}, False, "cli")
+ output = capsys.readouterr().out
+ assert ("hermes plugins install scout_missing_provider" in output) is show
+ assert agent._memory_manager is None
+ assert not (startup_home / "plugins").exists()
+
+
[email protected]("outcome", ["success", "unknown", "error", "present"])
+def test_recovery_outcomes_keep_log_and_return_contract(startup_home, monkeypatch, caplog, outcome):
+ monkeypatch.setattr("tools.lazy_deps._allow_lazy_installs", lambda: True)
+ monkeypatch.setattr(mig, "provider_present", lambda name, home: outcome == "present")
+ monkeypatch.setattr(mig, "catalog_source", lambda name: None if outcome == "unknown" else name)
+ calls = []
+
+ def install(name):
+ calls.append(name)
+ if outcome == "error":
+ raise RuntimeError("offline fixture")
+ return {"ok": True}
+
+ monkeypatch.setattr(mig, "_install_into", lambda home: install)
+ said = []
+ result = mig.recover_at_startup("scout_missing_provider", say=said.append)
+ assert result is (outcome == "success")
+ assert len(said) == (0 if outcome == "present" else 1)
+ assert calls == (["scout_missing_provider"] if outcome in {"success", "error"} else [])
+ if said:
+ assert said[0] in caplog.text
+ assert mig.recover_at_startup("scout_missing_provider", say=said.append) is False
+ assert len(said) == (0 if outcome == "present" else 1)
+
+
+def test_broken_presentation_does_not_undo_success(startup_home, monkeypatch, caplog):
+ monkeypatch.setattr("tools.lazy_deps._allow_lazy_installs", lambda: True)
+ monkeypatch.setattr(mig, "provider_present", lambda name, home: False)
+ monkeypatch.setattr(mig, "catalog_source", lambda name: name)
+ monkeypatch.setattr(mig, "_install_into", lambda home: lambda name: {"ok": True})
+
+ def broken(message):
+ raise RuntimeError("presentation unavailable")
+
+ assert mig.recover_at_startup("scout_missing_provider", say=broken) is True
+ assert "installed its plugin" in caplog.text
+
+
+def test_default_caller_retains_logging(startup_home, caplog):
+ assert mig.recover_at_startup("scout_missing_provider") is False
+ assert "security.allow_lazy_installs is off" in caplog.text