fix: deleting a folder or all chats leaves their replies and sub-agents running (#35058)

Deleting a single chat stops a reply that is still being written and any sub-agent it handed work to. Deleting a folder with its chats, or all chats, removed the chats but left that work running, so replies kept streaming from the provider and a sub-agent left running kept its background slot, refusing the next delegation with "Async subagent capacity reached". Both now stop the running work of every chat they delete, including its sub-agents, as deleting a single chat does.

Fixes #35056
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-25 13:13:17 +04:00
1 parent 1fcfc8a5cd
commit cdf38c4a72
3 files changed
+22 -1

No files matched your search

+12
View File
@@ -757,6 +757,18 @@ class ChatTable:
)
return list(result.scalars().all())
async def get_chat_ids_by_user_id(self, user_id: str, db: AsyncSession | None = None) -> list[str]:
async with get_async_db_context(db) as session:
result = await session.execute(select(Chat.id).filter_by(user_id=user_id))
return list(result.scalars().all())
async def get_chat_ids_by_user_id_and_folder_id(
self, user_id: str, folder_id: str, db: AsyncSession | None = None
) -> list[str]:
async with get_async_db_context(db) as session:
result = await session.execute(select(Chat.id).filter_by(user_id=user_id, folder_id=folder_id))
return list(result.scalars().all())
async def get_children_by_parent_id(self, parent_chat_id: str, user_id: str) -> list:
async with get_async_db_context() as session:
result = await session.execute(
+3
View File
@@ -838,6 +838,9 @@ async def delete_all_user_chats(
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
)
for chat_id in await Chats.get_chat_ids_by_user_id(user.id, db=db):
await stop_item_tasks(request.app.state.redis, chat_id)
result = await Chats.delete_chats_by_user_id(user.id, db=db)
if result:
await publish_event(
+7 -1
View File
@@ -34,7 +34,7 @@ from open_webui.models.shared_chats import ChatShareMode
from open_webui.models.users import Users
from open_webui.routers.notes import check_notes_access, truncate_note_data
from open_webui.socket.main import close_note
from open_webui.tasks import has_active_tasks
from open_webui.tasks import has_active_tasks, stop_item_tasks
from open_webui.utils.access_control import (
has_permission,
validate_access_grants,
@@ -1115,6 +1115,12 @@ async def delete_folder_by_id(
for folder_id in folder_ids:
if delete_contents:
for chat_id in await Chats.get_chat_ids_by_user_id_and_folder_id(
folder_owner_id, folder_id, db=db
):
await stop_item_tasks(request.app.state.redis, chat_id)
for child_id in await Chats.get_internal_chat_ids_by_parent_id(chat_id, folder_owner_id):
await stop_item_tasks(request.app.state.redis, child_id)
await Chats.delete_chats_by_user_id_and_folder_id(folder_owner_id, folder_id, db=db)
for note in await Notes.get_notes_by_folder_id_and_user_id(folder_id, folder_owner_id, db=db):
await Notes.delete_note_by_id(note.id, db=db)