Repository navigation
fix(a2a-pb)!: reject a part with no content and a request with no message - #510
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
this needs fixing @gulldan |
1cc476f to
c1d8f3e
Compare
muscariello
left a comment
There was a problem hiding this comment.
The fix is right: a part with no content is rejected at conversion, as the native Part deserializer already does. CI is green. I'd address 1–3 before merging; the rest are suggestions.
1. A bad response is reported as INVALID_PARAMS on gRPC and SLIM RPC. The gRPC client (client.rs#L90) and the SLIM RPC client (L101, L218, L233, L250, L262, L282) return the error as is when the server's response has a part without content. The caller's request was fine, and the JSON-RPC client already maps the same failure to A2AError::internal (jsonrpc.rs#L133, #L387). Anything that branches on INVALID_PARAMS (a gateway returning 400, a retry policy) now blames the caller, and the code depends on the transport. Wrapping it as internal on the client side keeps it consistent.
2. This is a breaking change but is marked as a fix. About 12 public pbconv::from_proto_* signatures change to Result, and ProtoJsonPayloadError gains a variant (L22) without #[non_exhaustive]. We mark these fix(a2a-pb)!: (6e3e032, a7bb51e, e488557), and the release changelog relies on it. The title is fix(pb):; please make it fix(a2a-pb)!: and add a BREAKING CHANGE: footer.
3. Tests cover one path. Only the gRPC server is tested over a transport. Not covered: the SLIM RPC server (request? and the streaming map_err), JSON-RPC SendStreamingMessage (jsonrpc.rs#L233), REST message:stream (rest.rs#L266), a part inside a task's history, an artifact or a status-update message, and the client-side rejection in gRPC and SLIM RPC.
Suggestions
- One part without content now fails a whole task (
from_proto_task) or a wholelist_taskspage (L582), so a client reading from a lenient peer gets nothing. Strict is right for requests; for responses consider skipping and reporting the bad task. - A request with no
messagestill becomes an empty user message (L512) and reaches the executor, so{"message": {"parts": [{}]}}is rejected but{}is not. You note this in the description; it leaves the goal half met.Task.statusand the update event'sartifacthave the same silent default. - A
Part::dataholding JSON null serializes as{"data": null}, which the decoder now reads as an unset oneof, so a part our own server can emit is rejected by our own client. Worth distinguishing an explicit null from an absent oneof, or documenting the limit. register_collaboratenow drops a message with an invalid part silently (L190); a log line would help.register_unary_unarypasses the fallible decode throughReqNative(L218) and unwraps it in one closure (L43), while the streaming handler maps the error before dispatch. LettingDecodeReqreturn aResultwould handle both the same way.impl_protojson_payload_fallible!(L115) also duplicatesimpl_protojson_payload!apart from one call, andListTasksResponserepeats it by hand.- "part content is required" names no part, and the REST
FieldViolation.fieldis empty (rest.rs#L658). Addingparts[i]viaenumerate()makes the 400/-32602 actionable on large messages.
d1f1320 to
057f8d4
Compare
|
Thanks for the review. 1–3 are in, and so are 5 (for the request), 6, 7, 8 and 9. I left 4 and the second half of 5 as they are and ask about them at the end. One commit, rebased on 1. A bad response is 2. Breaking change. The title is 3. Tests. Each path you listed has one: the SLIM RPC server over a raw channel (unary and streaming), JSON-RPC 5. 6. 7. 8. 9. The violation carries the JSON path, e.g. 4 and the rest of 5: how lenient should a client be with a response? I kept responses strict and left the defaults for
If you want lenient reads, or Mirror of |
muscariello
left a comment
There was a problem hiding this comment.
Thanks for the update. The three items from my earlier review are in: a bad response is INTERNAL_ERROR on every transport, the title and footer mark the break, and each path I listed has a test. Making the server choose invalid_request and the client invalid_response is a good shape. CI is green and a trial merge against current main has no conflicts. I'd settle 1–3 before merging; the rest are suggestions.
1. Null handling depends on key order. I probed protojson_conv::from_value::<SendMessageRequest>, the path the JSON-RPC and REST servers use, on 5a25b04 and on this head:
| body | 5a25b04 |
this head |
|---|---|---|
{"text":"x","data":null} |
text | duplicate field text |
{"url":"http://a","text":null,"raw":null,"data":null} |
url | duplicate field raw |
{"text":"x","raw":null} |
text | text |
The first is the change the description lists, and both new rejections agree with protobuf-go (a null Value sets the oneof), so this is a compatibility note, not a conformance bug. What I would look at is the cause: the generated oneof arms run the duplicate check before they read the value, so {"text":"x","raw":null} is accepted by from_value (sorted keys put raw first) but rejected by from_str (duplicate field raw), on main and here, while protobuf-go accepts it in either order. The data patch carries the same order dependence to data, and a preserve_order feature enabled anywhere in a dependent's build changes the from_value order as well. Patching the arms to skip a null before the duplicate check, and keeping only data: null as a value, would make acceptance order-independent. Or drop the patch and document the limit, as you offered. Either way a test that pins {"text":"x","data":null} in both key orders and through from_str is missing; the only null test is the round trip of a lone {"data": null} (L355).
2. Rebase so CI runs on Rust 1.100. The base 5a25b04 predates the 1.100 break and the fix for it (#553), so the 22 green checks ran on 1.99.1. One rebase, then the Build and test jobs show whether anything else is hiding.
3. #[non_exhaustive] on ProtoJsonPayloadError (L18). You asked whether to; the release is already breaking, so now is free and the next variant is not another break.
Suggestions
- Required-field enforcement is half done.
{"message": {}}still converts to a user message with an empty id, an unspecified role and no parts (test_send_message_request_minimalasserts it), and all three are REQUIRED in a2a.proto (L563). An unsetstatusorartifactstill defaults silently (L878). Fine as a follow-up if it is tracked. - The new
register_collaboratewarning logs the peer-chosenmessage_idwith%, uncapped, once per message (L193).?escapes control characters, and a length cap bounds the line. Undecodable bytes and stream errors at L187 are still dropped without a log, which the description reads as covered. slimrpc_collaborate_drops_a_message_with_a_part_without_contentwaits a fixed 200 ms and 300 ms (L1231). Pollingreceivedwith a timeout avoids a flaky run on a loaded runner, and the test does not assert the warning.- One bad part gives three messages: the JSON-RPC client says
failed to deserialize result: …, the REST clientfailed to deserialize response as ProtoJSON: …, gRPC and SLIM RPCinvalid response: …. The doc oninvalid_responsesays it matches the ProtoJSON clients, which holds for the code only. - Boilerplate in
a2a-slimrpc/src/server.rs: nine|request| Ok(pbconv::from_proto_…(request))closures only to fit the new signature, and a privateinvalid_requestthat shares its name withpbconv::invalid_requestbut returns anRpcError. The gRPC server also repeats the samemap_errtwice (L83, L103).
I checked the probes in item 1 on a local checkout of this head with temporary tests, since removed. Empty-valued parts (text(""), raw([]), data(0) and so on) round-trip through both ProtoJSON and protobuf, so the new strictness does not reject anything a native Part can produce.
…sage
`Part.content` is a required oneof and `SendMessageRequest.message` a
REQUIRED field in a2a.proto, but the conversion from proto turned a part
that carries no content into an empty text part and a request without a
message into an empty user message, so both reached the executor. a2a-go
refuses both at conversion, and the native `Part` deserializer refuses
the first.
The converters in `pbconv` that can meet such a field now return
`Result<_, FieldViolation>`. The violation names the field by its JSON
path from the converted message (`message.parts[0]`,
`tasks[1].history[0].parts[2]`) and is not an `A2AError`, because what it
means depends on the reader:
- a server that finds it in a request answers `pbconv::invalid_request`:
INVALID_PARAMS over JSON-RPC, 400 with the field in `BadRequest` over
HTTP+JSON, INVALID_ARGUMENT over gRPC and SLIM RPC;
- a client that finds it in a response reports `pbconv::invalid_response`:
INTERNAL_ERROR, as the JSON-RPC and HTTP+JSON clients already report a
response they cannot decode. The gRPC and SLIM RPC clients returned the
conversion error as it was, which blamed the caller's request.
`{"data": null}` is a part whose content is JSON null, as
`google.protobuf.Value` defines it and protobuf-go reads it, not a part
without content: the generated ProtoJSON deserializer read it as an unset
oneof, so a part this server can send was rejected by its own client.
A null member of any other oneof is not set, wherever it stands among the
keys. The generated deserializer checked for a duplicate before it read
the value, so `{"text": "x", "raw": null}` parsed or failed with the key
order, which differs between `from_str` and `from_value`. `build.rs` makes
every oneof arm read first; the members come from the descriptor and a
miss fails the build.
A `Collaborate` item a listen-only member cannot deliver is dropped with
a warning instead of silently. The reason is escaped and capped, because
the peer chooses the message id.
BREAKING CHANGE: in `a2a_pb::pbconv`, `from_proto_part`,
`from_proto_message`, `from_proto_task_status`, `from_proto_artifact`,
`from_proto_task`, `from_proto_send_message_request`,
`from_proto_list_tasks_response`, `from_proto_task_status_update_event`
and `from_proto_task_artifact_update_event` return
`Result<T, FieldViolation>` instead of `T`, and
`from_proto_send_message_response` and `from_proto_stream_response`
return `Result<Option<T>, FieldViolation>` instead of `Option<T>`.
`ProtoJsonPayloadError` gains the variant `Invalid(FieldViolation)` and
is `#[non_exhaustive]`, so a match on it needs a wildcard arm. A
`SendMessageRequest` without `message` is rejected instead of becoming an
empty user message.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Signed-off-by: gulldan <5641375+gulldan@users.noreply.github.com>
7b2db66 to
1aa0a8e
Compare
|
Thanks. 1–3 are in, and so are 5–8. 4 is left for a follow-up; where it is tracked is below. It is one commit on 1. Null handling no longer depends on key order. The cause is the one you named: the generated arm checked for a duplicate before it read the value. Your probes and their reverse orders, each through
That is protobuf-go's rule ( 2. Rebased on e9b00bc. I ran the 3. 4. Required fields: follow-up. I would rather not widen this PR a third time. #561 already tracks the 5. Collaborate log. There is one warning for anything the member cannot deliver: a stream error, bytes that do not decode, or a message that fails conversion. The reason is written with 6. Test. 7. The doc now says that only the code is shared and each client words its own message. I left the three messages alone: aligning them changes 8. Patch coverage as |
Fixes #509.
Problem
Part.contentis a required oneof andSendMessageRequest.messagea REQUIRED field ina2a.proto, but the conversion from proto turned a part that carries no content ({}on JSON-RPC and REST, an empty oneof on gRPC and SLIM RPC) into an empty text part, and a request without a message into an empty user message. Both were accepted and reached the executor. a2a-go refuses both at conversion (a2apb/v1/pbconv/from_proto.go:44-46and:118-119at ea739de), and the nativePartdeserializer refuses the first.Fix
The converters in
a2a_pb::pbconvthat can meet such a field returnResult<_, FieldViolation>(the existinga2a::FieldViolation). The violation names the field by its JSON path from the converted message, built withenumerate()at each repeated field:message.parts[0],tasks[1].history[0].parts[2],statusUpdate.status.message.parts[0].It is deliberately not an
A2AError, because what it means depends on the reader, and there is noFromimpl, so a call site has to say which it is:pbconv::invalid_request:-32602on JSON-RPC,400with the path inBadRequest.fieldViolations[0].fieldon HTTP+JSON,INVALID_ARGUMENTon gRPC and SLIM RPC. The message ismessage.parts[0]: must have one of: text, raw, url, dataormessage: is required.pbconv::invalid_response:INTERNAL_ERRORwithinvalid response: <path>: <reason>, as the JSON-RPC and HTTP+JSON clients already report a response they cannot decode. The gRPC and SLIM RPC clients returned the conversion error as it was (INVALID_PARAMS), which blamed the caller's request; every conversion site in both clients (six in gRPC, seven in SLIM RPC,collaborateincluded) now goes throughinvalid_response.Also in this change, from the review:
{"data": null}is a part whose content is JSON null, not a part without content.datais agoogle.protobuf.Value, for which null is a value: protobuf-go sets the field (encoding/protojson/decode.go:219-224). pbjson reads every null oneof member as unset, sobuild.rspatches that one arm next to the existing null patches. Onmainthe same body silently became an empty text part.{"text": "x", "raw": null}was accepted byfrom_value(sorted keys) and rejected byfrom_str, onmaintoo.build.rsrewrites all 19 oneof arms (Part,SecurityScheme,OAuthFlows,SendMessageResponse,StreamResponse) to read first and check only a member that is not null. The members come from the descriptor, and the build fails if the number of patched arms differs from it.register_collaboratelogs one warning for an item it cannot deliver (a stream error, bytes that do not decode, a message that fails conversion) instead of dropping it silently. The reason is written with?and cut at 256 characters, because the peer chooses the message id. This addstracingtoa2a-slimrpc, andtracing-subscriberas a dev-dependency.SendMessageandSendStreamingMessageboth answer a rejected request throughpbconv::invalid_request;register_unary_unarykeeps its signature.impl_protojson_payload!is one macro: a path for a converter that cannot fail,|value| exprfor one that can, and optional trait items in braces.impl_protojson_payload_fallible!,impl_protojson_payload_optional!and the hand-writtenListTasksResponseimpl are gone.Behaviour changes to check
SendMessageRequestwithoutmessageis rejected (message: is required); it used to reach the executor as an empty user message."data": nullnext to another member, such as{"text": "x", "data": null}, is rejected as a duplicate oneof member, in either key order and through bothfrom_strandfrom_value. Onmainthe null was ignored and the part was read as text. protobuf-go rejects the same body (decode.go:238-242, "oneof … is already set").datanext to the member that is set, such as{"text": "x", "raw": null}, is accepted in any key order. Onmainfrom_strrejected it when the null came second.Not changed
A response is still read strictly: one part without content fails the task or the
ListTaskspage it is in, now asINTERNAL_ERRORnaming the element. The other REQUIRED fields are left for a follow-up: an emptymessageIdand emptypartsare tracked in #561, an unsetTask.status,TaskStatusUpdateEvent.statusandTaskArtifactUpdateEvent.artifactin #563.Tests
a2a-pb:test_part_without_content_is_named_by_its_path(a part inside a message, a task's history, an artifact, a status message, aListTaskspage, bothSendMessageResponsepayloads and all fourStreamResponsepayloads),test_send_message_request_without_a_message_is_rejected,test_a_violation_is_invalid_params_in_a_request_and_internal_in_a_response,test_part_none_contentflipped;tests/protojson.rs:send_message_request_rejects_part_without_content(asserts the message),a_null_data_part_round_trips,a_null_part_member_is_unset_in_any_key_orderanda_null_data_member_next_to_another_member_is_rejected_in_any_key_order(each body throughfrom_strandfrom_value),a_null_stream_response_member_is_unset.a2a-server:test_send_message_rejects_a_missing_message_and_a_part_without_contentinjsonrpc.rs(SendMessageandSendStreamingMessage) and inrest.rs(message:sendandmessage:stream, assertingfieldanddescription, plus a body that does not decode at all).a2a-grpc/tests/e2e.rs:grpc_server_rejects_a_missing_message_and_a_part_without_content(unary and streaming);grpc_transport_reports_a_part_without_content_in_a_response_as_internalagainst a raw service whose every response carries such a part (send_message,get_task,list_tasks,cancel_task, both streams).a2a-slimrpc/tests/e2e.rs:slimrpc_server_rejects_a_missing_message_and_a_part_without_content(raw channel, unary and streaming);slimrpc_transport_reports_a_part_without_content_in_a_response_as_internal(the same six calls);slimrpc_collaborate_replies_are_attributed_to_their_sendernow also gets a reply with such a part and expectsINTERNAL_ERROR;slimrpc_collaborate_drops_a_message_it_cannot_deliver(a listen-only member drops a part without content and an undecodable payload, logs both with the message id escaped, and receives the next message);slimrpc_transport_end_to_endcallsget_extended_agent_card, which no SLIM RPC test did.src/server.rs:collaborate_message_says_why_an_item_is_dropped,capped_cuts_on_a_character_boundary.On
main(e9b00bc) the 12 new or changed tests that compile against it fail: the five inprotojson.rs, both gRPC tests, the JSON-RPC test and the four SLIM RPC tests; the others need the new signatures. CI steps on Linux, Rust 1.100.0: all green (991 tests). Patch coverage ascoverage.ymlbuilds it (measured on 1.99.1): 374 coverable added lines, 0 missed.Overlap
One commit on
maine9b00bc. It closes the first case of #561 (a request with nomessage); the emptymessageIdandpartscases there are not covered. #558 editsa2a-grpc/tests/e2e.rs,a2a-server/src/jsonrpc.rsandrest.rsas well, so whichever merges second needs a rebase.a2a-grpc/src/errors.rsis untouched, so no conflict with #515.Breaking change
In
a2a_pb::pbconv,from_proto_part,from_proto_message,from_proto_task_status,from_proto_artifact,from_proto_task,from_proto_send_message_request,from_proto_list_tasks_response,from_proto_task_status_update_eventandfrom_proto_task_artifact_update_eventreturnResult<T, FieldViolation>instead ofT;from_proto_send_message_responseandfrom_proto_stream_responsereturnResult<Option<T>, FieldViolation>instead ofOption<T>.ProtoJsonPayloadErrorgains the variantInvalid(FieldViolation)and is#[non_exhaustive]. The commit message carries theBREAKING CHANGE:footer.🤖 Generated with Claude Code