Repository navigation
Conversation
toJsonRPCRequest() serialised with alwaysPrintFieldsWithNoPresence(), so proto3 scalars the caller never set went out as "" (tenant, taskId, contextId, filename, mediaType) and repeated fields as []. A peer cannot tell "not supplied" from "supplied but empty" any more: in a2aproject#770 the .NET agent was told the task id was present but empty, answered with an empty task.id, and the client then failed to deserialise it. Requests now use a plain printer, which is what the REST client already does. Responses keep alwaysPrintFieldsWithNoPresence() to match the REST server handler, so clients still see the full payload shape. Both printers are static fields now instead of being rebuilt per call, and both still go through ProtoJsonUtils.toJson so the HTML-unescaping from a2aproject#892 is preserved. Adds two unit tests: one asserting the request omits those fields, one pinning that the response printer still prints them. Fixes a2aproject#770
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
JSONRPCUtils.toJsonRPCRequestserialised client requests withalwaysPrintFieldsWithNoPresence(). proto3 scalar fields have implicit presence, so every field the caller never set was forced onto the wire as"", and repeated fields as[]:On the wire those are two different assertions — "I am not supplying a task id" versus "the task id is the empty string" — and they cannot be told apart again once the request is parsed. That is what #770 reports: the .NET agent was told a task id was present but empty, replied with
"id": "", and the a2a-java client then failed to deserialise the empty id.Fix
Serialise requests without that flag and keep it for responses:
toJsonRPCRequest)alwaysPrintFieldsWithNoPresence()toJsonRPCResultResponse)alwaysPrintFieldsWithNoPresence()This is not a new convention, it aligns the JSON-RPC client with the sibling implementations that already do it:
client/transport/rest/.../RestTransport.javaposts with a plainJsonFormat.printer()on both of its paths — the REST client already omits unset fields.transport/rest/.../RestHandler.javakeepsalwaysPrintFieldsWithNoPresence()when writing responses — the REST server also keeps it.So only the JSON-RPC request side was the odd one out; the response side stays as-is on purpose.
Both printers are now
static finalfields instead of being rebuilt per call, and both still go throughProtoJsonUtils.toJson, so the HTML-unescaping fix from #892 is preserved.Tests
Updating the fixtures alone would not catch a regression here, because the fixtures are just mockserver expectations. Two unit tests pin the behaviour directly:
testToJsonRPCRequest_omitsFieldsWithoutPresence— assertstenant,taskId,contextId,extensions,referenceTaskIds,filenameandmediaTypeare all absent from the serialised request, then round-trips it throughparseRequestBody.testToJsonRPCResultResponse_stillPrintsFieldsWithoutPresence— pins the other half of the split so the two printers are not collapsed into one later.Fixture side: the
JsonMessagesrequest fixtures no longer carry"returnImmediately":falseor an empty"metadata":{}object — with the flag gone the client does not send them any more, and the stubs match withMatchType.ONLY_MATCHING_FIELDS. The twoListTasksParamsassertions inJSONRPCTransportTestnow assert thetenantkey is absent instead of asserting it is"". Response fixtures are untouched.Verification
Reverse check: pointing
toJsonRPCRequestback at the response printer makestestToJsonRPCRequest_omitsFieldsWithoutPresencefail with exactly the payload from #770 —— and nothing else in
JSONRPCUtilsTestfails, i.e. the test really is guarding this flag and not passing for some unrelated reason.Relation to #774
This is the same fix as #774 (thanks @jmesnil), which was closed for inactivity rather than on merit. It cannot be applied as-is: the packages moved from
io.a2atoorg.a2aproject, and both call sites now go throughProtoJsonUtils.toJsoninstead of callingPrinter.printdirectly — that indirection is the #892 HTML-escaping fix, which #774 predates. So this is #774 rebased ontoe5483dd4f3, plus the static printers from the earlier review and the two tests above.Happy to close this if you would rather reopen #774 and drive it from there.
Fixes #770