Skip to content

fix(server)!: validate client message roles - #558

Merged
muscariello merged 7 commits into
a2aproject:mainfrom
Linux2010:codex/validate-client-message-role
Nov 24, 2026
Merged

muscariello merged 7 commits into
a2aproject:mainfrom
Linux2010:codex/validate-client-message-role

Conversation

@Linux2010

@Linux2010 Linux2010 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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_USER as 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 to ROLE_UNSPECIFIED by the existing protobuf conversion.

The protocol describes ROLE_USER as client-to-server and ROLE_AGENT as 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 -- --check and git diff --check.
  • Handler tests cover normal and streaming sends, preservation of an existing task on rejected continuation, and no executor calls. JSON-RPC, REST and actual TCP gRPC tests assert the decoded role in errors; valid user messages remain accepted.

Tests used the local cached registry mirror and an isolated target directory.

Fixes #557

@Linux2010
Linux2010 requested a review from a team as a code owner November 14, 2026 04:05
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.55357% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
a2a-server/src/handler.rs 99.44% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Linux2010
Linux2010 force-pushed the codex/validate-client-message-role branch from c3131e3 to 083c015 Compare November 19, 2026 11:28

@muscariello muscariello left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. It narrows what the server accepts. The spec has no MUST for the sender's role. a2a-go's proto conversion already rejects ROLE_UNSPECIFIED but accepts ROLE_AGENT from a client, and a2a-python's server checks neither, so a client written against those can send ROLE_AGENT and now gets INVALID_PARAMS here. 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): their ROLE_AGENT messages are replies, and their requests use ROLE_USER. ACTS and ITK against the other SDKs are the checks to watch.
  2. The error says client messages must have role ROLE_USER but 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.

@muscariello

Copy link
Copy Markdown
Member

The role in the error message and the release note are both in, thanks. Two changes to how the break is recorded:

  1. Put ! in the title: fix(server)!: validate client message roles. That is how fix(a2a-pb)!: reject a part with no content and a request with no message #510 marked its break (fix(a2a-pb)!:), and the title is what lands on main.
  2. Please drop the two hand-edited [Unreleased] entries (CHANGELOG.md and a2a-server/CHANGELOG.md). This repo does not hand-edit its changelogs: the release PR generates them (release-plz.toml says so for the root one), and the only commits that touch them on main are the release bot's. The sentence in the description about release notes can then say the title carries it.

@Linux2010 Linux2010 changed the title fix(server): validate client message roles fix(server)!: validate client message roles Nov 24, 2026

@muscariello muscariello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@muscariello
muscariello added this pull request to the merge queue Nov 24, 2026
Merged via the queue into a2aproject:main with commit e7d507b Nov 24, 2026
22 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
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.

Client messages can use the agent sender role

2 participants