Repository navigation
fix(server)!: validate client message roles - #558
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
c3131e3 to
083c015
Compare
Signed-off-by: andy <[email protected]>
Signed-off-by: andy <[email protected]>
083c015 to
1432f5a
Compare
There was a problem hiding this comment.
The problem in #557 is real: a client-supplied ROLE_AGENT reaches the executor as the user's message and can stay in the task history as an agent turn, which an LLM-backed executor reads as the agent's own words. Rejecting ROLE_UNSPECIFIED is well founded too, since role is REQUIRED in a2a.proto. The check sits in start_execution, so every binding and both send methods share it, and the tests cover JSON-RPC, REST and gRPC, plus that a rejected message leaves an existing task unchanged.
Two things to settle before merging:
- It narrows what the server accepts. The spec has no MUST for the sender's role. a2a-go's proto conversion already rejects
ROLE_UNSPECIFIEDbut acceptsROLE_AGENTfrom a client, and a2a-python's server checks neither, so a client written against those can sendROLE_AGENTand now getsINVALID_PARAMShere. That is a defensible choice for the reason above, but it needs a line in the release notes. I checked this repo's own senders (ITK, a2acli, examples): theirROLE_AGENTmessages are replies, and their requests useROLE_USER. ACTS and ITK against the other SDKs are the checks to watch. - The error says
client messages must have role ROLE_USERbut not what was received; naming the role helps the caller.
The role tests (handler, JSON-RPC, REST and the gRPC e2e) pass locally on this head.
Signed-off-by: andy <[email protected]>
|
The role in the error message and the release note are both in, thanks. Two changes to how the break is recorded:
|
Signed-off-by: andy <[email protected]>
Problem
A client can submit a message with
ROLE_AGENT, which the default server handler passes to the executor and can persist in task history as an agent message. Callers can therefore make their text appear agent-authored. See #557.Change
Validate the client message role at the shared execution boundary for normal and streaming sends. Reject roles other than
ROLE_USERas invalid parameters before task creation, push configuration, or agent execution. Authentication and streaming capability checks keep their existing order. The error reports the decoded role; unknown gRPC enum values are decoded toROLE_UNSPECIFIEDby the existing protobuf conversion.The protocol describes
ROLE_USERas client-to-server andROLE_AGENTas server-to-client. This tightens validation of previously accepted inputs; it does not assert a separate explicit protocol MUST governing how receivers reject them. The PR title marks this compatibility change as breaking for the generated release notes.Validation
cargo test -p a2a-server-lf -p a2a-grpc --locked --offline: 282 server unit tests, 8 server integration tests, 40 gRPC unit tests, 7 gRPC end-to-end tests and 1 doc test passed.cargo clippy -p a2a-server-lf -p a2a-grpc --all-targets --locked --offline -- -D warnings.cargo fmt --all -- --checkandgit diff --check.Tests used the local cached registry mirror and an isolated target directory.
Fixes #557