The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): left-core startup installs back off exponentially instead of hourly forever
Teknium3569e8461ea7
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex 5c7441e646c..69b96faebdd 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -10,8 +10,9 @@ reuses; memory is not a row because its plugin name comes from ``memory.provider* Agent start and gateway start retry once per process for the active home (Desktop users updatethrough the app and never run ``hermes update``), honouring ``security.allow_lazy_installs``.* After a failed attempt (catalog miss or unreachable, failed install) starts skip the row for- :data:`STARTUP_RETRY_SECONDS`, so an offline machine pays the network round trip once, not on every- ``hermes chat``; ``hermes update`` always retries.+ an hour, doubling with each further failure up to a week, so an offline+ machine pays the network round trip once, not on every ``hermes chat``, and a home whose install+ cannot succeed stops failing every hour; ``hermes update`` always retries.* A home gets the plugin automatically at most once (``_left_core_installed`` in its config.yaml):``hermes plugins remove`` afterwards is the user's choice and sticks.@@ -29,7 +30,7 @@ from pathlib import Pathfrom typing import Callable, Optionalfrom hermes_cli.memory_provider_migration import (- STARTUP_RETRY_SECONDS, _failed_recently, _home_consent, _home_label, _install_command, _interactive,+ _failed_recently, _home_consent, _home_label, _install_command, _interactive,_note_failure, _unattended_consent,)@@ -305,8 +306,8 @@ def _pending(home: Path, *, say: Callable[[str], None], process_env: bool = Falsif present:continueif 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)+ logger.info("%s plugin install failed recently for %s; retrying later or on `hermes update`",+ feature.label, home)continueif catalog_source(feature.plugin) is None:_note_failure(home, feature.plugin)diff --git a/hermes_cli/memory_provider_migration.py b/hermes_cli/memory_provider_migration.pyindex 94a4b8d62f0..3509a921ca7 100644--- a/hermes_cli/memory_provider_migration.py+++ b/hermes_cli/memory_provider_migration.py@@ -8,9 +8,9 @@ name, the settings it already read, its data directory and tool names, so the mijust rebuilt anyway).* agent init — when the configured provider cannot be found at all, once per process (Desktopusers 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.+ starts skip it for :data:`STARTUP_RETRY_SECONDS`, doubling with each further failure up to+ :data:`STARTUP_RETRY_MAX_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,@@ -35,28 +35,49 @@ _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"})+# The startup retry window doubles with each consecutive failure, up to a week: a flat window had a+# home whose install can never succeed (a version gate, a root-owned plugins dir, no route to GitHub)+# fail once an hour for good, while an offline laptop still gets its plugin within the hour.STARTUP_RETRY_SECONDS = 3600.0+STARTUP_RETRY_MAX_SECONDS = 7 * 24 * 3600.0def _failure_stamp(home: Path, plugin: str) -> Path:- """Touched on every failed automatic install; its mtime gates the next startup attempt."""+ """Written on every failed automatic install: its mtime and failure count gate the next startup attempt."""return home / "cache" / f"left-core-{plugin}.failed"+def _failure_count(stamp: Path) -> int:+ """Consecutive failures recorded in *stamp*; the empty stamp an older Hermes touched counts once."""+ try:+ text = stamp.read_text(encoding="utf-8-sig").strip()+ except OSError:+ return 0+ return int(text) if text.isdigit() else 1++def _note_failure(home: Path, plugin: str) -> None:stamp = _failure_stamp(home, plugin)try:stamp.parent.mkdir(parents=True, exist_ok=True)- stamp.touch()+ stamp.write_text(str(_failure_count(stamp) + 1), encoding="utf-8")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:+ stamp = _failure_stamp(home, plugin)try:- return time.time() - _failure_stamp(home, plugin).stat().st_mtime < STARTUP_RETRY_SECONDS+ age = time.time() - stamp.stat().st_mtimeexcept OSError:return False+ failures = min(_failure_count(stamp), 32)+ return age < min(STARTUP_RETRY_SECONDS * 2 ** (failures - 1), STARTUP_RETRY_MAX_SECONDS)+++def _note_success(home: Path, plugin: str) -> None:+ """A later failure (the plugin removed, then missed again) starts the backoff from an hour."""+ _failure_stamp(home, plugin).unlink(missing_ok=True)def configured_provider(home: Path) -> str:@@ -294,9 +315,11 @@ def recover_at_startup(name: str, *, say: Optional[Callable[[str], None]] = Nonereturn Falseif _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)}`.")+ f"Its automatic install failed recently: run `{_install_command(name, home)}`.")return Falseinstalled = migrate_home(home, install=_install_into(home, consent=True), say=report) == name- if not installed:+ if installed:+ _note_success(home, name)+ else:_note_failure(home, name)return installeddiff --git a/tests/hermes_cli/test_left_core_migration.py b/tests/hermes_cli/test_left_core_migration.pyindex 4924e9cddb9..63baebac701 100644--- a/tests/hermes_cli/test_left_core_migration.py+++ b/tests/hermes_cli/test_left_core_migration.py@@ -305,6 +305,45 @@ def test_a_failed_startup_install_backs_off_and_reports_one_line(tmp_path, monkeassert lookups == ["homeassistant", "homeassistant"]+def test_repeated_startup_failures_back_off_exponentially(tmp_path, monkeypatch):+ """A home whose install can never succeed (version gate, root-owned plugins dir, no route to+ GitHub) is retried after 1h, 2h, 4h ... up to a week, not every hour forever."""+ import os+ import time++ import hermes_cli.memory_provider_migration as mpm+ import pm.install+ home = _home(tmp_path, env="HASS_TOKEN=abc\n")+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr(pm.install, "lazy_installs_allowed", lambda: True)+ attempts = []+ monkeypatch.setattr(lcm, "_install_into", lambda h: lambda n: attempts.append(n) or {"ok": False, "error": "x"})+ stamp = mpm._failure_stamp(home, "homeassistant")++ def start_after(hours: float) -> None:+ then = time.time() - hours * 3600+ os.utime(stamp, (then, then))+ lcm._attempted.clear() # a fresh agent/gateway process+ lcm.recover_at_startup(say=lambda _m: None)++ lcm.recover_at_startup(say=lambda _m: None) # failure 1 → next try after 1h+ start_after(1.5) # failure 2 → next try after 2h+ assert len(attempts) == 2+ start_after(1.5) # inside the 2h window: no network+ assert len(attempts) == 2+ start_after(2.5) # failure 3 → 4h+ start_after(3.5)+ assert len(attempts) == 3+ stamp.write_text("40", encoding="utf-8") # capped at a week, never overflows+ start_after(24 * 6.9)+ assert len(attempts) == 3+ start_after(24 * 7.1)+ assert len(attempts) == 4+ stamp.write_text("", encoding="utf-8") # an older Hermes's empty stamp counts once+ start_after(1.5)+ assert len(attempts) == 5++@pytest.mark.parametrize(("auth_json", "config", "in_use"), [('{"providers": {"spotify": {"refresh_token": "r"}}}', "", True),('{"providers": {"spotify": {"access_token": "a"}}}', "", True),