The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(relay): narrow foreign host conflict detection
Alex Fournier7d2d106d27b0
diff --git a/agent/relay_runtime.py b/agent/relay_runtime.pyindex db9f2db297e..580ecb8f647 100644--- a/agent/relay_runtime.py+++ b/agent/relay_runtime.py@@ -270,7 +270,7 @@ class _ProcessRelayPluginConfiguration:config_path = _configured_plugin_inputs()if config_path is None:return False- # Relay reads the explicit file in place of the user file; the system file still layers beneath it.+ # Relay replaces the user file with the explicit file, then applies the system file above it.activation = _resolve_plugin_awaitable(relay.plugin.initialize({}, additional_plugins_toml=config_path))if activation is None:raise RuntimeError("NeMo Relay plugin initialization returned no activation handle")@@ -1239,15 +1239,19 @@ def _configured_plugin_inputs() -> Path | None:) from exc-# Relay 0.9 exposes no active-host query; only initialize's Conflict message signals one.-_RELAY_HOST_CONFLICT_MARKERS = (- "plugin configuration is already active",- "owned by an active dynamic plugin host",+# Relay 0.9 exposes no active-host query; only initialize's two Conflict messages signal one.+_RELAY_HOST_CONFLICT_MESSAGES = frozenset(+ {+ "conflict: a static plugin configuration is already active; to combine static and dynamic plugins, "+ "provide the static components as the base configuration to dynamic plugin activation before calling "+ "plugin initialization",+ "conflict: plugin configuration is owned by an active dynamic plugin host",+ })def _is_relay_host_conflict(exc: BaseException) -> bool:- return isinstance(exc, RuntimeError) and any(marker in str(exc) for marker in _RELAY_HOST_CONFLICT_MARKERS)+ return isinstance(exc, RuntimeError) and str(exc) in _RELAY_HOST_CONFLICT_MESSAGESdef _resolve_plugin_awaitable(value: Any) -> Any:diff --git a/tests/agent/test_relay_runtime_plugins.py b/tests/agent/test_relay_runtime_plugins.pyindex 1683f987b93..422cfb08de8 100644--- a/tests/agent/test_relay_runtime_plugins.py+++ b/tests/agent/test_relay_runtime_plugins.py@@ -15,8 +15,9 @@ from agent import relay_runtimeHOST_CONFLICT = RuntimeError(- "a static plugin configuration is already active; to combine static and dynamic plugins, "- "provide the static components as the base configuration"+ "conflict: a static plugin configuration is already active; to combine static and dynamic plugins, "+ "provide the static components as the base configuration to dynamic plugin activation before calling "+ "plugin initialization")@@ -248,7 +249,7 @@ def test_foreign_active_plugin_configuration_is_left_unchanged(def test_dynamic_host_conflict_is_foreign_too(explicit_static_config, caplog):relay = _FakeRelay(initialize_error=RuntimeError(- "plugin configuration is owned by an active dynamic plugin host"+ "conflict: plugin configuration is owned by an active dynamic plugin host"))@@ -263,6 +264,57 @@ def test_dynamic_host_conflict_is_foreign_too(explicit_static_config, caplog):host.shutdown()+def test_plugin_error_containing_conflict_text_is_not_misclassified(+ explicit_static_config,+ caplog,+):+ relay = _FakeRelay(+ initialize_error=RuntimeError(+ "registration failed: plugin configuration is owned by an active dynamic plugin host"+ )+ )++ with caplog.at_level("WARNING"):+ host = relay_runtime.RelayRuntime(relay=relay, profile_key="profile")+ try:+ assert (+ host._plugin_configuration_state+ is relay_runtime._RelayPluginConfigurationState.FAILED+ )+ assert "Hermes Relay plugin initialization failed" in caplog.text+ assert "already active outside Hermes native ownership" not in caplog.text+ finally:+ host.shutdown()+++def test_real_binding_leaves_foreign_plugin_host_unchanged(+ explicit_static_config,+):+ relay = pytest.importorskip("nemo_relay")+ if getattr(relay, "_native", None) is None:+ pytest.skip("NeMo Relay native binding is unavailable on this platform")+ activation = relay_runtime._resolve_plugin_awaitable(+ relay.plugin.initialize(+ {},+ additional_plugins_toml=explicit_static_config,+ )+ )++ try:+ host = relay_runtime.RelayRuntime(relay=relay, profile_key="profile")+ try:+ assert (+ host._plugin_configuration_state+ is relay_runtime._RelayPluginConfigurationState.FOREIGN+ )+ assert activation.is_active+ finally:+ host.shutdown()+ assert activation.is_active+ finally:+ relay_runtime._resolve_plugin_awaitable(activation.close())++def test_legacy_exporter_env_without_plugins_toml_warns_and_stays_disabled(monkeypatch,caplog,