From d5d9d19fbe6044529b2e0cf8f3aa1d2ef2dc3ea2 Mon Sep 17 00:00:00 2001 From: buua436 Date: Wed, 24 Jun 2026 11:51:35 +0800 Subject: [PATCH] fix: keep chat channel bindings consistent (#16274) --- api/db/services/conversation_service.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/db/services/conversation_service.py b/api/db/services/conversation_service.py index b53f66391c..8f69524e3e 100644 --- a/api/db/services/conversation_service.py +++ b/api/db/services/conversation_service.py @@ -61,10 +61,14 @@ class ConversationService(CommonService): A chat_channel is bound to a dialog; each end-user chat on that channel keeps its own conversation history. The conversation is identified by a - deterministic id derived from (channel_id, chat_id) so history persists - across restarts without a back-reference column on the conversation. + deterministic id derived from (dialog_id, channel_id, chat_id) so + history persists across restarts without a back-reference column on the + conversation, while still separating histories when the channel is + re-bound to a different dialog. """ - conv_id = hashlib.md5(f"{channel_id}:{chat_id}".encode("utf-8")).hexdigest()[:32] + conv_id = hashlib.md5( + f"{dialog_id}:{channel_id}:{chat_id}".encode("utf-8") + ).hexdigest()[:32] conv = cls.model.get_or_none(cls.model.id == conv_id) if conv is not None: return conv