Commit 58b4c81
authored
fix: Prevent client disconnect from stopping task execution (#440)
# Issue
* Client disconnect triggered synchronous cleanup.
* That awaited the producer task, effectively tying producer lifetime to
the client connection.
* Reconnecting with `tasks/resubscribe` would not receive further events
because the producer had already been forced to finish.
This behaviour no longer raises a `asyncio.exceptions.CancelledError`
like claimed in #296 due to this fix: #383, but `tasks/resubscribe`
still didn't behave as expected.
# How it's reproduced
In any streaming agent: Simply sending a (longer-running)
`message/stream`, disconnecting, and then reconnecting to the task using
`tasks/resubscribe` will no longer yield events, even though the task
should have been still running.
# Fix
## Code
The fix is an one-liner. Now:
* Client disconnect schedules cleanup in the background and returns
immediately.
* Producer continues; resubscribe taps the existing queue and receives
subsequent events.
* Cleanup still runs once the producer completes.
## Tests
**Existing tests:**
* Changed existing tests that asserted on `AgentExecutor.execute` by
adding an `asyncio.Event` latch to wait until the background producer
hits `execute`.
**New tests:**
* `test_stream_disconnect_then_resubscribe_receives_future_events` --
start streaming, disconnect, resubscribe, and confirm future events are
received.
*
`test_on_message_send_stream_client_disconnect_triggers_background_cleanup_and_producer_continues`
-- to validate that disconnecting is non-blocking, producer continues,
and cleanup completes afterward.
Fixes #2961 parent 6d0ef59 commit 58b4c81
File tree
3 files changed
+381
-3
lines changed- src/a2a/server/request_handlers
- tests/server/request_handlers
3 files changed
+381
-3
lines changedLines changed: 35 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
105 | 109 | | |
106 | 110 | | |
107 | 111 | | |
| |||
355 | 359 | | |
356 | 360 | | |
357 | 361 | | |
358 | | - | |
359 | | - | |
| 362 | + | |
360 | 363 | | |
361 | 364 | | |
| 365 | + | |
| 366 | + | |
362 | 367 | | |
363 | 368 | | |
364 | 369 | | |
| |||
394 | 399 | | |
395 | 400 | | |
396 | 401 | | |
397 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
398 | 407 | | |
399 | 408 | | |
400 | 409 | | |
| |||
403 | 412 | | |
404 | 413 | | |
405 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
406 | 438 | | |
407 | 439 | | |
408 | 440 | | |
| |||
0 commit comments