The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(left-core): a provider plugin that failed to load gets its import error, never "enable it"
Tekniuma6f834def168
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex afd30be26a1..6d34f0b88c8 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -137,23 +137,29 @@ def spotify_in_use(home: Path, *, process_env: bool = False) -> bool:return _toolset_listed(_read_config(home), frozenset({"spotify"}))-def _bundled_plugin_selected(home: Path, plugin: str) -> bool:- """*plugin*'s bundled copy was on for *home*: its key or name in ``plugins.enabled`` and neither in- ``plugins.disabled`` (which wins, as in the loader), read with the managed overlay applied like the- loader's config, so an administrator's pinned list counts."""+def _plugin_lists(home: Path, plugin: str) -> tuple[bool, bool]:+ """Whether *plugin*'s key or name is in *home*'s ``plugins.enabled`` / ``plugins.disabled``, read with the+ managed overlay applied like the loader's config, so an administrator's pinned list counts."""from gateway import config_loaderfeature = next(f for f in LEFT_CORE if f.plugin == plugin)try:plugins = config_loader.read_yaml_layers(home).get("plugins")except Exception: # malformed config.yaml: the loader enables nothing from it eitherlogger.debug("left-core: unreadable config for %s", home, exc_info=True)- return False+ return False, Falseplugins = plugins if isinstance(plugins, dict) else {}def listed(key: str) -> bool:names = plugins.get(key)return isinstance(names, list) and any(str(n) in (feature.plugin_key, feature.plugin) for n in names)- return listed("enabled") and not listed("disabled")+ return listed("enabled"), listed("disabled")+++def _bundled_plugin_selected(home: Path, plugin: str) -> bool:+ """*plugin*'s bundled copy was on for *home*: in ``plugins.enabled`` and not in ``plugins.disabled``+ (which wins, as in the loader)."""+ enabled, disabled = _plugin_lists(home, plugin)+ return enabled and not disableddef langfuse_in_use(home: Path, *, process_env: bool = False) -> bool:@@ -540,8 +546,8 @@ def _provider_feature(name: str) -> Optional[LeftCoreFeature]:def provider_install_hint(name: str) -> str:"""For a provider name nothing resolves to that a left-core plugin supplies: the sentence naming its- install command for the active home (its enable command when installed but not enabled; its load error and- update command when enabled but it failed to load), else ``""``.+ install command for the active home (its enable command when installed but disabled; its load error and+ update command when installed but it failed to load), else ``""``.Appended to every "unknown provider" error (runtime resolution, ``/model``, ``hermes model``, ``hermesauth add``)."""feature = _provider_feature(name)@@ -552,21 +558,20 @@ def provider_install_hint(name: str) -> str:if not plugin_present(feature.plugin, home):return f"{_install_sentence(feature)}."command = _install_command(feature.plugin, home)- if _bundled_plugin_selected(home, feature.plugin): # enabled, yet no profile: its load failed- error = _load_error(feature)- return (f"{feature.label} moved out of core into the '{feature.plugin}' plugin, which is enabled but failed "- f"to load{f' ({error})' if error else ''}: run `{command.replace(' install ', ' update ')}`, or "- f"see `hermes logs` for the cause.")- return (f"{feature.label} moved out of core into the '{feature.plugin}' plugin, which is installed but not "- f"loaded: run `{command.replace(' install ', ' enable ')}`.")+ if _plugin_lists(home, feature.plugin)[1]:+ return (f"{feature.label} moved out of core into the '{feature.plugin}' plugin, which is installed but "+ f"disabled: run `{command.replace(' install ', ' enable ')}`.")+ # A model-provider plugin loads without plugins.enabled: present, not disabled and no profile = its load failed.+ error = _load_error(feature)+ return (f"{feature.label} moved out of core into the '{feature.plugin}' plugin, which is installed but failed "+ f"to load{f' ({error})' if error else ''}: run `{command.replace(' install ', ' update ')}`, or "+ f"see `hermes logs` for the cause.")def _load_error(feature: LeftCoreFeature) -> str:- """The plugin loader's recorded error for *feature*'s plugin in this process, else ``""``."""- from hermes_cli.plugins import get_plugin_manager- names = {feature.plugin, feature.plugin_key} - {""}- return next((str(p["error"]) for p in get_plugin_manager().list_plugins()- if p.get("error") and names & {p.get("name"), p.get("key")}), "")+ """The error *feature*'s provider plugin raised on import in the active home, else ``""``."""+ from providers import plugin_load_error+ return plugin_load_error(feature.plugin)def provider_left_core(name: str) -> bool:diff --git a/providers/__init__.py b/providers/__init__.pyindex 57ab4354ae3..8d91bd6a411 100644--- a/providers/__init__.py+++ b/providers/__init__.py@@ -83,6 +83,8 @@ class _HomeLayer:stamp_checked_at: float | None = None# name -> when its miss last forced a stamp check (see ``_miss_recheck_due``)misses: dict[str, float] = field(default_factory=dict)+ # plugin dir name -> the error its import raised (``plugin_load_error``), until an import succeeds+ errors: dict[str, str] = field(default_factory=dict)_HOME_LAYERS: dict[str, _HomeLayer] = {}@@ -596,6 +598,7 @@ def _import_hosted_plugin_dir(plugin_dir: Path, source: str, module_name: str) -register_provider(profile)except Exception as exc: # health: allow BLE001 -- plugin load boundary (moved from _import_plugin_dir): one broken plugin never breaks discoverylogger.warning("Failed to load user provider plugin %s in the plugin host: %s", plugin_dir.name, exc)+ _note_load_result(plugin_dir, exc)returnfinally:_current_source = None@@ -626,15 +629,35 @@ def _exec_plugin_module(plugin_dir: Path, source: str, module_name: str) -> Nonemodule = importlib.util.module_from_spec(spec)sys.modules[module_name] = modulespec.loader.exec_module(module)+ _note_load_result(plugin_dir, None)except Exception as exc: # health: allow BLE001 -- plugin import boundary (moved from _import_plugin_dir): one broken plugin never breaks discoverylogger.warning("Failed to load %s provider plugin %s: %s", source, plugin_dir.name, exc)sys.modules.pop(module_name, None)+ _note_load_result(plugin_dir, exc)finally:_current_source = None+def _note_load_result(plugin_dir: Path, exc: BaseException | None) -> None:+ """Record (or clear) a ``$HERMES_HOME`` plugin's import error on the home layer importing it: the+ general plugin manager lists a model-provider dir with no error, so this is the only record of why it+ registered nothing."""+ layer = _REGISTRATION_TARGET.get()+ if layer is None: # bundled: process-wide, never a home's plugin+ return+ if exc is None:+ layer.errors.pop(plugin_dir.name, None)+ else:+ layer.errors[plugin_dir.name] = f"{type(exc).__name__}: {exc}"+++def plugin_load_error(plugin: str) -> str:+ """The error the bound home's provider plugin dir *plugin* raised on its last import, else ``""``."""+ return _home_layer().errors.get(plugin, "")++def _discover_entry_point_providers() -> None:"""Import pip-installed provider plugins via the ``hermes_agent.plugins``entry-point group so they self-register.diff --git a/tests/hermes_cli/test_left_core_provider_rows.py b/tests/hermes_cli/test_left_core_provider_rows.pyindex da2669d63e0..99c7982197b 100644--- a/tests/hermes_cli/test_left_core_provider_rows.py+++ b/tests/hermes_cli/test_left_core_provider_rows.py@@ -175,22 +175,25 @@ def test_unknown_left_core_provider_names_the_install_on_every_surface(acme_row)for text in (str(err.value), str(_unknown_provider_exit("acme")), _unknown_provider_message("ACME")):assert "Acme LLM moved out of core into the 'acme-llm' plugin" in textassert "hermes plugins install acme-llm" in text- (acme_row / "plugins" / "acme-llm").mkdir(parents=True) # installed but not loaded- assert "hermes plugins enable acme-llm" in lcm.provider_install_hint("acme")+ (acme_row / "plugins" / "acme-llm").mkdir(parents=True)+ (acme_row / "config.yaml").write_text("model:\n provider: acme\nplugins:\n disabled: [acme-llm]\n",+ encoding="utf-8")+ assert "hermes plugins enable acme-llm" in lcm.provider_install_hint("acme") # installed but disabledassert lcm.provider_install_hint("other") == ""-def test_an_enabled_plugin_that_failed_to_load_gets_its_error_not_enable(acme_row, monkeypatch):- from types import SimpleNamespace- from hermes_cli import plugins- (acme_row / "plugins" / "acme-llm").mkdir(parents=True)- (acme_row / "config.yaml").write_text("model:\n provider: acme\nplugins:\n enabled: [acme-llm]\n",- encoding="utf-8")- monkeypatch.setattr(plugins, "get_plugin_manager", lambda: SimpleNamespace(list_plugins=lambda: [- {"name": "acme-llm", "key": "acme-llm", "enabled": False, "error": "ImportError: cannot import name 'x'"}]))[email protected]("listed", ["", "plugins:\n enabled: [acme-llm]\n"])+def test_a_provider_plugin_that_failed_to_load_gets_its_error_not_enable(acme_row, listed):+ """A model-provider plugin loads without `plugins.enabled`: installed, not disabled and no profile means+ its import failed. The hint carries the error providers discovery recorded for this home."""+ plugin = acme_row / "plugins" / "acme-llm"+ plugin.mkdir(parents=True)+ (plugin / "plugin.yaml").write_text("name: acme-llm\nkind: model-provider\n", encoding="utf-8")+ (plugin / "__init__.py").write_text("from acme_sdk import client\n", encoding="utf-8")+ (acme_row / "config.yaml").write_text("model:\n provider: acme\n" + listed, encoding="utf-8")hint = lcm.provider_install_hint("acme")- assert "ImportError: cannot import name 'x'" in hint and "hermes plugins update acme-llm" in hint- assert "enable" not in hint.replace("enabled", "")+ assert "ModuleNotFoundError: No module named 'acme_sdk'" in hint and "hermes plugins update acme-llm" in hint+ assert "enable" not in hintdef test_runtime_resolution_installs_the_plugin_first_for_a_home_using_it(acme_row, monkeypatch):