Repository navigation
Commit b22a68d
feat(server): release parked interrupted tasks after a configurable timeout (#1338)
## Description
Second half of #1296, following the direction agreed in
#1296 (comment)
and the maintainer's reply.
A task in `input-required` or `auth-required` keeps its `ActiveTask`
(producer, consumer, two dispatchers, registry entry) until a follow-up
arrives, which may never happen.
### Change
- New `DefaultRequestHandlerV2(..., interrupted_task_timeout: float |
None = None)`. The default `None` keeps today's behavior.
- When the timeout is set, `ActiveTask` starts a timer once a request
finishes or the last subscriber leaves. A new request or subscriber
cancels it. When it fires, the `ActiveTask` is released only if all of
these still hold:
- the task is in an interrupted state,
- no request is running or queued,
- no subscriber is attached.
- The stored task is not modified. A follow-up recreates the
`ActiveTask` from the store.
- `0` releases as soon as the task is idle.
### Registry fix
Removing a finished `ActiveTask` from the registry runs asynchronously.
A follow-up that arrived in between was rejected with `Task … is already
completed.` `get_or_create` now replaces a finished entry, and the
scheduled removal only deletes the instance it was scheduled for. Side
effect without a timeout: a follow-up to a task that just ended now gets
`is in terminal state: …`, the same error as outside that window.
### Tests
Seven new tests in `test_default_request_handler_v2.py`:
- no timeout by default,
- release for input-required and auth-required, with no leftover asyncio
tasks and the stored state unchanged,
- resume from the store after a release,
- reset by a follow-up,
- reset by a subscriber,
- no release while the executor is still running,
- a follow-up to a finished but still registered `ActiveTask` (this one
fails on `main`).
### Checks
- `./scripts/lint.sh`: passed (the 3 `ty` warnings already exist on
`main`).
- `uv run pytest`: 2285 passed. The new tests passed 10/10 repeated runs
and also pass on Python 3.14.
- Not tested: cluster mode (`event_stream`).
Part of #1296
Release-As: 1.3.0
---------
Co-authored-by: Mateusz Iwaniuk <45974414+Iwaniukooo11@users.noreply.github.com>1 parent 167bc16 commit b22a68d
4 files changed
Lines changed: 379 additions & 6 deletions
File tree
- src/a2a/server
- agent_execution
- request_handlers
- tests/server/request_handlers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| 249 | + | |
249 | 250 | | |
250 | 251 | | |
251 | 252 | | |
| |||
476 | 477 | | |
477 | 478 | | |
478 | 479 | | |
| 480 | + | |
479 | 481 | | |
480 | 482 | | |
481 | 483 | | |
| |||
489 | 491 | | |
490 | 492 | | |
491 | 493 | | |
| 494 | + | |
| 495 | + | |
492 | 496 | | |
493 | 497 | | |
494 | 498 | | |
| |||
501 | 505 | | |
502 | 506 | | |
503 | 507 | | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
504 | 511 | | |
505 | 512 | | |
506 | 513 | | |
| |||
537 | 544 | | |
538 | 545 | | |
539 | 546 | | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
540 | 552 | | |
541 | 553 | | |
542 | 554 | | |
| |||
717 | 729 | | |
718 | 730 | | |
719 | 731 | | |
| 732 | + | |
720 | 733 | | |
721 | 734 | | |
722 | 735 | | |
| |||
737 | 750 | | |
738 | 751 | | |
739 | 752 | | |
740 | | - | |
| 753 | + | |
741 | 754 | | |
742 | 755 | | |
743 | 756 | | |
| |||
753 | 766 | | |
754 | 767 | | |
755 | 768 | | |
| 769 | + | |
756 | 770 | | |
757 | 771 | | |
758 | 772 | | |
| |||
843 | 857 | | |
844 | 858 | | |
845 | 859 | | |
| 860 | + | |
846 | 861 | | |
847 | 862 | | |
848 | 863 | | |
| |||
968 | 983 | | |
969 | 984 | | |
970 | 985 | | |
| 986 | + | |
971 | 987 | | |
972 | 988 | | |
973 | 989 | | |
| |||
984 | 1000 | | |
985 | 1001 | | |
986 | 1002 | | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
987 | 1051 | | |
988 | 1052 | | |
989 | 1053 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
60 | 68 | | |
61 | 69 | | |
62 | 70 | | |
| |||
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
| 84 | + | |
76 | 85 | | |
77 | 86 | | |
78 | 87 | | |
| |||
99 | 108 | | |
100 | 109 | | |
101 | 110 | | |
| 111 | + | |
102 | 112 | | |
103 | 113 | | |
104 | 114 | | |
| |||
111 | 121 | | |
112 | 122 | | |
113 | 123 | | |
114 | | - | |
| 124 | + | |
115 | 125 | | |
116 | 126 | | |
117 | 127 | | |
118 | | - | |
| 128 | + | |
| 129 | + | |
119 | 130 | | |
120 | | - | |
121 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
122 | 137 | | |
123 | 138 | | |
124 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
99 | 104 | | |
100 | 105 | | |
101 | 106 | | |
| |||
118 | 123 | | |
119 | 124 | | |
120 | 125 | | |
| 126 | + | |
121 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
122 | 133 | | |
123 | 134 | | |
124 | 135 | | |
| |||
172 | 183 | | |
173 | 184 | | |
174 | 185 | | |
| 186 | + | |
175 | 187 | | |
176 | 188 | | |
177 | 189 | | |
| |||
260 | 272 | | |
261 | 273 | | |
262 | 274 | | |
263 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
264 | 280 | | |
265 | 281 | | |
266 | 282 | | |
| |||
0 commit comments