The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(a2a): a peer's messageId keys the forwarded admission
erosikab2968fb1c40a
diff --git a/plugins/platforms/a2a/adapter.py b/plugins/platforms/a2a/adapter.pyindex c8ffe9997a2..4a9f810a829 100644--- a/plugins/platforms/a2a/adapter.py+++ b/plugins/platforms/a2a/adapter.py@@ -7,6 +7,7 @@ from __future__ import annotationsimport asyncioimport contextlib+import hashlibimport jsonimport loggingimport os@@ -520,9 +521,13 @@ class A2AAdapter(BasePlatformAdapter):protocol.metrics.inbound_total += 1self._register_inline_push(task_id, params, agent=agent)if not agent.get("local", True):+ # A retry after a timeout must find its accepted work, not queue a second turn.+ message_id = protocol.extract_message_id(params)+ input_id = ("a2a-msg:" + hashlib.sha256(f"{context_id}\0{message_id}".encode()).hexdigest()+ if message_id else task_id)self._activate_task(task_id)try:- reply, state = self._forward_to_profile(agent, peer, context_id, framed, input_id=task_id)+ reply, state = self._forward_to_profile(agent, peer, context_id, framed, input_id=input_id)self._record_outcome(task_id, context_id, peer, state, reply)return protocol.build_task(task_id, context_id, state, reply, created_at=rec["created_iso"]), Nonefinally:diff --git a/plugins/platforms/a2a/protocol.py b/plugins/platforms/a2a/protocol.pyindex a4cbcfe083f..db6f2f2bd45 100644--- a/plugins/platforms/a2a/protocol.py+++ b/plugins/platforms/a2a/protocol.py@@ -176,6 +176,12 @@ def extract_text(message_or_params: dict) -> str:return "\n".join(chunks).strip()+def extract_message_id(params: dict) -> str:+ """v1.0 puts messageId inside the Message; a peer retrying a send repeats it."""+ msg = params.get("message") or {}+ return str(msg.get("messageId") or "") if isinstance(msg, dict) else ""++def extract_context_id(params: dict) -> str:"""v1.0 puts contextId inside the Message; tolerate legacy top-level."""msg = params.get("message") or {}diff --git a/tests/plugins/test_a2a_plugin.py b/tests/plugins/test_a2a_plugin.pyindex 58840ed203b..4304cf1f5f1 100644--- a/tests/plugins/test_a2a_plugin.py+++ b/tests/plugins/test_a2a_plugin.py@@ -1379,6 +1379,38 @@ class TestMultiAgentRouting:route = adapter._route_for_request("/dev/", {"tenant": "research"})assert "error" in route+ def test_forwarded_retry_of_the_same_message_reuses_its_admission_id(self, monkeypatch):+ """A peer that resends after a timeout repeats its messageId; the forwarded input id must+ repeat with it so the owner answers from the accepted work instead of queueing a second turn."""+ from plugins.platforms.a2a.adapter import A2AAdapter+ from gateway.config import PlatformConfig++ adapter = A2AAdapter(PlatformConfig(enabled=True, extra={+ "agents": {"dev": {"profile": "dev", "tenant": "dev"}}+ }))+ agent = adapter._agents["dev"]+ seen = []++ def fake_forward(agent_arg, peer, context_id, framed_text, *, input_id):+ seen.append(input_id)+ return "dev reply", protocol.STATE_COMPLETED++ adapter._forward_to_profile = fake_forward # type: ignore+ message = protocol.text_message(protocol.ROLE_USER, "hello", context_id="ctx-dev")+ for _ in range(2):+ adapter._prepare_task({"tenant": "dev", "message": dict(message)}, "peer-x", agent=agent)+ fresh = protocol.text_message(protocol.ROLE_USER, "hello", context_id="ctx-dev")+ adapter._prepare_task({"tenant": "dev", "message": fresh}, "peer-x", agent=agent)+ other_context = {**dict(message), "contextId": "ctx-other"}+ adapter._prepare_task({"tenant": "dev", "message": other_context}, "peer-x", agent=agent)+ assert seen[0] == seen[1]+ assert len({seen[0], seen[2], seen[3]}) == 3+ assert all(i.startswith("a2a-msg:") and len(i) < 1024 for i in seen)+ # A message without an id keeps the per-task id, which is never reused.+ adapter._prepare_task({"tenant": "dev", "message": {"role": "user", "parts": [{"text": "hi"}], "contextId": "ctx-dev"}},+ "peer-x", agent=agent)+ assert not seen[4].startswith("a2a-msg:")+def test_forwarded_profile_task_completes_in_task_store(self, monkeypatch):from plugins.platforms.a2a.adapter import A2AAdapterfrom gateway.config import PlatformConfig