Skip to content

Commit 21fe836

Browse files
fix(compat): treat an unset v0.3 history_length as unlimited (a2aproject#1306)
## Problem `FromProto.message_send_configuration` passed the v0.3 `history_length` default of 0 through as a limit, so v0.3 gRPC and REST `SendMessage` returned tasks with empty history. The v0.3 proto defines 0 as unlimited. ## Fix Map 0 to `None`, as `task_query_params` already does for GetTask. Follow-up to a2aproject#1277 in the same file. ## Tests `test_message_send_configuration_history_length` in `test_proto_utils.py`. The three `test_grpc_handler.py` cases that expected `history_length=0` on the forwarded request now expect it unset. Fixes a2aproject#1305 Co-authored-by: mykytanetipa <mykytanetipa@google.com>
1 parent 6ff0a82 commit 21fe836

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,9 @@ def message_send_configuration(
793793
)
794794
if config.HasField('push_notification')
795795
else None,
796-
history_length=config.history_length,
796+
history_length=config.history_length
797+
if config.history_length
798+
else None,
797799
blocking=config.blocking,
798800
)
799801

‎tests/compat/v0_3/test_grpc_handler.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ async def test_send_message_success_task(
7878
message=a2a_pb2.Message(
7979
message_id='msg-1', role=a2a_pb2.Role.ROLE_USER
8080
),
81-
configuration=a2a_pb2.SendMessageConfiguration(
82-
history_length=0, return_immediately=True
83-
),
81+
configuration=a2a_pb2.SendMessageConfiguration(return_immediately=True),
8482
)
8583
mock_request_handler.on_message_send.assert_called_once_with(
8684
expected_req, ANY
@@ -115,9 +113,7 @@ async def test_send_message_success_message(
115113
message=a2a_pb2.Message(
116114
message_id='msg-1', role=a2a_pb2.Role.ROLE_USER
117115
),
118-
configuration=a2a_pb2.SendMessageConfiguration(
119-
history_length=0, return_immediately=True
120-
),
116+
configuration=a2a_pb2.SendMessageConfiguration(return_immediately=True),
121117
)
122118
mock_request_handler.on_message_send.assert_called_once_with(
123119
expected_req, ANY
@@ -168,9 +164,7 @@ async def mock_stream(*args, **kwargs):
168164
message=a2a_pb2.Message(
169165
message_id='msg-1', role=a2a_pb2.Role.ROLE_USER
170166
),
171-
configuration=a2a_pb2.SendMessageConfiguration(
172-
history_length=0, return_immediately=True
173-
),
167+
configuration=a2a_pb2.SendMessageConfiguration(return_immediately=True),
174168
)
175169
mock_request_handler.on_message_send_stream.assert_called_once_with(
176170
expected_req, ANY

‎tests/compat/v0_3/test_proto_utils.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ def test_task_push_config_from_proto_invalid_parent(self):
263263
exc_info.value
264264
)
265265

266+
@pytest.mark.parametrize(
267+
('history_length', 'expected'), [(0, None), (5, 5)]
268+
)
269+
def test_message_send_configuration_history_length(
270+
self, history_length: int, expected: int | None
271+
):
272+
"""A v0.3 history_length of 0 means unlimited, as in task_query_params."""
273+
config = proto_utils.FromProto.message_send_configuration(
274+
a2a_pb2.SendMessageConfiguration(history_length=history_length)
275+
)
276+
assert config.history_length == expected
277+
266278
def test_none_handling(self):
267279
"""Test that None inputs are handled gracefully."""
268280
assert proto_utils.ToProto.message(None) is None

0 commit comments

Comments
 (0)