Skip to content

Commit 94ad594

Browse files
authored
fix: Improve task_push_notification_config presence check. (a2aproject#1047)
Call _push_config_store.set_info only when task_push_notification_config is set. Due to proto3 semantic bool(params.configuration.task_push_notification_config) was always True. Fixes a2aproject#1045 🦕
1 parent 1af9050 commit 94ad594

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

‎src/a2a/server/request_handlers/default_request_handler.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,8 @@ async def _setup_message_execution(
301301
# dictating the task ID at this layer is useful for tracking running
302302
# agents.
303303

304-
if (
305-
self._push_config_store
306-
and params.configuration
307-
and params.configuration.task_push_notification_config
304+
if self._push_config_store and params.configuration.HasField(
305+
'task_push_notification_config'
308306
):
309307
await self._push_config_store.set_info(
310308
task_id,

‎src/a2a/server/request_handlers/default_request_handler_v2.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,8 @@ async def _setup_active_task(
209209
task_id = cast('str', request_context.task_id)
210210
context_id = cast('str', request_context.context_id)
211211

212-
if (
213-
self._push_config_store
214-
and params.configuration
215-
and params.configuration.task_push_notification_config
212+
if self._push_config_store and params.configuration.HasField(
213+
'task_push_notification_config'
216214
):
217215
await self._push_config_store.set_info(
218216
task_id,

‎tests/server/request_handlers/test_default_request_handler_v2.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,36 @@ async def test_on_message_send_with_push_notification():
12471247
)
12481248

12491249

1250+
@pytest.mark.asyncio
1251+
async def test_on_message_send_with_empty_push_notification_config_does_not_call_set_info():
1252+
task_store = InMemoryTaskStore()
1253+
push_store = AsyncMock(spec=PushNotificationConfigStore)
1254+
1255+
request_handler = DefaultRequestHandlerV2(
1256+
agent_executor=HelloAgentExecutor(),
1257+
task_store=task_store,
1258+
push_config_store=push_store,
1259+
agent_card=create_default_agent_card(),
1260+
)
1261+
# Use empty SendMessageConfiguration where task_push_notification_config is NOT set explicitly.
1262+
# Proto3 makes accessing it return a truthy default instance.
1263+
params = SendMessageRequest(
1264+
message=Message(
1265+
role=Role.ROLE_USER,
1266+
message_id='msg_push_empty',
1267+
parts=[Part(text='Hi')],
1268+
),
1269+
configuration=SendMessageConfiguration(),
1270+
)
1271+
1272+
context = create_server_call_context()
1273+
result = await request_handler.on_message_send(params, context)
1274+
1275+
assert result is not None
1276+
assert isinstance(result, Task)
1277+
push_store.set_info.assert_not_called()
1278+
1279+
12501280
class MultipleMessagesAgentExecutor(AgentExecutor):
12511281
"""Misbehaving agent that yields more than one Message."""
12521282

0 commit comments

Comments
 (0)