AOSSIE-Org / AOSSIE-Org/SkillBot

fix: backlog replay can drop messages and produce duplicate replies in bot.py

未关闭
#5 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
6
派生
3
PR 合并指标
30 天内没有已合并 PR

描述

## Summary

The backlog replay logic in `bot.py` (`on_ready`) has two related problems that can cause missed messages and duplicate replies.

## Problem 1 – History scan limit drops older messages

At line 114, only the last **50 messages** are scanned to find the bot's last reply cursor (`last_bot_msg`). If the bot was offline long enough that its last reply is beyond the 50-message window, `last_bot_msg` is `None` and the fallback (lines 126–129) processes only the last **5 user messages**, silently dropping any older unprocessed ones.

## Problem 2 – Duplicate replies when `on_message` is active during replay

The `on_message` event handler is active while the backlog is being replayed in `on_ready`. If a new message arrives (or if history iteration yields a message that also triggers `on_message`), the same message can be forwarded to Ollama and replied to **twice**.

## Suggested fix

1. **Persist a durable checkpoint** — store `last_processed_message_id` to disk (e.g., a small JSON/SQLite file) after each successful `process_message` call instead of relying on scanning chat history for the last bot message.
2. **Use the checkpoint for history fetch** — call `channel.history(after=last_processed_message_id, oldest_first=True)` (or from the beginning if no checkpoint exists) with no artificial small limit.
3. **Add message-id deduplication** in `process_message` (maintain a set of recently processed IDs) **or** temporarily gate `on_message` while the replay loop runs to prevent double-processing.

## References

- PR: https://github.com/AOSSIE-Org/SkillBot/pull/4
- Review comment: https://github.com/AOSSIE-Org/SkillBot/pull/4#discussion_r3393419333
- Requested by: @kpj2006

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。