The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: every profile a multiplex gateway serves gets its left-core plugin before its adapters start
teknium1c63bc3dcbd4a
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex 6d4fd3f43e6..fe9cb453288 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -1123,11 +1123,8 @@ def _init_fallback_chain(agent, fallback_model):def _load_tools(agent, enabled_toolsets, disabled_toolsets):# A feature that left core for a catalog plugin (Home Assistant) is installed for a home that# used it, once per process, before discovery so its tools are in this agent's snapshot.- try:- from hermes_cli.left_core_migration import recover_at_startup as _recover_left_core- _recover_left_core(say=agent._emit_startup_warning)- except Exception:- logger.debug("left-core plugin migration skipped", exc_info=True)+ from hermes_cli.left_core_migration import recover_at_startup+ recover_at_startup(say=agent._emit_startup_warning)# A multiplexed gateway may have switched HERMES_HOME since model_tools was imported;# make sure this profile's plugins are discovered before the tool snapshot.try:diff --git a/gateway/run.py b/gateway/run.pyindex 313c02a1080..c2733ae906d 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -5862,13 +5862,8 @@ async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool =_start_gateway_configure_logging(verbosity)- # A platform that left core for a catalog plugin (Home Assistant) must be installed before the- # runner loads platform config; the outcome is logged and handed to this home's first agent.- try:- from hermes_cli.left_core_migration import recover_at_startup as _recover_left_core- await asyncio.to_thread(_recover_left_core)- except Exception:- logger.debug("left-core plugin migration skipped", exc_info=True)+ from gateway.run_startup import recover_left_core_at_gateway_start+ await asyncio.to_thread(recover_left_core_at_gateway_start) # before the runner loads platform configrunner = GatewayRunner(config)# Multiplex: swap the launch-home file handlers for per-profile routers so each profile's recordsdiff --git a/gateway/run_adapters.py b/gateway/run_adapters.pyindex 7c2f8109ec2..d705c429c2a 100644--- a/gateway/run_adapters.py+++ b/gateway/run_adapters.py@@ -1059,6 +1059,9 @@ class GatewayAdapterLifecycleMixin:from hermes_cli.env_loader import hydrate_profile_secret_sources# Hydrate external secret sources off-loop ONCE: sync hydration would stall every heartbeat.await asyncio.to_thread(hydrate_profile_secret_sources, profile_home)+ # A platform that left core for a catalog plugin is installed before discovery below.+ from gateway.run_startup import recover_left_core_in+ await asyncio.to_thread(recover_left_core_in, profile_home, hydrate_secrets=False)with _profile_runtime_scope(profile_home, hydrate_secrets=False):profile_runtime_cfg = _load_gateway_config()from hermes_cli.plugins import discover_plugins, get_plugin_managerdiff --git a/gateway/run_startup.py b/gateway/run_startup.pyindex dc9963721d9..a20ba923f33 100644--- a/gateway/run_startup.py+++ b/gateway/run_startup.py@@ -37,6 +37,29 @@ from typing import Any, Dict, Optional, Tuplelogger = logging.getLogger("gateway.run")+def recover_left_core_in(home: Path, *, hydrate_secrets: bool = True) -> None:+ """Install the catalog plugin of every feature that left core (Home Assistant) *home* uses, in+ *home*'s runtime scope (its config, secrets and allow_lazy_installs); once per process per home.+ Blocking: call it off the event loop."""+ from gateway.run import _profile_runtime_scope+ from hermes_cli.left_core_migration import recover_at_startup+ with _profile_runtime_scope(Path(home), hydrate_secrets=hydrate_secrets):+ recover_at_startup()+++def recover_left_core_at_gateway_start() -> None:+ """Left-core migration for the homes whose platform config the runner loads first: the launch+ home and the default root (the multiplex primary; a named launcher is then served as a+ secondary). Every secondary runs :func:`recover_left_core_in` before its plugins are discovered,+ so a platform plugin it gets starts its adapter in the same gateway start."""+ from hermes_cli.left_core_migration import recover_at_startup+ from hermes_constants import get_default_hermes_root, get_hermes_home+ recover_at_startup()+ root = Path(get_default_hermes_root())+ if root.resolve() != Path(get_hermes_home()).resolve():+ recover_left_core_in(root)++class GatewayStartupMixin:"""Startup sequence, resume/restore and handoff methods for GatewayRunner."""diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex 4472de6356e..0cb243e4ed0 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -100,6 +100,8 @@ class LeftCoreFeature:toolsets: tuple[str, ...] = ()# Platforms whose core default composite (``hermes-<platform>``) never carried those toolsets.off_platforms: tuple[str, ...] = ()+ # Gateway platform the plugin ships: a running gateway serves it only after a restart.+ platform: str = ""LEFT_CORE: tuple[LeftCoreFeature, ...] = (@@ -107,7 +109,7 @@ LEFT_CORE: tuple[LeftCoreFeature, ...] = (plugin="homeassistant", label="Home Assistant", in_use=homeassistant_in_use,unchanged="HASS_TOKEN/HASS_URL, platforms.homeassistant and the ha_* tool names are unchanged",secret_env=("HASS_TOKEN",), private_env=("HASS_URL",),- toolsets=("homeassistant",), off_platforms=("acp", "webhook"),+ toolsets=("homeassistant",), off_platforms=("acp", "webhook"), platform="homeassistant",),)@@ -274,6 +276,15 @@ def migrate_all_homes(*, say: Callable[[str], None] = print) -> list[str]:return installed+def _gateway_serves(home: Path) -> bool:+ """A live gateway serves *home*: it loaded its platforms before this agent-start install."""+ try:+ from gateway.status import resolve_gateway_liveness+ return resolve_gateway_liveness(profile_dir=home, use_cache=False).running+ except Exception:+ return False++def recover_at_startup(*, say: Optional[Callable[[str], None]] = None) -> list[str]:"""Agent/gateway start hook for the active home: one attempt per process per home. With *say*(an agent's startup-warning sink) outcomes are delivered now, together with any a gateway-start@@ -320,6 +331,8 @@ def recover_at_startup(*, say: Optional[Callable[[str], None]] = None) -> list[sfor feature in features:if _install_one(home, feature, install=_install_into(home), say=report):installed.append(feature.plugin)+ if say is not None and feature.platform and _gateway_serves(home):+ report(f"Restart the gateway (`hermes gateway restart`) so it serves {feature.label}.")return installedexcept Exception as exc: # never take agent/gateway start downlogger.warning("left-core plugin migration failed: %s", exc, exc_info=True)