Repository navigation
Commit ab7e36f
authored
fix(server): fail fast when an executor produces no events (a2aproject#1345)
## Description
With an `AgentExecutor` that returns normally without enqueueing any
event, `message/send` hung forever on both the request coroutine and the
ActiveTask producer/consumer tasks: `result` was `None`, and
`ActiveTask.get_task()` awaited `_task_created` with no timeout — but
`_task_created` is only set when a task event is processed, the task
pre-existed at `start()`, or the producer failed. A *silent success*
path sets none of them. Root-cause analysis and a runtime reproduction
are in a2aproject#1330.
Per the approach endorsed on the issue, this fail-fasts with
`InternalError` when the subscribe loop finishes without a task event:
- New `ActiveTask.task_created_is_set()` accessor (public wrapper over
the internal `_task_created` event) so the handler doesn't reach into
private state.
- `DefaultRequestHandlerV2.on_message_send`: raise `InternalError` when
`result is None` and `task_created_is_set()` is False, before awaiting
`get_task()`.
Follow-up (not in this PR): the legacy handler contains an equivalent
`raise InternalError` guard (`default_request_handler.py:456`) that is
empirically unreachable in this scenario — the flow blocks earlier in
`consume_and_break_on_interrupt`. Making that reachable is a separate
piece of work.
- [x] Follow the CONTRIBUTING Guide
- [x] PR title follows Conventional Commits (`fix:` → SemVer patch)
- [x] Tests and linter pass
- [x] Appropriate docs were updated (accessor docstring states the
guarantee)
Fixes a2aproject#1330 🦕
## Validation
- Claim: a zero-event executor now fails fast with `InternalError`
instead of hanging; an event-producing executor is unaffected.
- Exact head: 1ed3680
- BEFORE: `message/send` never returns (3s+ timeout in repro, issue
a2aproject#1330). AFTER: raises `InternalError('Agent execution produced no
events')` immediately.
- Tests: new
`test_on_message_send_raises_when_agent_produces_no_events`; handler +
agent_execution suites green.
- Environment: Python 3.10.20, macOS.
- Limits / not tested: the optional timeout/completion-signaling
complement discussed on the issue — the `is_set()` guard fully covers
the unreachable-wait case; happy to add on request.
Prepared with AI assistance (WorkBuddy); reviewed and verified by
Linux2010
---------
Signed-off-by: andy <linux2011@qq.com>1 parent 2cc1dd5 commit ab7e36f
3 files changed
Lines changed: 46 additions & 0 deletions
File tree
- src/a2a/server
- agent_execution
- request_handlers
- tests/server/request_handlers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1120 | 1120 | | |
1121 | 1121 | | |
1122 | 1122 | | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
1123 | 1128 | | |
1124 | 1129 | | |
1125 | 1130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
516 | 517 | | |
517 | 518 | | |
518 | 519 | | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
519 | 525 | | |
520 | 526 | | |
521 | 527 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3586 | 3586 | | |
3587 | 3587 | | |
3588 | 3588 | | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
| 3612 | + | |
| 3613 | + | |
| 3614 | + | |
| 3615 | + | |
| 3616 | + | |
| 3617 | + | |
| 3618 | + | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
| 3623 | + | |
0 commit comments