From eead8e0675650629caba3501c2873a548afbc78b Mon Sep 17 00:00:00 2001 From: saquibjawedbit <138011435+saquibjawedbit@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:09:20 +0530 Subject: [PATCH] fix(compat): return a null result for v0.3 JSON-RPC push config deletes A successful v0.3 `tasks/pushNotificationConfig/delete` was answered with `{"jsonrpc": "2.0", "id": 1}`: no `result` and no `error`. JSON-RPC 2.0 requires the `result` member on every success response, and the v0.3 schema (`DeleteTaskPushNotificationConfigSuccessResponse`) requires `result: null`. The SDK's own v0.3 response model rejects the body. Root cause: `JSONRPC03Adapter._process_non_streaming_request` serializes the response envelope with `model_dump(exclude_none=True)`. That is meant to drop unset optional fields inside the result, but for delete the result itself is `None`, so the whole member is dropped. Keep `exclude_none` for the payload and put `result` back when it was dropped. The v1.0 JSON-RPC dispatcher already answers with `"result": null`. --- src/a2a/compat/v0_3/jsonrpc_adapter.py | 10 +++++---- tests/compat/v0_3/test_jsonrpc_app_compat.py | 22 +++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/a2a/compat/v0_3/jsonrpc_adapter.py b/src/a2a/compat/v0_3/jsonrpc_adapter.py index 2263f336b..4089fd517 100644 --- a/src/a2a/compat/v0_3/jsonrpc_adapter.py +++ b/src/a2a/compat/v0_3/jsonrpc_adapter.py @@ -240,11 +240,13 @@ async def _process_non_streaming_request( else: raise ValueError(f'Unsupported method {method}') - return JSONResponse( - content=result.model_dump( - mode='json', by_alias=True, exclude_none=True - ) + content = result.model_dump( + mode='json', by_alias=True, exclude_none=True ) + # exclude_none also drops the null result of a successful delete, but + # JSON-RPC 2.0 requires the result member in every success response. + content.setdefault('result', None) + return JSONResponse(content=content) @validate_version(constants.PROTOCOL_VERSION_0_3) async def _process_streaming_request( diff --git a/tests/compat/v0_3/test_jsonrpc_app_compat.py b/tests/compat/v0_3/test_jsonrpc_app_compat.py index 5a9227d20..426868f09 100644 --- a/tests/compat/v0_3/test_jsonrpc_app_compat.py +++ b/tests/compat/v0_3/test_jsonrpc_app_compat.py @@ -6,7 +6,7 @@ import pytest -from a2a.compat.v0_3 import jsonrpc_adapter +from a2a.compat.v0_3 import jsonrpc_adapter, types as types_v03 from a2a.compat.v0_3.jsonrpc_adapter import JSONRPC03Adapter from a2a.server.context import ServerCallContext from a2a.server.request_handlers.request_handler import RequestHandler @@ -162,6 +162,26 @@ def test_get_task_v03_compat( assert data['result']['status']['state'] == 'completed' +def test_delete_push_notification_config_v03_compat_returns_null_result( + client: TestClient, mock_handler: AsyncMock +) -> None: + """A successful delete carries `"result": null`, as JSON-RPC 2.0 requires.""" + mock_handler.on_delete_task_push_notification_config.return_value = None + request_payload = { + 'jsonrpc': '2.0', + 'id': '5', + 'method': 'tasks/pushNotificationConfig/delete', + 'params': {'id': 'test_task_id', 'pushNotificationConfigId': 'cfg'}, + } + + response = client.post('/', json=request_payload) + assert response.status_code == 200 + data = response.json() + + assert data == {'jsonrpc': '2.0', 'id': '5', 'result': None} + types_v03.DeleteTaskPushNotificationConfigResponse.model_validate(data) + + def test_get_extended_agent_card_v03_compat( client: TestClient, mock_handler: AsyncMock, agent_card: AgentCard ) -> None: