Skip to content

The agent that grows with you

fix(relay): keep error diagnostics fatal and validate the exact payload

mschwabc7b2198a3815
diff --git a/agent/relay_runtime.py b/agent/relay_runtime.py
index 0cbe9333d72..db9f2db297e 100644
--- a/agent/relay_runtime.py
+++ b/agent/relay_runtime.py
@@ -270,9 +270,7 @@ class _ProcessRelayPluginConfiguration:
config_path = _configured_plugin_inputs()
if config_path is None:
return False
- # The explicit file is the whole payload, static components and [[plugins.dynamic]]
- # alike; Relay resolves it in place of user-file discovery and hands back the
- # activation that owns every plugin it loaded.
+ # Relay reads the explicit file in place of the user file; the system file still layers beneath 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")
@@ -1241,8 +1239,7 @@ def _configured_plugin_inputs() -> Path | None:
) from exc
-# Relay 0.9 has no query for an active plugin host; the only signal is initialize refusing the
-# lease. These are the two PluginError::Conflict messages it raises for that.
+# 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",
diff --git a/hermes_cli/relay_plugin_migrate.py b/hermes_cli/relay_plugin_migrate.py
index 8ddc9642edf..29c0887ee8a 100644
--- a/hermes_cli/relay_plugin_migrate.py
+++ b/hermes_cli/relay_plugin_migrate.py
@@ -125,13 +125,17 @@ def dumps_toml(document: Mapping[str, Any]) -> str:
def validate_relay_plugin_payload(payload: Mapping[str, Any]) -> list:
- """Run the payload through Relay's own validator; returns the diagnostics (empty = clean).
- Raises when Relay rejects the document outright."""
+ """Run the payload through Relay's own validator; returns the warnings (empty = clean).
+ Raises when Relay rejects the document, including by error-level diagnostics."""
from nemo_relay import plugin
- report = plugin.validate(dict(payload))
- config_report = report.get("config") if isinstance(report, dict) else None
- return list((config_report or {}).get("diagnostics") or []) if isinstance(config_report, dict) else []
+ # Exact: the runtime loads this document as the explicit file, never layered over the
+ # ambient user config that plain validate() would discover.
+ diagnostics = list(plugin.validate_exact(dict(payload))["config"]["diagnostics"])
+ # Relay 0.8 raised on these from initialize(); 0.9's validator reports them instead.
+ if errors := [d for d in diagnostics if d.get("level") == "error"]:
+ raise ValueError("; ".join(str(d.get("message") or d.get("code") or d) for d in errors))
+ return diagnostics
def _comment_out_legacy_lines(lines: list[str], names: set[str]) -> list[str]:
diff --git a/tests/agent/test_relay_tools.py b/tests/agent/test_relay_tools.py
index 760aa7335b8..ba10bf9726d 100644
--- a/tests/agent/test_relay_tools.py
+++ b/tests/agent/test_relay_tools.py
@@ -76,8 +76,8 @@ def test_request_rewrite_reaches_authorized_callback_once(relay_turn):
def rewrite_request(_name, args):
return {**args, "path": "/approved/path"}
- async def wrap_execution(_name, args, next_call):
- result = await next_call(args)
+ async def wrap_execution(context, next_call):
+ result = await next_call(context.args)
return relay.ToolExecutionInterceptOutcome(
{**result.result, "wrapped": True},
annotation={"audit": "annotation-canary"},
diff --git a/tests/hermes_cli/test_relay_plugin_migrate.py b/tests/hermes_cli/test_relay_plugin_migrate.py
index 9a2e74bc25b..7c0c80e6546 100644
--- a/tests/hermes_cli/test_relay_plugin_migrate.py
+++ b/tests/hermes_cli/test_relay_plugin_migrate.py
@@ -9,7 +9,8 @@ from pathlib import Path
import pytest
from hermes_cli.relay_plugin_migrate import (
- RELAY_PLUGINS_TOML_NAME, migrate_all_profile_relay_envs, migrate_profile_relay_env)
+ RELAY_PLUGINS_TOML_NAME, migrate_all_profile_relay_envs, migrate_profile_relay_env,
+ validate_relay_plugin_payload)
from hermes_cli.relay_plugin_cutover import RELAY_PLUGINS_CONFIG_ENV, configured_legacy_relay_env_vars
nemo_relay = pytest.importorskip("nemo_relay")
@@ -56,8 +57,9 @@ def test_legacy_env_becomes_validated_toml_selected_from_env(profile_env):
sink = document["components"][0]["config"]["atof"]["sinks"][0]
assert sink["type"] == "file" and sink["filename"] == "hermes-atof.jsonl"
assert document["components"][0]["config"]["atif"]["filename_template"] == "trajectory-{session_id}.json"
- # Relay itself accepts the file Hermes will load at runtime.
- report = nemo_relay.plugin.validate(document)
+ # Relay itself accepts the file Hermes will load at runtime, through the same layer
+ # set the runtime uses: the explicit file, not the ambient user config.
+ report = nemo_relay.plugin.validate({}, additional_plugins_toml=toml_path)
assert report["config"]["diagnostics"] == []
# .env now selects the file; the legacy lines survive as comments (not deleted), so the
# runtime warning + doctor finding go quiet and a second run is a no-op.
@@ -86,3 +88,45 @@ def test_update_migrates_every_profile_home_separately(profile_env):
assert not results[profile_env].migrated and not (profile_env / RELAY_PLUGINS_TOML_NAME).exists()
assert _parse_env(work / ".env")[RELAY_PLUGINS_CONFIG_ENV] == str(work / RELAY_PLUGINS_TOML_NAME)
assert (idle / ".env").read_text(encoding="utf-8") == "SLACK_BOT_TOKEN=y\n"
+
+
+def _relay_report(*diagnostics):
+ return {"config": {"diagnostics": list(diagnostics)}, "config_paths": [], "dynamic_plugins": []}
+
+
+def test_error_diagnostics_reject_the_payload_like_relay_0_8_did(monkeypatch):
+ monkeypatch.setattr(
+ nemo_relay.plugin,
+ "validate_exact",
+ lambda _payload: _relay_report(
+ {"level": "warning", "code": "unknown_field", "message": "unknown field 'x'"},
+ {"level": "error", "code": "unsupported_value", "message": "atof.mode 'nope' is unsupported"},
+ ),
+ )
+
+ with pytest.raises(ValueError, match="atof.mode 'nope' is unsupported"):
+ validate_relay_plugin_payload({"version": 1})
+
+
+def test_warning_diagnostics_are_returned_not_raised(monkeypatch):
+ warning = {"level": "warning", "code": "unknown_field", "message": "unknown field 'x'"}
+ monkeypatch.setattr(nemo_relay.plugin, "validate_exact", lambda _payload: _relay_report(warning))
+
+ assert validate_relay_plugin_payload({"version": 1}) == [warning]
+
+
+def test_error_diagnostics_leave_env_untouched(profile_env, monkeypatch):
+ (profile_env / ".env").write_text(LEGACY_ENV.format(home=profile_env), encoding="utf-8")
+ before = (profile_env / ".env").read_text(encoding="utf-8")
+ monkeypatch.setattr(
+ nemo_relay.plugin,
+ "validate_exact",
+ lambda _payload: _relay_report({"level": "error", "code": "bad", "message": "rejected"}),
+ )
+
+ result = migrate_profile_relay_env(profile_env)
+
+ assert not result.migrated
+ assert result.validation_error == "ValueError: rejected"
+ assert (profile_env / ".env").read_text(encoding="utf-8") == before
+ assert not (profile_env / RELAY_PLUGINS_TOML_NAME).exists()
diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.md
index 7178b375120..50999d9eac1 100644
--- a/website/docs/developer-guide/relay-shared-metrics.md
+++ b/website/docs/developer-guide/relay-shared-metrics.md
@@ -39,7 +39,19 @@ than downloading a different implementation.
Operator-supplied typed native plugins must be rebuilt for Relay 0.9. `grpc-v1`
workers must be regenerated and rebuilt when they use tool callbacks, tool
-execution intercepts, or manual tool-end APIs.
+execution intercepts, or manual tool-end APIs. Tool execution intercepts now
+receive a `ToolExecutionContext` instead of separate name and argument values.
+
+Hermes passes the selected file to Relay as the explicit plugin configuration.
+Relay reads it in place of the ambient user `plugins.toml`, but the
+operator-managed system file (`/etc/nemo-relay/plugins.toml`, or the
+`%ProgramData%` equivalent) still layers beneath it, so a system-wide exporter
+or policy applies to Hermes too.
+
+Relay 0.9 has no query for whether another process already owns the plugin
+host. Hermes learns that only when its own initialization is refused, so a
+foreign activation is reported as such only when Hermes has a plugin
+configuration selected; without one, Hermes stays disabled and does not probe.
When Relay managed execution is active, the provider request and response pass
through that native module in the Hermes process so configured interceptors can