The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(aux): the aux provider alias table is per profile home and registry generation
Tekniume936eacc45ff
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 527ba1c40b7..e2199a9b1b1 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -543,25 +543,23 @@ _LOCAL_SERVER_ALIASES = {"llama.cpp": "custom", "llama-cpp": "custom",}-_ALIAS_TABLE: Optional[dict[str, str]] = None+_ALIAS_TABLES: dict[str, tuple[int, dict[str, str]]] = {} # home key -> (registry generation, table)def _provider_alias_table() -> dict[str, str]:- """The same alias table the main provider path resolves against (hermes_cli.auth).-- A hand-copied mirror here rots silently every time auth grows a family — the local- servers (#106010) and the OpenCode entries were both missed that way. Local-server- names stay pinned on top: that set doubles as the guard for the /v1 tail and the- no-key-borrow rule in the custom branch below.- """- global _ALIAS_TABLE- if _ALIAS_TABLE is None:- merged: dict[str, str] = dict(_LOCAL_SERVER_ALIASES)+ """The alias table the main provider path resolves against (hermes_cli.auth), per home and registry+ generation: plugin aliases are per home. A hand-copied mirror rots silently (#106010); local-server+ names stay in: they guard the /v1 tail and the custom-branch no-key-borrow rule."""+ from providers import bound_registry_key+ home, generation = bound_registry_key()+ cached = _ALIAS_TABLES.get(home)+ if cached is None or cached[0] != generation:+ cached = (generation, dict(_LOCAL_SERVER_ALIASES))with contextlib.suppress(Exception):from hermes_cli.auth import _plugin_aliases- merged.update(_plugin_aliases())- _ALIAS_TABLE = merged- return _ALIAS_TABLE+ cached[1].update(_plugin_aliases())+ _ALIAS_TABLES[home] = cached+ return cached[1]def _normalize_aux_provider(provider: Optional[str]) -> str:normalized = (provider or "auto").strip().lower()diff --git a/providers/__init__.py b/providers/__init__.pyindex 177a9e5019a..776fc310efc 100644--- a/providers/__init__.py+++ b/providers/__init__.py@@ -268,6 +268,19 @@ def registry_generation() -> int:return _REGISTRY_GENERATION+def bound_registry_key() -> tuple[str, int]:+ """``(bound home key, registry generation)`` after the periodic plugin-dir check.++ Key for per-home memos of profile-derived answers: each profile home has its own plugins, and+ any registration (a plugin installed while the process runs) moves the generation.+ """+ if not _discovered:+ _discover_providers()+ layer, home, key = _bound_home_layer()+ _refresh_home_layer(layer, home, key)+ return key, _REGISTRY_GENERATION++def _host_claims(host: str, claimed: str) -> bool:claimed = str(claimed or "").strip().lower().rstrip(".")return bool(claimed) and (host == claimed or host.endswith("." + claimed))diff --git a/tests/agent/test_aux_alias_home_scope.py b/tests/agent/test_aux_alias_home_scope.pynew file mode 100644index 00000000000..ef26ba58632--- /dev/null+++ b/tests/agent/test_aux_alias_home_scope.py@@ -0,0 +1,84 @@+"""The aux provider alias table follows the bound profile home and later plugin installs.++It merges the plugin aliases of the home bound when it is built; memoized once per process, the+first home's aliases leaked into every other profile and a plugin installed while the process ran+never reached it (R4 H2).+"""++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="aliased-fake", aliases=("aliasy",), auth_type="api_key",+ env_vars=("ALIASED_FAKE_KEY",), base_url="https://aliased.invalid/v1"))+ """+)+++def _install(home: Path) -> None:+ plugin = home / "plugins" / "model-providers" / "aliased-fake"+ plugin.mkdir(parents=True)+ (plugin / "__init__.py").write_text(_PLUGIN, encoding="utf-8")+++def homes(tmp_path, monkeypatch):+ import providers+ from hermes_cli import auth_plugin_providers as app+ from hermes_cli.auth import PROVIDER_REGISTRY++ plugin_home, bare_home = tmp_path / "with_plugin", tmp_path / "bare"+ plugin_home.mkdir()+ bare_home.mkdir()+ monkeypatch.setenv("HERMES_HOME", str(bare_home))+ 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", {})+ monkeypatch.setattr(providers, "_PLUGIN_DIR_STAMP_TTL_SECONDS", 0.0)+ monkeypatch.setattr(app, "PLUGIN_MIRRORED_PROVIDERS", set(app.PLUGIN_MIRRORED_PROVIDERS))+ rows = list(dict.items(PROVIDER_REGISTRY))+ yield plugin_home, bare_home+ PROVIDER_REGISTRY.clear()+ PROVIDER_REGISTRY.update(rows)+ for mod in [m for m in sys.modules if m.startswith("_hermes_user_provider")]:+ del sys.modules[mod]+++def _normalize_in(home: Path, name: str) -> str:+ from agent.auxiliary_client import _normalize_aux_provider++ token = set_hermes_home_override(home)+ try:+ return _normalize_aux_provider(name)+ finally:+ reset_hermes_home_override(token)+++def test_alias_table_is_per_home_in_either_order(homes):+ plugin_home, bare_home = homes+ _install(plugin_home)++ assert _normalize_in(bare_home, "aliasy") == "aliasy"+ assert _normalize_in(plugin_home, "aliasy") == "aliased-fake"+ assert _normalize_in(bare_home, "aliasy") == "aliasy"+ assert _normalize_in(plugin_home, "aliasy") == "aliased-fake"+++def test_plugin_installed_while_running_reaches_the_alias_table(homes):+ _plugin_home, bare_home = homes++ assert _normalize_in(bare_home, "aliasy") == "aliasy"+ _install(bare_home)+ assert _normalize_in(bare_home, "aliasy") == "aliased-fake"