This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-01 13:18:44 -07:00
1 parent 27fb20c13a
commit 778dba1d6b
2 files changed
+17 -2

No files matched your search

+13 -1
View File
@@ -30,6 +30,7 @@ from open_webui.models.folders import Folders
from open_webui.models.shared_chats import SharedChatResponse, SharedChats
from open_webui.models.tags import TagModel, Tags
from open_webui.socket.main import get_event_emitter
from open_webui.tasks import stop_item_tasks
from open_webui.utils.access_control import filter_allowed_access_grants, has_permission
from open_webui.utils.auth import get_admin_user, get_verified_user
from open_webui.utils.middleware import serialize_output
@@ -1116,6 +1117,10 @@ async def delete_chat_by_id(
user=Depends(get_verified_user),
db: AsyncSession = Depends(get_async_session),
):
# Cancel any in-flight LLM tasks (streaming, title/tags generation)
# before deleting the chat to prevent orphaned requests.
await stop_item_tasks(request.app.state.redis, id)
if user.role == 'admin':
chat = await Chats.get_chat_by_id(id, db=db)
if not chat:
@@ -1305,13 +1310,20 @@ async def clone_shared_chat_by_id(
@router.post('/{id}/archive', response_model=ChatResponse | None)
async def archive_chat_by_id(id: str, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)):
async def archive_chat_by_id(
request: Request,
id: str,
user=Depends(get_verified_user),
db: AsyncSession = Depends(get_async_session),
):
chat = await Chats.get_chat_by_id_and_user_id(id, user.id, db=db)
if chat:
chat = await Chats.toggle_chat_archive_by_id(id, db=db)
tag_ids = chat.meta.get('tags', [])
if chat.archived:
# Cancel any in-flight LLM tasks before archiving
await stop_item_tasks(request.app.state.redis, id)
# Archived chats are excluded from count — clean up orphans
await Chats.delete_orphan_tags_for_user(tag_ids, user.id, db=db)
else: