Repository navigation
Description
What happened?
DefaultRequestHandler.onMessageSend/onMessageSendStream only treat a null taskId on the incoming Message as "start a new task". A blank string ("") is instead looked up in the TaskStore, which either throws TaskNotFoundError for a legitimate new-task request, or — depending on the TaskStore backend — can propagate a raw backend error for an empty key (e.g. a datastore that rejects empty partition keys).
Root cause
Proto3 scalar fields have no wire-level "was this set" tracking. spec-grpc/src/main/proto/a2a.proto declares Message.task_id/context_id as plain (non-optional) string fields:
string context_id = 2;
string task_id = 3;So a client that never set taskId and one that explicitly serialized it as "" are indistinguishable once the message crosses a transport built on JsonFormat, which forces default-valued fields to be printed:
JsonFormat.printer().alwaysPrintFieldsWithNoPresence().omittingInsignificantWhitespace()(spec-grpc/src/main/java/org/a2aproject/sdk/grpc/utils/JSONRPCUtils.java, toJsonRPCRequest/toJsonRPCResultResponse).
On the reference server's own transports (JSON-RPC, REST, gRPC) this is largely absorbed by MessageMapper.fromProto's existing emptyToNull mapping (spec-grpc/src/main/java/org/a2aproject/sdk/grpc/mapper/A2ACommonFieldMapper.java) — but DefaultRequestHandler itself doesn't apply that normalization, so:
- Any caller that builds a
MessageSendParams/Messagedirectly (bypassing the proto/MapStruct mapping layer) and passestaskId("")hits this. - The pre-authorization
enforceWrite/enforceCreatebranch inonMessageSend/onMessageSendStream(String msgTaskId = params.message().taskId(); if (msgTaskId != null) { enforceWrite(...) } else { enforceCreate(...) }) also picks the wrong branch for a blank id. - Downstream,
RequestContext.Builder.build()'s coalesce (taskId != null ? taskId : messageTaskId != null ? messageTaskId : UUID.randomUUID()) would use the blank string as the real task id instead of generating a new one, since a builder-set""is non-null.
Steps to reproduce
Call DefaultRequestHandler.onMessageSend(params, context) (or onMessageSendStream) with a MessageSendParams whose Message.taskId() is "" (not null) — e.g. as would arrive from any JSON-RPC/REST server implementation that deserializes the incoming message without going through this SDK's own ProtoUtils/MapStruct conversion. Expected: treated as a new task. Actual: TaskNotFoundError (taskStore.get("") returns no task).
Relation to #1160
Unrelated bug, different code path. #1160 is an NPE in A2ACommonFieldMapper.structToMap when a protobuf Struct contains an explicit JSON null field, hit while converting a GetTask response (valueToObject/structToMap, via TaskMapperImpl/MessageMapperImpl). This issue is about an incoming message/send request's taskId/contextId handling in DefaultRequestHandler, on the request-authorization path, not the struct-to-map conversion path.
Suggested fix
Normalize blank taskId/contextId to null once, before DefaultRequestHandler inspects them for the new-vs-existing-task decision — mirroring the emptyToNull convention already used in A2ACommonFieldMapper for the gRPC mapping path. PR ready with the fix and regression tests.
Relevant log output
at org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler.authorizeTaskAccess(DefaultRequestHandler.java:1430)
at org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler.initMessageSend(DefaultRequestHandler.java:1356)
at org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler.onMessageSend(DefaultRequestHandler.java:728)
at org.a2aproject.sdk.transport.jsonrpc.handler.JSONRPCHandler.onMessageSend(JSONRPCHandler.java:248)Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
fix(server): treat blank taskId/contextId as absent in message/send (a…