@@ -188,7 +188,6 @@ public void onSubscribe(Flow.Subscription subscription) {
188188 public void onNext (EventQueueItem item ) {
189189 receivedEvents .add (item .getEvent ());
190190 subscription .request (1 );
191-
192191 }
193192
194193 @ Override
@@ -237,7 +236,6 @@ public void onSubscribe(Flow.Subscription subscription) {
237236 public void onNext (EventQueueItem item ) {
238237 receivedEvents .add (item .getEvent ());
239238 subscription .request (1 );
240-
241239 }
242240
243241 @ Override
@@ -257,6 +255,69 @@ public void onComplete() {
257255 assertSame (message , receivedEvents .get (0 ));
258256 }
259257
258+ @ Test
259+ public void testConsumeTaskInputRequired () throws Exception {
260+ Task task = Task .builder ()
261+ .id ("task-id" )
262+ .contextId ("task-context" )
263+ .status (new TaskStatus (TaskState .INPUT_REQUIRED ))
264+ .build ();
265+ List <Event > events = List .of (
266+ task ,
267+ TaskArtifactUpdateEvent .builder ()
268+ .taskId ("task-123" )
269+ .contextId ("session-xyz" )
270+ .artifact (Artifact .builder ()
271+ .artifactId ("11" )
272+ .parts (new TextPart ("text" ))
273+ .build ())
274+ .build (),
275+ TaskStatusUpdateEvent .builder ()
276+ .taskId ("task-123" )
277+ .contextId ("session-xyz" )
278+ .status (new TaskStatus (TaskState .WORKING ))
279+ .isFinal (true )
280+ .build ());
281+ for (Event event : events ) {
282+ eventQueue .enqueueEvent (event );
283+ }
284+
285+ Flow .Publisher <EventQueueItem > publisher = eventConsumer .consumeAll ();
286+ final List <Event > receivedEvents = new ArrayList <>();
287+ final AtomicReference <Throwable > error = new AtomicReference <>();
288+
289+ publisher .subscribe (new Flow .Subscriber <>() {
290+ private Flow .Subscription subscription ;
291+
292+ @ Override
293+ public void onSubscribe (Flow .Subscription subscription ) {
294+ this .subscription = subscription ;
295+ subscription .request (1 );
296+ }
297+
298+ @ Override
299+ public void onNext (EventQueueItem item ) {
300+ receivedEvents .add (item .getEvent ());
301+ subscription .request (1 );
302+ }
303+
304+ @ Override
305+ public void onError (Throwable throwable ) {
306+ error .set (throwable );
307+ }
308+
309+ @ Override
310+ public void onComplete () {
311+ subscription .cancel ();
312+ }
313+ });
314+
315+ assertNull (error .get ());
316+ // The stream is closed after the input_required task
317+ assertEquals (1 , receivedEvents .size ());
318+ assertSame (task , receivedEvents .get (0 ));
319+ }
320+
260321 @ Test
261322 public void testCreateAgentRunnableDoneCallbackSetsError () {
262323 EnhancedRunnable mockRunnable = new EnhancedRunnable () {
0 commit comments