Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugins/platforms/a2a/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,12 @@ def __init__(self, config, **kwargs):
super().__init__(config=config, platform=platform)

extra = getattr(config, "extra", {}) or {}
self.port = int(os.getenv("A2A_PORT") or extra.get("port", _DEFAULT_PORT))
# Mirror IRC_PORT (#40598): malformed A2A_PORT / extra.port must not
# ValueError during adapter construction and take the platform down.
try:
self.port = int(os.getenv("A2A_PORT") or extra.get("port", _DEFAULT_PORT))
except (ValueError, TypeError):
self.port = _DEFAULT_PORT
self.host = security.resolve_bind_host()
self.agent_name = _default_agent_name()
self._advertised_toolsets = [
Expand Down
24 changes: 24 additions & 0 deletions tests/plugins/test_a2a_port_int_guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""A2A adapter must tolerate malformed A2A_PORT / extra.port."""

from __future__ import annotations

from gateway.config import PlatformConfig
from plugins.platforms.a2a.adapter import A2AAdapter, _DEFAULT_PORT


def test_malformed_a2a_port_env_falls_back_to_default(monkeypatch):
monkeypatch.setenv("A2A_PORT", "not-a-port")
adapter = A2AAdapter(PlatformConfig(enabled=True))
assert adapter.port == _DEFAULT_PORT


def test_malformed_extra_port_falls_back_to_default(monkeypatch):
monkeypatch.delenv("A2A_PORT", raising=False)
adapter = A2AAdapter(PlatformConfig(enabled=True, extra={"port": "nope"}))
assert adapter.port == _DEFAULT_PORT


def test_valid_a2a_port_env_is_honored(monkeypatch):
monkeypatch.setenv("A2A_PORT", "9911")
adapter = A2AAdapter(PlatformConfig(enabled=True))
assert adapter.port == 9911
Loading