From 0b98adae9c771e2689a79ac624b0e404f00bba9a Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Fri, 10 Apr 2026 19:44:57 -0400 Subject: [PATCH] Add generation exception handler to LLM, VLM engines --- src/engine/ov_genai/llm.py | 7 +++++++ src/engine/ov_genai/vlm.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/engine/ov_genai/llm.py b/src/engine/ov_genai/llm.py index 12bcdf8..0b3fe42 100755 --- a/src/engine/ov_genai/llm.py +++ b/src/engine/ov_genai/llm.py @@ -141,8 +141,15 @@ async def _run_generation(): generation_kwargs, streamer ) + def _generation_exception_handler(task: asyncio.Task): + exc = task.exception() + if exc and not task.cancelled(): + # Force break the below loop + streamer.text_queue.put_nowait(None) + raise exc gen_task = asyncio.create_task(_run_generation()) + gen_task.add_done_callback(_generation_exception_handler) try: while True: diff --git a/src/engine/ov_genai/vlm.py b/src/engine/ov_genai/vlm.py index 054bb54..6015ef7 100644 --- a/src/engine/ov_genai/vlm.py +++ b/src/engine/ov_genai/vlm.py @@ -189,8 +189,15 @@ async def _run_generation(): generation_config=generation_kwargs, streamer=streamer, ) + def _generation_exception_handler(task: asyncio.Task): + exc = task.exception() + if exc and not task.cancelled(): + # Force break the below loop + streamer.text_queue.put_nowait(None) + raise exc gen_task = asyncio.create_task(_run_generation()) + gen_task.add_done_callback(_generation_exception_handler) try: while True: