Commit 29d1c3d
committed
fix: prevent premature stream closure in EventConsumer grace period
The EventConsumer grace period logic could close streams prematurely when
final events were still in-transit through MainEventBusProcessor. This
manifested as intermittent test failures where the stream would close
before all events were delivered.
Root Cause:
- When agent execution completes, EventConsumer enters a grace period
- It polls the ChildQueue with 500ms timeout, allowing 3 consecutive
timeouts (1.5s total) before closing the stream
- The original logic only checked queue.size() == 0
- However, final events can be in-transit: MainQueue → MainEventBus →
MainEventBusProcessor → ChildQueue
- This timing window (typically <500ms) could result in premature closure
when the local queue was empty but the final event hadn't arrived yet
Solution:
- Added EventQueue.isAwaitingFinalEvent() method
- MainQueue calls child.expectFinalEvent() when enqueueing final events
- EventConsumer checks awaitingFinalEvent flag before starting timeout
counter: agentCompleted && queueSize == 0 && !awaitingFinal
- ChildQueue clears the flag only when a FINAL event is dequeued (not on
any event, to avoid clearing it too early when non-final events arrive)
- This ensures the grace period doesn't start counting down while a final
event is still being distributed
The fix handles both local execution (events available immediately) and
replicated scenarios (events may arrive via Kafka with delays).1 parent fd33b3d commit 29d1c3d
2 files changed
Lines changed: 42 additions & 7 deletions
Lines changed: 12 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
| |||
102 | 107 | | |
103 | 108 | | |
104 | 109 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
109 | 114 | | |
110 | 115 | | |
111 | 116 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
307 | 326 | | |
308 | 327 | | |
309 | 328 | | |
| |||
735 | 754 | | |
736 | 755 | | |
737 | 756 | | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
738 | 763 | | |
739 | 764 | | |
740 | 765 | | |
| |||
757 | 782 | | |
758 | 783 | | |
759 | 784 | | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
760 | 790 | | |
761 | 791 | | |
762 | 792 | | |
| |||
0 commit comments