Skip to content

fix(compat-0.3): return InvalidParamsError for invalid SendMessage params - #1337

Merged
kabir merged 1 commit into
a2aproject:mainfrom
cchinchilla-dev:issue-1336
Nov 20, 2026
Merged

kabir merged 1 commit into
a2aproject:mainfrom
cchinchilla-dev:issue-1336

Conversation

@cchinchilla-dev

Copy link
Copy Markdown
Contributor

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

Fixes #1336 🦕

Problem

In the v0.3 compatibility layer, a SendMessage whose message has no messageId or an empty parts list is only rejected with InvalidParamsError by JSON-RPC message/send. REST and gRPC report it as an internal error, and so does JSON-RPC message/stream for a missing messageId:

$ curl -s -w ' [%{http_code}]' localhost:9999/v1/message:send -H 'Content-Type: application/json' \
    -d '{"message":{"role":"ROLE_USER","content":[{"text":"x"}]}}'
{"error": "org.a2aproject.sdk.compat03.spec.InternalError_v0_3", "message": "Internal error"} [500]

The checks throw IllegalArgumentException from the v1.0 Message during the v0.3 to v1.0 conversion (messageId) and from Message_v0_3 in ProtoUtils_v0_3.FromProto.message (parts). Only JSONRPCHandler_v0_3.onMessageSend maps it to InvalidParamsError_v0_3; every other path reports InternalError_v0_3. This is what the v0.3 TCK reports for REST and gRPC in the tck-test-0-3 job (test_missing_required_message_fields and test_empty_arrays).

Fix

The exception is now converted where it is raised, the same way v1.0 does in ProtoUtils.FromProto.convert():

  • Convert_v0_3_To10RequestHandler: onMessageSend and onMessageSendStream convert the params through a small helper that turns the IllegalArgumentException from MessageSendParamsMapper_v0_3.toV10 into InvalidParamsError. ErrorConverter_v0_3 already maps it to InvalidParamsError_v0_3 on every transport.
  • ProtoUtils_v0_3.FromProto.messageSendParams: throws InvalidParamsError_v0_3 for the same exception, which the REST and gRPC handlers already report as invalid params.

The handlers are unchanged. Clients now get InvalidParamsError_v0_3 with the original message (Parameter 'messageId' may not be null, Parts cannot be empty): HTTP 422 for REST message:send, an InvalidParamsError_v0_3 event in the message:stream SSE stream, INVALID_ARGUMENT over gRPC and -32602 over JSON-RPC. Exceptions raised by the backend or while writing the response still go through InternalError_v0_3.

Test

Tests were added to the existing handler suites:

  • RestHandler_v0_3_Test: testSendMessageMissingMessageId, testSendMessageEmptyParts and testSendStreamingMessageMissingMessageId.
  • GrpcHandler_v0_3_Test: testOnMessageMissingMessageId, testOnMessageEmptyParts and testOnMessageStreamMissingMessageId, which also check the InvalidParamsError description.
  • JSONRPCHandler_v0_3_Test: testOnMessageStreamMissingMessageId.

The seven tests fail on main, where they get InternalError_v0_3, and pass with the fix. No existing test was modified or removed. The compat-0.3 spec-grpc, server-conversion, transport and reference modules build and pass their suites, and with the fix the v0.3 TCK (0.3.0.beta6, --category all --transports jsonrpc,grpc,rest, as in CI) runs against compat-0.3/tck with no failures.

Happy to adapt the test approach based on maintainer feedback.

…rams

A v0.3 SendMessage with no messageId or with empty parts makes a message
record throw IllegalArgumentException: the v1.0 Message during the v0.3
to v1.0 conversion, or Message_v0_3 when REST and gRPC read the request.
Only JSONRPCHandler_v0_3.onMessageSend mapped it to invalid params, so
REST, gRPC and JSON-RPC message/stream reported an internal error.

Convert the exception where it is raised, as v1.0 does in
ProtoUtils.FromProto.convert(): Convert_v0_3_To10RequestHandler now
throws InvalidParamsError when converting the params, and
ProtoUtils_v0_3.FromProto.messageSendParams throws
InvalidParamsError_v0_3.

Fixes a2aproject#1336
@kabir
kabir merged commit 9c7eabf into a2aproject:main Nov 20, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: v0.3 SendMessage returns Internal error instead of InvalidParams for a missing messageId or empty parts

2 participants