fix: OCR合并消息时问句被MD尾巴剥离吞掉

问题:stage[3]尾部消息'php有2种登陆模式:...]否|,那那个登录插件应该又去哪儿下载呢?'
被_strip_markdown_tail在首个|处切断,只保留'php有2种登陆模式:...]是',
用户下载问句'那那个登录插件应该又去哪儿下载呢?'被丢弃。

修复:
1. 问句保护:检测文本含问号但首段无问号时,在最后一个|处拆分
2. 尾部含问号的部分单独保留,不进入md剥离流程
3. md_stripped后把问句追加回来,确保用户提问不被吞掉

测试:
- 问题场景:download question preserved ✓
- 正常bot回复(无问句): unaffected ✓
- 问句在头部:unaffected ✓
This commit is contained in:
youpaishidifu
2026-08-17 18:55:11 +08:00
parent 1a6692ee12
commit 66d748a884
+24
View File
@@ -3456,11 +3456,35 @@ class MessageMonitor:
# OCR 把「用户新消息 + bot 旧回复」拼成一行时,先剥 bot 回复才能
# 保住用户提问,否则 _strip_markdown_tail 会在 bot 回复的 '::|::'
# 残片处切断、误删用户提问,导致 filter4 整体丢弃。
# ⭐ 2026-08-17 修复:问句保护——若文本含问号但被 _strip_markdown_tail
# 在 | 处切断导致问句丢失(如"php有2种登陆模式:...]否|,那那个登录插件
# 应该又去哪儿下载呢?"→head='php...是',问句被吞),先提问答句再剥离。
_msg_bot = self._strip_bot_reply_fragments(buf.strip())
if not _msg_bot:
logger.debug(f"[ocr] stage[{i}] [filter/bot] 尾部bot旧回复整体剥离后为空,跳过: {buf.strip()[:60]!r}")
else:
# ⭐ 问句保护:若文本含问号且首段无问句,先分离尾部问句
# 例: "php直登,是|,游戏里输,Jweb拿授权token,否|,那那个登录插件应该又去哪儿下载呢?"
# _strip_markdown_tail 在首个 | 处切→只留"php直登,是"→问句丢失
# 修复:在最后一个 | 处拆分,尾部含问号的部分单独保留,
# head 部分正常走 md 剥离流程(会正确切到首个 |)
_question_suffix = ''
if '?' in _msg_bot or '?' in _msg_bot:
_first_seg = _msg_bot.split('|')[0] if '|' in _msg_bot else _msg_bot
_has_q_in_head = '?' in _first_seg or '?' in _first_seg
if not _has_q_in_head:
# 在最后一个 | 处拆分
_last_pipe = _msg_bot.rfind('|')
if _last_pipe >= 0 and _last_pipe < len(_msg_bot) - 1:
_question_suffix = _msg_bot[_last_pipe + 1:].strip()
_before_pipe = _msg_bot[:_last_pipe].rstrip(',,|').strip()
if _before_pipe and _question_suffix:
_msg_bot = _before_pipe
logger.debug(f"[ocr] stage[{i}] 问句保护分离: head={_msg_bot[:40]!r}, suffix={_question_suffix[:40]!r}")
md_stripped = self._strip_markdown_tail(_msg_bot)
# 把分离出的问句追加回来(如果 md 剥离丢弃了尾部内容)
if _question_suffix and md_stripped is not None:
md_stripped = (md_stripped + ' ' + _question_suffix).strip()
if md_stripped is None:
logger.info(f"[ocr] stage[{i}] [filter3/md] DROP md大头整段丢弃(尾部): {_msg_bot[:80]!r}")
elif md_stripped != _msg_bot: