Skip to content

The agent that grows with you

fix(a2a): resolve the inbound enablement gate through the profile-scoped reader

JE4NVRG68c205b5b9a7
diff --git a/plugins/platforms/a2a/__init__.py b/plugins/platforms/a2a/__init__.py
index a67c86ccd82..9b8213db7fc 100644
--- a/plugins/platforms/a2a/__init__.py
+++ b/plugins/platforms/a2a/__init__.py
@@ -4,7 +4,6 @@ five outbound client tools of the ``a2a`` toolset through the public PluginConte
from __future__ import annotations
import logging
-import os
logger = logging.getLogger(__name__)
@@ -34,9 +33,18 @@ def validate_config(config) -> bool:
def is_connected(config) -> bool:
- """'Connected' when explicitly enabled (the gateway only instantiates enabled platforms)."""
+ """'Connected' when explicitly enabled (the gateway only instantiates enabled platforms).
+
+ ``A2A_PORT`` resolves through the shared scope-aware reader. A bare ``os.getenv`` hands every
+ secondary profile the DEFAULT profile's port under multiplexing, so each of them instantiates
+ an inbound server, the first one binds and every other profile dies with ``bind_failed``.
+ """
extra = getattr(config, "extra", {}) or {}
- return bool(extra.get("enabled")) or bool(os.getenv("A2A_PORT"))
+ if extra.get("enabled"):
+ return True
+ from gateway.platforms._shared import env_is_connected
+
+ return env_is_connected("A2A_PORT")(config)
def interactive_setup() -> None:
diff --git a/tests/plugins/test_a2a_plugin.py b/tests/plugins/test_a2a_plugin.py
index 48e90656d1e..ea66510c0f2 100644
--- a/tests/plugins/test_a2a_plugin.py
+++ b/tests/plugins/test_a2a_plugin.py
@@ -35,6 +35,46 @@ def _free_port() -> int:
return port
+# --------------------------------------------------------------------------
+# Enablement gate (profile scope)
+# --------------------------------------------------------------------------
+
+class TestConnectionGateScope:
+ """``A2A_PORT`` decides whether the inbound server starts, so it must resolve through the
+ profile-scoped reader. A bare ``os.getenv`` hands every secondary profile the DEFAULT
+ profile's port under multiplexing: all of them instantiate, the first binds and the rest
+ die with ``bind_failed``."""
+
+ def test_missing_scoped_port_is_not_connected(self, monkeypatch):
+ import hermes_cli.gateway as gw
+ from plugins.platforms import a2a
+
+ seen: list[str] = []
+
+ def fake_get_env_value(key: str):
+ seen.append(key)
+ return None # a secondary profile's own scope carries no A2A_PORT
+
+ monkeypatch.setattr(gw, "get_env_value", fake_get_env_value)
+ monkeypatch.setattr(os, "getenv", lambda *a, **k: pytest.fail("raw os.getenv during enablement"))
+ assert a2a.is_connected(SimpleNamespace(extra={})) is False
+ assert seen == ["A2A_PORT"]
+
+ def test_scoped_port_connects(self, monkeypatch):
+ import hermes_cli.gateway as gw
+ from plugins.platforms import a2a
+
+ monkeypatch.setattr(gw, "get_env_value", lambda key: "9902" if key == "A2A_PORT" else None)
+ assert a2a.is_connected(SimpleNamespace(extra={})) is True
+
+ def test_explicit_extra_enabled_wins(self, monkeypatch):
+ import hermes_cli.gateway as gw
+ from plugins.platforms import a2a
+
+ monkeypatch.setattr(gw, "get_env_value", lambda key: None)
+ assert a2a.is_connected(SimpleNamespace(extra={"enabled": True})) is True
+
+
# --------------------------------------------------------------------------
# Security
# --------------------------------------------------------------------------