Commit bf4d011
committed
feat: Separate task state building from persistence
This refactoring introduces TaskStateProcessor as a global singleton to
manage task state lifecycle and addresses a critical architectural issue
in task state management.
Problem:
- Task state was persisted multiple times during event propagation,
causing redundant database writes and tight coupling between event
processing and persistence
Solution:
- Created TaskStateProcessor as @ApplicationScoped singleton to maintain
in-flight tasks globally
- Separated state building (TaskStateProcessor) from persistence (TaskStore)
- Tasks are now persisted once at appropriate lifecycle points instead of
for each event
- Tasks are explicitly removed from TaskStateProcessor after final
persistence, ensuring bounded memory usage
Changes:
- New: TaskStateProcessor - global singleton managing task state in memory
- Modified: DefaultRequestHandler - injects TaskStateProcessor and ensures
cleanup after task completion
- Modified: ResultAggregator - uses TaskStateProcessor for state building,
removes tasks after background consumption
- Modified: TaskManager - delegates state building to TaskStateProcessor
- Updated: All test files to inject TaskStateProcessor instances
- Fixed: Test isolation issues with defensive cleanup
Impact:
- Performance: Significantly reduced I/O operations (one write vs multiple)
- Memory: Bounded usage that scales with concurrent tasks, not total tasks
- Reliability: Improved test isolation and clearer task lifecycle
See doc/adr/0001_task_state_management_refactoring.md for detailed
architectural decision record.1 parent cb084ec commit bf4d011
File tree
13 files changed
+1088
-220
lines changed- client/base/src/main/java/io/a2a/client
- doc/adr
- server-common/src
- main/java/io/a2a/server
- requesthandlers
- tasks
- test/java/io/a2a/server
- requesthandlers
- tasks
- spec/src/main/java/io/a2a/util
- tests/server-common/src/test/java/io/a2a/server/apps/common
13 files changed
+1088
-220
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
Lines changed: 56 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
| |||
119 | 121 | | |
120 | 122 | | |
121 | 123 | | |
| 124 | + | |
122 | 125 | | |
123 | 126 | | |
124 | 127 | | |
| |||
223 | 226 | | |
224 | 227 | | |
225 | 228 | | |
| 229 | + | |
226 | 230 | | |
227 | 231 | | |
228 | | - | |
| 232 | + | |
229 | 233 | | |
230 | 234 | | |
231 | 235 | | |
| |||
249 | 253 | | |
250 | 254 | | |
251 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
252 | 265 | | |
253 | | - | |
| 266 | + | |
254 | 267 | | |
255 | | - | |
| 268 | + | |
256 | 269 | | |
257 | 270 | | |
258 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
259 | 276 | | |
260 | 277 | | |
261 | 278 | | |
| |||
267 | 284 | | |
268 | 285 | | |
269 | 286 | | |
270 | | - | |
| 287 | + | |
271 | 288 | | |
272 | 289 | | |
273 | 290 | | |
| |||
320 | 337 | | |
321 | 338 | | |
322 | 339 | | |
323 | | - | |
| 340 | + | |
324 | 341 | | |
325 | 342 | | |
326 | 343 | | |
| |||
360 | 377 | | |
361 | 378 | | |
362 | 379 | | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
367 | 386 | | |
368 | | - | |
369 | | - | |
370 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
371 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
372 | 403 | | |
373 | 404 | | |
374 | 405 | | |
| |||
401 | 432 | | |
402 | 433 | | |
403 | 434 | | |
404 | | - | |
| 435 | + | |
405 | 436 | | |
406 | 437 | | |
407 | 438 | | |
| |||
419 | 450 | | |
420 | 451 | | |
421 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
422 | 461 | | |
423 | 462 | | |
424 | 463 | | |
| |||
600 | 639 | | |
601 | 640 | | |
602 | 641 | | |
603 | | - | |
604 | | - | |
| 642 | + | |
| 643 | + | |
605 | 644 | | |
606 | 645 | | |
607 | 646 | | |
| |||
797 | 836 | | |
798 | 837 | | |
799 | 838 | | |
| 839 | + | |
800 | 840 | | |
801 | 841 | | |
802 | 842 | | |
| |||
0 commit comments