Skip to content

Commit 01483cb

Browse files
fix(compat): send no v0.3 configuration when the request has none (a2aproject#1429)
## Problem The v0.3 REST and gRPC client transports sent an empty `SendMessageConfiguration` for a request without one, which the server reads as `blocking=false`. ## Fix `ToProto.message_send_configuration` returns `None` when there is no configuration, so the client sends none and the server keeps its blocking default, like the JSON-RPC transport. ## Tests `test_compat_rest_transport_send_message_without_configuration` and `test_compat_grpc_transport_send_message_without_configuration` fail on main. `test_compat_rest_transport_send_message_with_configuration` checks that an explicit configuration still sends `blocking: true`. 2555 passed. Fixes a2aproject#1428 --------- Co-authored-by: Mateusz Iwaniuk <45974414+Iwaniukooo11@users.noreply.github.com>
1 parent ab7e36f commit 01483cb

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

‎src/a2a/compat/v0_3/proto_utils.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,11 @@ def task_status_update_event(
307307
@classmethod
308308
def message_send_configuration(
309309
cls, config: types.MessageSendConfiguration | None
310-
) -> a2a_pb2.SendMessageConfiguration:
310+
) -> a2a_pb2.SendMessageConfiguration | None:
311+
# An empty configuration reads as blocking=false, so send none and
312+
# leave the server on its blocking default.
311313
if not config:
312-
return a2a_pb2.SendMessageConfiguration()
314+
return None
313315
return a2a_pb2.SendMessageConfiguration(
314316
accepted_output_modes=config.accepted_output_modes,
315317
push_notification=cls.push_notification_config(

‎tests/compat/v0_3/test_grpc_transport.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ async def test_compat_grpc_transport_send_message_response_msg_parsing():
4040
assert response.HasField('message')
4141
assert response.message.message_id == 'msg-123'
4242

43+
sent = mock_stub.SendMessage.call_args.args[0]
44+
assert not sent.HasField('configuration')
45+
4346

4447
def test_compat_grpc_transport_mirrors_extension_metadata():
4548
"""Compat gRPC client must also emit the legacy x-a2a-extensions metadata

‎tests/compat/v0_3/test_proto_utils.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ def test_none_handling(self):
301301
assert proto_utils.ToProto.provider(None) is None
302302
assert proto_utils.ToProto.security(None) is None
303303
assert proto_utils.ToProto.security_schemes(None) is None
304+
assert proto_utils.ToProto.message_send_configuration(None) is None
304305

305306
def test_metadata_conversion(self):
306307
"""Test metadata conversion with various data types."""

‎tests/compat/v0_3/test_rest_transport.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ListTasksRequest,
2121
Message,
2222
Role,
23+
SendMessageConfiguration,
2324
SendMessageRequest,
2425
SendMessageResponse,
2526
StreamResponse,
@@ -625,6 +626,50 @@ async def mock_send_request(*args, **kwargs):
625626
assert response == SendMessageResponse()
626627

627628

629+
@pytest.mark.asyncio
630+
async def test_compat_rest_transport_send_message_without_configuration(
631+
transport,
632+
):
633+
"""No configuration is sent, so the server keeps its blocking default."""
634+
sent: dict = {}
635+
636+
async def mock_execute_request(method, path, context=None, json=None):
637+
sent.update(json)
638+
return {}
639+
640+
transport._execute_request = mock_execute_request
641+
642+
req = SendMessageRequest(
643+
message=Message(message_id='msg-1', role=Role.ROLE_USER)
644+
)
645+
await transport.send_message(req)
646+
647+
assert 'configuration' not in sent
648+
649+
650+
@pytest.mark.asyncio
651+
async def test_compat_rest_transport_send_message_with_configuration(
652+
transport,
653+
):
654+
sent: dict = {}
655+
656+
async def mock_execute_request(method, path, context=None, json=None):
657+
sent.update(json)
658+
return {}
659+
660+
transport._execute_request = mock_execute_request
661+
662+
req = SendMessageRequest(
663+
message=Message(message_id='msg-1', role=Role.ROLE_USER),
664+
configuration=SendMessageConfiguration(
665+
accepted_output_modes=['text/plain']
666+
),
667+
)
668+
await transport.send_message(req)
669+
670+
assert sent['configuration']['blocking'] is True
671+
672+
628673
@pytest.mark.asyncio
629674
async def test_compat_rest_transport_get_task_no_history(transport):
630675
async def mock_execute_request(method, path, context=None, params=None):

0 commit comments

Comments
 (0)