feat: abort immediately on max call duration exceed

This commit is contained in:
Abhishek Kumar 2026-05-31 13:21:37 +05:30
parent 78ba62e185
commit c586d02d5d
3 changed files with 27 additions and 5 deletions

View file

@ -1,5 +1,3 @@
from __future__ import annotations
"""Callback factory helpers for :pyclass:`~api.services.workflow.pipecat_engine.PipecatEngine`.
Each helper takes a :class:`PipecatEngine` instance and returns an async
@ -10,6 +8,8 @@ encapsulating the callback implementations here for easier maintenance and
unit-testing.
"""
from __future__ import annotations
import re
from typing import TYPE_CHECKING
@ -73,11 +73,14 @@ def create_user_idle_handler(engine: "PipecatEngine") -> UserIdleHandler:
def create_max_duration_callback(engine: "PipecatEngine"):
"""Return a callback that ends the task when the max call duration is exceeded."""
"""Return a callback that cancels the task when the hard call limit is exceeded."""
async def handle_max_duration():
logger.debug("Max call duration exceeded. Terminating call")
await engine.end_call_with_reason(EndTaskReason.CALL_DURATION_EXCEEDED.value)
await engine.end_call_with_reason(
EndTaskReason.CALL_DURATION_EXCEEDED.value,
abort_immediately=True,
)
return handle_max_duration