diff --git a/backend/open_webui/utils/timers.py b/backend/open_webui/utils/timers.py index d8be899dff..15a6b898db 100644 --- a/backend/open_webui/utils/timers.py +++ b/backend/open_webui/utils/timers.py @@ -11,7 +11,7 @@ from datetime import datetime, timezone from typing import Literal from uuid import uuid4 -from fastapi import Request +from fastapi import HTTPException, Request from open_webui.internal.db import get_async_db from open_webui.models.chat_messages import ChatMessages from open_webui.models.chats import Chat, ChatForm, Chats @@ -416,7 +416,20 @@ async def execute_due_timer(app, timer_id: str, claim_id: str | None = None) -> await app.state.CHAT_COMPLETION_HANDLER(request, form_data, user=user) except Exception as exc: log.exception(f'Timer {timer_id} completion failed') - await _set_timer_state(timer_id, 'error', timer_error=str(exc)[:500]) + error_detail = exc.detail if isinstance(exc, HTTPException) else str(exc) + await _set_timer_state(timer_id, 'error', timer_error=error_detail[:500]) + await Chats.upsert_message_to_chat_by_id_and_message_id( + parent_chat_id, assistant_message_id, {'error': {'content': error_detail}, 'done': True} + ) + await sio.emit( + 'events', + { + 'chat_id': parent_chat_id, + 'message_id': assistant_message_id, + 'data': {'type': 'chat:message:error', 'data': {'error': {'content': error_detail}, 'done': True}}, + }, + room=f'user:{timer.user_id}', + ) async def _set_timer_state(timer_id: str, status: str, **fields) -> None: