fix: failed timer leaves a blank, unfinished reply in the chat (#31483)

When a scheduled timer failed before the model started answering, for example because its model had been removed, the chat showed the timer's prompt with a blank reply that looked stuck, and the error never appeared in the chat. The reply now shows the error and stops loading, like any other failed message.

Fixes #31481
This commit is contained in:
Classic298 2026-09-27 20:56:20 +02:00 • committed by GitHub
parent 420b4a2797
commit b0650d04b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: