fix: deleting a message in the middle of a chat keeps the earlier messages in the model's context (#32332)

This commit is contained in:
G30 2026-10-14 10:30:31 -04:00 • committed by GitHub
parent 7129cc1d84
commit 29289f5ba6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1374,6 +1374,7 @@ class ChatTable:
self._repair_chat_current_id(chat)
history = chat.get('history', {})
parent_id = ((history.get('messages') or {}).get(message_id) or {}).get('parentId')
deleted_ids = self.delete_message_from_history(history, message_id)
await ChatMessages.delete_message_ids_by_chat_id(id, deleted_ids, db=session)
if not deleted_ids:
@ -1384,6 +1385,12 @@ class ChatTable:
return ChatModel.model_validate(chat_item)
for mid, message in (history.get('messages') or {}).items():
if message.get('parentId') == parent_id:
await ChatMessages.upsert_message(
mid, id, message.get('user_id') or chat_item.user_id, message, db=session
)
chat['history'] = history
chat_item.chat = chat
chat_item.title = self._clean_null_bytes(chat.get('title', 'New Chat'))