From a10a2d8769abcc4d5c353cc6a7cc725b4a46fb35 Mon Sep 17 00:00:00 2001 From: Hz_ Date: Mon, 29 Jun 2026 19:05:25 +0800 Subject: [PATCH] fix(py): chat message reference deletion index (#16436) Fix the reference index used when deleting a chat message pair. Each user/assistant message pair shares one reference entry, while the first assistant prologue has no reference. Using `i // 2` correctly removes the reference for the deleted pair and avoids deleting the previous turn's reference. --- api/apps/restful_apis/chat_api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/apps/restful_apis/chat_api.py b/api/apps/restful_apis/chat_api.py index 5ea6bd3fcc..605b473137 100644 --- a/api/apps/restful_apis/chat_api.py +++ b/api/apps/restful_apis/chat_api.py @@ -929,7 +929,8 @@ async def delete_session_message(chat_id, session_id, msg_id): assert conv["message"][i + 1]["id"] == msg_id conv["message"].pop(i) conv["message"].pop(i) - conv["reference"].pop(max(0, i // 2 - 1)) + ref_index = (i - 1) // 2 + conv["reference"].pop(ref_index) break ConversationService.update_by_id(conv["id"], conv) return get_json_result(data=_build_session_response(conv))