Repository navigation
Commit c16cab1
fix(server): fail streaming sends when an executor produces no events (a2aproject#1460)
# Description
Since a2aproject#1345, `on_message_send` raises `InvalidAgentResponseError`
("Agent execution produced no events") when the `AgentExecutor` returns
without producing any event. `on_message_send_stream` did not have the
same guard: its subscription ended with nothing yielded, so
`SendStreamingMessage` answered `200 text/event-stream` with zero
events. Spec §3.1.2 requires the stream to begin with a `Task` or
contain exactly one `Message`.
This PR applies the same check at the end of `on_message_send_stream`:
when the subscription yielded no event and no task was created, it
raises `InvalidAgentResponseError`. The JSON-RPC and REST dispatchers
already read the first event eagerly, so the client now gets the same
error as the non-streaming call (JSON-RPC `-32006`, REST `500
INVALID_AGENT_RESPONSE`) instead of an empty stream. Executors that
produce events are unaffected.
Tests:
`test_on_message_send_stream_raises_when_agent_produces_no_events`
reuses the `SilentExecutor` from the a2aproject#1345 test.
```
$ pytest tests/server/request_handlers/test_default_request_handler_v2.py -k no_events # handler from main
1 failed, 1 passed
$ pytest tests/server/request_handlers/test_default_request_handler_v2.py -k no_events # this branch
2 passed
$ pytest tests/server tests/integration
1460 passed; the same 4 failures and 8 errors as on unmodified main (sample smoke tests and database tests that need services I don't have locally)
```
I also checked it over HTTP with a silent executor behind
`create_jsonrpc_routes` and `create_rest_routes`: before, both streaming
endpoints returned an empty `200` stream; after, JSON-RPC returns the
`-32006` error and REST returns `500` with reason
`INVALID_AGENT_RESPONSE`.
`ruff check`, `ruff format` and `ty check` pass on the changed files.
This change was written with Claude Code.
- [x] Follow the [`CONTRIBUTING`
Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md).
- [x] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- [x] Ensure the tests and linter pass (Run `bash scripts/format.sh`
from the repository root to format)
- [x] Appropriate docs were updated (if necessary)
Fixes a2aproject#1459 🦕
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Mateusz Iwaniuk <45974414+Iwaniukooo11@users.noreply.github.com>1 parent caab6a2 commit c16cab1
2 files changed
Lines changed: 35 additions & 0 deletions
File tree
- src/a2a/server/request_handlers
- tests/server/request_handlers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
| 558 | + | |
558 | 559 | | |
559 | 560 | | |
560 | 561 | | |
561 | 562 | | |
| 563 | + | |
562 | 564 | | |
563 | 565 | | |
564 | 566 | | |
| |||
571 | 573 | | |
572 | 574 | | |
573 | 575 | | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
574 | 583 | | |
575 | 584 | | |
576 | 585 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3689 | 3689 | | |
3690 | 3690 | | |
3691 | 3691 | | |
| 3692 | + | |
| 3693 | + | |
| 3694 | + | |
| 3695 | + | |
| 3696 | + | |
| 3697 | + | |
| 3698 | + | |
| 3699 | + | |
| 3700 | + | |
| 3701 | + | |
| 3702 | + | |
| 3703 | + | |
| 3704 | + | |
| 3705 | + | |
| 3706 | + | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
0 commit comments