Fix interruption blocked by slow non-uninterruptible frame in queue

When a non-uninterruptible frame was being processed slowly and an
uninterruptible frame was waiting in the queue, _start_interruption
skipped task cancellation. This caused interruptions to stall until
the slow frame finished, even though it had no reason to block them.

The fix: only skip cancellation when the *current* frame is
uninterruptible. Uninterruptible frames already in the queue are
preserved regardless, because __create_process_task calls
__reset_process_queue internally, which always retains them.

Fixes: https://github.com/pipecat-ai/pipecat/issues/4412
This commit is contained in:
filipi87
2026-05-06 15:35:43 -03:00
parent 90f0f7cd27
commit 921a7a46cb

View File

@@ -877,14 +877,19 @@ class FrameProcessor(BaseObject):
current_is_uninterruptible = isinstance( current_is_uninterruptible = isinstance(
self.__process_current_frame, UninterruptibleFrame self.__process_current_frame, UninterruptibleFrame
) )
if current_is_uninterruptible or self.__process_queue.has_uninterruptible: if current_is_uninterruptible:
# We don't want to cancel an UninterruptibleFrame (either the # The frame currently being processed is uninterruptible, so we
# one currently being processed or one waiting in the queue), # must not cancel it. Just flush non-uninterruptible frames from
# so we simply cleanup the queue keeping only # the queue; any uninterruptible ones will be kept and processed
# UninterruptibleFrames. # after the current frame finishes.
self.__reset_process_queue() self.__reset_process_queue()
else: else:
# Cancel and re-create the process task. # Cancel and re-create the process task. Previously this branch
# was skipped when the queue contained an uninterruptible frame,
# which caused slow non-uninterruptible frames to block
# interruptions. Uninterruptible queued frames are safe here
# because __create_process_task calls __reset_process_queue
# internally, which always preserves them.
await self.__cancel_process_task() await self.__cancel_process_task()
self.__create_process_task() self.__create_process_task()
except Exception as e: except Exception as e: