fix(chat): 在聊天流处理后清除未读消息

在之前的逻辑中,当 ChatterManager 处理完一个聊天流后,该流上下文中的 unread_messages 列表并未被清空。这可能导致在后续的处理周期中,相同的消息被重复获取和处理,引发非预期的行为并浪费计算资源。

此更改通过在 MessageManager 中新增 `clear_stream_unread_messages` 方法,并在每次成功处理流之后立即调用它,确保消息只被处理一次,解决了潜在的重复处理问题。
This commit is contained in:
tt-P607
2025-10-02 04:05:59 +08:00
committed by Windpicker-owo
parent b6b4e3745b
commit 22dc9374fd
2 changed files with 26 additions and 0 deletions

View File

@@ -122,6 +122,13 @@ class ChatterManager:
actions_count = result.get("actions_count", 0)
logger.debug(f"{stream_id} 处理完成: 成功={success}, 动作数={actions_count}")
# 在处理完成后,清除该流的未读消息
try:
from src.chat.message_manager.message_manager import message_manager
await message_manager.clear_stream_unread_messages(stream_id)
except Exception as clear_e:
logger.error(f"清除流 {stream_id} 未读消息时发生错误: {clear_e}")
return result
except Exception as e:
self.stats["failed_executions"] += 1