The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(memory): a failed agent-start provider install is not retried by every process start
Teknium6a2909c6b119
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex 1ca831d87b9..4dc83a89cc0 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -24,13 +24,13 @@ Desktop, chat); a gateway-start outcome waits for the home's first agent to delifrom __future__ import annotationsimport logging-import timefrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Callable, Optionalfrom hermes_cli.memory_provider_migration import (- _home_consent, _home_label, _install_command, _interactive, _unattended_consent,+ STARTUP_RETRY_SECONDS, _failed_recently, _home_consent, _home_label, _install_command, _interactive,+ _note_failure, _unattended_consent,)logger = logging.getLogger(__name__)@@ -274,30 +274,6 @@ def _record_migration(home: Path, feature: LeftCoreFeature) -> None:atomic_config_write(path, config)-STARTUP_RETRY_SECONDS = 3600.0---def _failure_stamp(home: Path, feature: LeftCoreFeature) -> Path:- """Touched on every failed automatic install; its mtime gates the next startup attempt."""- return home / "cache" / f"left-core-{feature.plugin}.failed"---def _note_failure(home: Path, feature: LeftCoreFeature) -> None:- stamp = _failure_stamp(home, feature)- try:- stamp.parent.mkdir(parents=True, exist_ok=True)- stamp.touch()- except OSError as exc:- logger.debug("left-core retry stamp not written for %s: %s", home, exc)---def _failed_recently(home: Path, feature: LeftCoreFeature) -> bool:- try:- return time.time() - _failure_stamp(home, feature).stat().st_mtime < STARTUP_RETRY_SECONDS- except OSError:- return False--def _pending(home: Path, *, say: Callable[[str], None], process_env: bool = False,backoff: bool = False) -> list[LeftCoreFeature]:"""Rows *home* uses whose plugin it never had and that the catalog ships (a catalog miss is@@ -322,12 +298,12 @@ def _pending(home: Path, *, say: Callable[[str], None], process_env: bool = Falscontinueif present:continue- if backoff and _failed_recently(home, feature):+ if backoff and _failed_recently(home, feature.plugin):logger.info("%s plugin install failed recently for %s; retrying after %ds or on `hermes update`",feature.label, home, STARTUP_RETRY_SECONDS)continueif catalog_source(feature.plugin) is None:- _note_failure(home, feature)+ _note_failure(home, feature.plugin)say(f" ⚠ {feature.label} moved out of core into the '{feature.plugin}' plugin, which this "f"Hermes cannot find in the plugin catalog yet. Run `{_install_command(feature.plugin, home)}` "f"once it is listed.")@@ -371,7 +347,7 @@ def _install_one(home: Path, feature: LeftCoreFeature, *, install: Callable[[strsay(f" ✓ {feature.label} moved out of core — installed the '{feature.plugin}' plugin from the "f"catalog ({feature.unchanged}).")return True- _note_failure(home, feature)+ _note_failure(home, feature.plugin)error = _first_cause(str(result.get("error") or ""))say(f" ⚠ {feature.label} moved out of core and its '{feature.plugin}' plugin could not be installed "f"automatically: {error}. Run `{_install_command(feature.plugin, home)}`.")diff --git a/hermes_cli/memory_provider_migration.py b/hermes_cli/memory_provider_migration.pyindex 4624d73837e..94a4b8d62f0 100644--- a/hermes_cli/memory_provider_migration.py+++ b/hermes_cli/memory_provider_migration.py@@ -7,7 +7,10 @@ name, the settings it already read, its data directory and tool names, so the mi* ``hermes update`` — for every profile home that shares the venv (primary; runs where the venv wasjust rebuilt anyway).* agent init — when the configured provider cannot be found at all, once per process (Desktop- users update through the app and never run ``hermes update`` by hand).+ users update through the app and never run ``hermes update`` by hand). After a failed attempt,+ starts skip it for :data:`STARTUP_RETRY_SECONDS` (``hermes update`` always retries): every+ ``hermes chat``, cron run and Desktop restart otherwise paid the network round trip again and+ showed the same failure.Both install the catalog entry at its reviewed pin through the normal plugin install path (killlist, dependency constraints, enable), never a custom source. Every outcome — installed, refused,@@ -19,6 +22,7 @@ from __future__ import annotationsimport loggingimport sys+import timefrom pathlib import Pathfrom typing import Callable, Optional@@ -31,6 +35,29 @@ _attempted: set[tuple[str, str]] = set()# (a synced config, a cloned profile) still needs an explicit install._LEFT_CORE = frozenset({"hindsight", "honcho", "mem0", "supermemory", "openviking", "retaindb", "byterover", "holographic"})+STARTUP_RETRY_SECONDS = 3600.0+++def _failure_stamp(home: Path, plugin: str) -> Path:+ """Touched on every failed automatic install; its mtime gates the next startup attempt."""+ return home / "cache" / f"left-core-{plugin}.failed"+++def _note_failure(home: Path, plugin: str) -> None:+ stamp = _failure_stamp(home, plugin)+ try:+ stamp.parent.mkdir(parents=True, exist_ok=True)+ stamp.touch()+ except OSError as exc:+ logger.debug("left-core retry stamp not written for %s: %s", home, exc)+++def _failed_recently(home: Path, plugin: str) -> bool:+ try:+ return time.time() - _failure_stamp(home, plugin).stat().st_mtime < STARTUP_RETRY_SECONDS+ except OSError:+ return False+def configured_provider(home: Path) -> str:"""``memory.provider`` of *home*'s effective config, or ``""``."""@@ -265,4 +292,11 @@ def recover_at_startup(name: str, *, say: Optional[Callable[[str], None]] = Nonef"It never shipped with Hermes, so Hermes installs it only when you ask: "f"run `{_install_command(name, home)}`.")return False- return migrate_home(home, install=_install_into(home, consent=True), say=report) == name+ if _failed_recently(home, name):+ report(f"⚠ Memory provider '{name}' is not installed, so external memory is off for this session. "+ f"Its automatic install failed less than an hour ago: run `{_install_command(name, home)}`.")+ return False+ installed = migrate_home(home, install=_install_into(home, consent=True), say=report) == name+ if not installed:+ _note_failure(home, name)+ return installeddiff --git a/tests/hermes_cli/test_memory_provider_migration.py b/tests/hermes_cli/test_memory_provider_migration.pyindex 4a0fa049b4d..3797ba71ff0 100644--- a/tests/hermes_cli/test_memory_provider_migration.py+++ b/tests/hermes_cli/test_memory_provider_migration.py@@ -292,3 +292,26 @@ def test_recovery_copy_without_a_catalog_memory_entry_keeps_the_generic_hint(tmpassert mig.catalog_install_hint("no-such-provider") is Nonedoctor_state._memory_provider_generic("no-such-provider")assert "run: hermes memory setup" in capsys.readouterr().out+++def test_startup_recovery_backs_off_after_a_failed_install(tmp_path, monkeypatch):+ """A failed agent-start install is not retried by every following process start (each `hermes chat`,+ cron run, Desktop restart): one failure, then a quiet hour; `hermes update` still retries."""+ from pm import install as pm_install++ (tmp_path / "config.yaml").write_text("memory:\n provider: hindsight\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ monkeypatch.setattr(mig, "catalog_source", lambda n: n)+ monkeypatch.setattr(pm_install, "lazy_installs_allowed", lambda: True)+ attempts: list[str] = []+ monkeypatch.setattr(mig, "_install_into", lambda home, **_kw: (lambda n: attempts.append(n) or {"ok": False, "error": "uv lock exited 1"}))+ said: list[str] = []+ for _process in range(3):+ monkeypatch.setattr(mig, "_attempted", set()) # a fresh process each time+ assert mig.recover_at_startup("hindsight", say=said.append) is False+ assert attempts == ["hindsight"]+ assert "`hermes plugins install hindsight`" in said[-1] # still told memory is off, and the fix+ monkeypatch.setattr(mig, "STARTUP_RETRY_SECONDS", 0.0)+ monkeypatch.setattr(mig, "_attempted", set())+ mig.recover_at_startup("hindsight")+ assert attempts == ["hindsight", "hindsight"]diff --git a/website/docs/user-guide/features/memory-providers.md b/website/docs/user-guide/features/memory-providers.mdindex 821cf09d8e8..0fbd364a308 100644--- a/website/docs/user-guide/features/memory-providers.md+++ b/website/docs/user-guide/features/memory-providers.md@@ -538,7 +538,7 @@ Hindsight used to ship inside the Hermes tree (and as the `hermes-agent[hindsigh- `hermes update` installs the catalog plugin into every profile home that names the provider. Each line names the profile it is about. In a terminal it asks before preparing the plugin's Python dependencies; when several profiles use the provider, the questions are asked once and the answers apply to all of them. Without a terminal (the Desktop app, a script, a service) nobody can answer, so each profile prepares them unattended when its `security.allow_lazy_installs` is on (the default); a profile with it off gets the exact `hermes -p <profile> plugins install hindsight` command instead, and the other profiles still migrate.- If the plugin is still missing on the first agent start (`hermes chat`, Desktop, the gateway, …), Hermes installs it, dependencies included, and shows ``✓ Memory provider 'hindsight' moved out of core — installed its plugin from the catalog (memory.provider and your stored memories are unchanged; check its settings with `hermes memory status`).`` Messaging platforms get the line with the first reply.-- When the agent-start install cannot happen, you see why instead of silently running without external memory: with `security.allow_lazy_installs: false` the warning names the install command for that profile; offline or declined installs show the error and the same command.+- When the agent-start install cannot happen, you see why instead of silently running without external memory: with `security.allow_lazy_installs: false` the warning names the install command for that profile; offline or declined installs show the error and the same command. After a failed attempt, agent starts in the next hour skip the install and only repeat the command; `hermes update` always retries.- Agent start never asks a question (the chat prompt owns the terminal). A catalog provider that never shipped with Hermes (for example `mnemosyne`) is therefore not installed on agent start: the warning names `hermes plugins install <name>` for that profile, or install it from the dashboard/Desktop Plugins page.What changes on disk: the plugin appears in `~/.hermes/plugins/hindsight/` and `config.yaml` gains `plugins.enabled: [hindsight]`. `memory.provider`, `$HERMES_HOME/hindsight/config.json`, `HINDSIGHT_API_KEY` in `.env` and your memory bank data are untouched. Verify with `hermes memory status` (provider active) and `hermes plugins list` (plugin installed and enabled).