JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(a2a): skip cancel payload resource_id in enterprise identity check
NickFuryXXX1c835816c25a
diff --git a/jiuwenswarm/gateway/message_handler/message_handler.py b/jiuwenswarm/gateway/message_handler/message_handler.pyindex 9eea226bab..2088770078 100644--- a/jiuwenswarm/gateway/message_handler/message_handler.py+++ b/jiuwenswarm/gateway/message_handler/message_handler.py@@ -3096,9 +3096,14 @@ class MessageHandler(FileTransferMixin, ABC):source_identity = identities[0]source_resource_id = str(source_identity.get("bot_id") or "").strip()requested_resource_id = str(params.get("resource_id") or "").strip()- resource_identity_invalid = bool(- not source_resource_id or requested_resource_id != source_resource_id- )+ missing_source = not source_resource_id+ if method == A2A_TOOL_CANCEL_CALL:+ # Cancel payloads only include jsonrpc_id; bind via active_calls.+ resource_identity_invalid = missing_source+ else:+ resource_identity_invalid = bool(+ missing_source or requested_resource_id != source_resource_id+ )if resource_identity_invalid:logger.warning("[A2A] reverse RPC identity missing or mismatched: method=%s session_id=%s "diff --git a/tests/unit_tests/gateway/test_a2a_outbound_dispatcher.py b/tests/unit_tests/gateway/test_a2a_outbound_dispatcher.pyindex a41164b6e7..735e7b4b3f 100644--- a/tests/unit_tests/gateway/test_a2a_outbound_dispatcher.py+++ b/tests/unit_tests/gateway/test_a2a_outbound_dispatcher.py@@ -1871,3 +1871,83 @@ async def test_gateway_cancel_call_cancels_only_same_session_active_rpc() -> Nonwith pytest.raises(asyncio.CancelledError):await dispatch_callassert replies[-1].params["response"]["result"]["canceled"] is True+++async def test_enterprise_cancel_call_binds_identity_via_active_calls(+ monkeypatch,+) -> None:+ monkeypatch.setenv("JIUWENSWARM_EDITION", "enterprise")+ started = asyncio.Event()++ class _Manager:+ async def outbound_dispatch_task(self, **kwargs):+ started.set()+ await asyncio.Event().wait()++ handler = object.__new__(MessageHandler)+ handler._a2a_outbound_tool_manager = _Manager()+ handler._active_a2a_outbound_tool_tasks = {}+ replies = []++ async def publish(message):+ replies.append(message)++ handler.publish_user_messages = publish+ metadata = {"routing": {"bot_id": "resource-1"}}+ dispatch_chunk = SimpleNamespace(+ payload={+ "id": "rpc-dispatch",+ "method": A2A_TOOL_DISPATCH_TASK,+ "params": {+ "agent_id": "agent-1",+ "task": "work",+ "mode": "sync",+ "resource_id": "resource-1",+ },+ },+ channel_id="web",+ )+ dispatch_call = asyncio.create_task(+ handler._handle_a2a_outbound_tool_push(+ chunk=dispatch_chunk, session_id="s1", request_metadata=metadata+ )+ )+ await started.wait()++ other_resource = SimpleNamespace(+ payload={+ "id": "rpc-cancel-other",+ "method": A2A_TOOL_CANCEL_CALL,+ "params": {"jsonrpc_id": "rpc-dispatch"},+ },+ channel_id="web",+ )+ await handler._handle_a2a_outbound_tool_push(+ chunk=other_resource,+ session_id="s1",+ request_metadata={"routing": {"bot_id": "resource-other"}},+ )+ try:+ assert dispatch_call.done() is False+ assert replies[-1].params["response"]["result"]["canceled"] is False++ same_resource = SimpleNamespace(+ payload={+ "id": "rpc-cancel-own",+ "method": A2A_TOOL_CANCEL_CALL,+ "params": {"jsonrpc_id": "rpc-dispatch"},+ },+ channel_id="web",+ )+ await handler._handle_a2a_outbound_tool_push(+ chunk=same_resource, session_id="s1", request_metadata=metadata+ )+ with pytest.raises(asyncio.CancelledError):+ await asyncio.wait_for(dispatch_call, timeout=0.5)+ assert replies[-1].params["response"]["result"]["canceled"] is True+ finally:+ if not dispatch_call.done():+ dispatch_call.cancel()+ with pytest.raises(asyncio.CancelledError):+ await dispatch_call