mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
Symptom: a model-provider plugin installed with `hermes plugins install` (e.g. claude-subscription-directsdk) worked from a terminal but the Desktop app failed every session build with "Unknown provider '<name>'". Cause: `providers/__init__.py` scanned `$HERMES_HOME/plugins` exactly once per process, under whichever profile home happened to be bound at the first lookup, and the registry was global. The Desktop backend and the multiplex gateway serve several profiles from one process, so any profile other than the first-discovered one never saw its own plugins, and a plugin installed while the process ran was invisible until a restart. Change: bundled, pip and legacy providers stay process-wide; `$HERMES_HOME` plugins load into a per-home layer keyed by `hermes_home_key()` at lookup time (`get_provider_profile`, `list_providers`, `provider_source`). The layer rescans when the plugin directories' mtimes change, so a fresh install is found on the next lookup. The registration target is a ContextVar so two turn threads scanning two homes cannot cross-register, and no lock is held across plugin imports (a lock there could deadlock against a thread mid-`import hermes_cli.auth`). Per-home module names let two profiles carry the same plugin. `plugin_dev` reuses the module-name helper. Live repro (tui_gateway `session.create` on a secondary profile whose config selects a plugin installed only there): base -> agent_error "Unknown provider 'fakeprov-b'"; fixed -> provider resolves and the build proceeds to the plugin's own runtime check.
92 lines
3.5 KiB
Python
92 lines
3.5 KiB
Python
"""``$HERMES_HOME`` model-provider plugins resolve for the profile home bound at lookup time (#88143).
|
|
|
|
One process serves several profiles (multiplex gateway, Desktop ``serve``); discovery used to read the
|
|
plugins of whichever home was bound first and never look again, so a plugin installed in a secondary
|
|
profile was ``Unknown provider`` from Desktop while ``hermes -p <profile>`` in a terminal worked.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import textwrap
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from hermes_constants import reset_hermes_home_override, set_hermes_home_override
|
|
|
|
_PLUGIN = textwrap.dedent(
|
|
"""
|
|
from providers import register_provider
|
|
from providers.base import ProviderProfile
|
|
|
|
register_provider(ProviderProfile(name="{name}", aliases=("{name}-alias",), auth_type="external_process",
|
|
base_url="process://{name}", api_mode="chat_completions"))
|
|
"""
|
|
)
|
|
|
|
|
|
def _install(home: Path, name: str) -> None:
|
|
plugin = home / "plugins" / name
|
|
plugin.mkdir(parents=True)
|
|
(plugin / "plugin.yaml").write_text(f"name: {name}\nkind: model-provider\n", encoding="utf-8")
|
|
(plugin / "__init__.py").write_text(_PLUGIN.format(name=name), encoding="utf-8")
|
|
|
|
|
|
@pytest.fixture
|
|
def homes(tmp_path, monkeypatch):
|
|
import providers
|
|
|
|
launch = tmp_path / "launch"
|
|
secondary = tmp_path / "profiles" / "scaleup"
|
|
launch.mkdir()
|
|
secondary.mkdir(parents=True)
|
|
monkeypatch.setenv("HERMES_HOME", str(launch))
|
|
monkeypatch.setattr(providers, "_REGISTRY", dict(providers._REGISTRY))
|
|
monkeypatch.setattr(providers, "_ALIASES", dict(providers._ALIASES))
|
|
monkeypatch.setattr(providers, "_PROVIDER_LIST_CACHE", None)
|
|
monkeypatch.setattr(providers, "_HOME_LAYERS", {}, raising=False)
|
|
yield launch, secondary
|
|
for mod in [m for m in sys.modules if m.startswith("_hermes_user_provider")]:
|
|
del sys.modules[mod]
|
|
|
|
|
|
def _bound(home: Path, fn):
|
|
token = set_hermes_home_override(home)
|
|
try:
|
|
return fn()
|
|
finally:
|
|
reset_hermes_home_override(token)
|
|
|
|
|
|
def test_secondary_profile_plugin_resolves_for_its_home_only(homes):
|
|
import providers
|
|
from hermes_cli.auth import resolve_provider
|
|
|
|
launch, secondary = homes
|
|
_install(secondary, "scaleup-only")
|
|
|
|
assert providers.get_provider_profile("scaleup-only") is None # launch home discovers first
|
|
|
|
assert _bound(secondary, lambda: providers.get_provider_profile("scaleup-only")) is not None
|
|
assert _bound(secondary, lambda: providers.get_provider_profile("scaleup-only-alias")) is not None
|
|
assert _bound(secondary, lambda: providers.provider_source("scaleup-only")) == "user"
|
|
assert "scaleup-only" in _bound(secondary, lambda: {p.name for p in providers.list_providers()})
|
|
# The agent-build gate Desktop hits (``Unknown provider`` came from here).
|
|
assert _bound(secondary, lambda: resolve_provider("scaleup-only")) == "scaleup-only"
|
|
|
|
# Profiles are islands: the launch home still does not see the secondary's install.
|
|
assert providers.get_provider_profile("scaleup-only") is None
|
|
assert "scaleup-only" not in {p.name for p in providers.list_providers()}
|
|
|
|
|
|
def test_plugin_installed_after_discovery_is_found_without_a_restart(homes):
|
|
import providers
|
|
|
|
launch, _ = homes
|
|
assert providers.get_provider_profile("late-install") is None
|
|
|
|
_install(launch, "late-install")
|
|
|
|
assert providers.get_provider_profile("late-install") is not None
|
|
assert "late-install" in {p.name for p in providers.list_providers()}
|