fix:Mobile QQ triggers empty messages that get sent to LLM#5797
fix:Mobile QQ triggers empty messages that get sent to LLM#5797gangcaiyoule wants to merge 1 commit intoAstrBotDevs:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where Mobile QQ's empty notice events were being processed as blank user messages and forwarded to the LLM. The changes introduce robust filtering for these non-meaningful events, ensuring that only relevant messages proceed through the pipeline. This prevents unnecessary processing by the LLM and cleans up log outputs, improving system efficiency and accuracy. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
你好,我在这里给出了一些整体性的反馈:
- 由于
_convert_handle_notice_event现在可能返回None,convert_message应当仿照你为_convert_handle_message_event添加的防御性检查:当得到None的 notice 结果时应直接短路返回,而不是继续向下传递并当作AstrBotMessage来处理(这样也能保证convert_message以及其调用处的类型标注保持准确)。 - 当前对被忽略的 notice 事件的调试日志会直接输出整个
event对象;建议只记录关键字段(例如post_type、notice_type、sub_type),以避免日志过于冗长,并减少潜在敏感载荷信息泄露的风险。
给 AI Agent 的提示词
Please address the comments from this code review:
## Overall Comments
- Since `_convert_handle_notice_event` can now return `None`, `convert_message` should mirror the defensive check you added for `_convert_handle_message_event`, so that a `None` notice result is short-circuited instead of being passed along as if it were an `AstrBotMessage` (and the type hints on `convert_message`/call sites stay accurate).
- The debug log for ignored notice events currently dumps the entire `event` object; consider logging only key fields (e.g. `post_type`, `notice_type`, `sub_type`) to avoid overly verbose logs and leaking potentially sensitive payload details.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English
Hey - I've left some high level feedback:
- Since
_convert_handle_notice_eventcan now returnNone,convert_messageshould mirror the defensive check you added for_convert_handle_message_event, so that aNonenotice result is short-circuited instead of being passed along as if it were anAstrBotMessage(and the type hints onconvert_message/call sites stay accurate). - The debug log for ignored notice events currently dumps the entire
eventobject; consider logging only key fields (e.g.post_type,notice_type,sub_type) to avoid overly verbose logs and leaking potentially sensitive payload details.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Since `_convert_handle_notice_event` can now return `None`, `convert_message` should mirror the defensive check you added for `_convert_handle_message_event`, so that a `None` notice result is short-circuited instead of being passed along as if it were an `AstrBotMessage` (and the type hints on `convert_message`/call sites stay accurate).
- The debug log for ignored notice events currently dumps the entire `event` object; consider logging only key fields (e.g. `post_type`, `notice_type`, `sub_type`) to avoid overly verbose logs and leaking potentially sensitive payload details.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the issue of empty notice events from Mobile QQ being processed as user messages. The core fix in _convert_handle_notice_event to check for meaningful message content before proceeding is well-implemented and correctly filters out the unwanted events. The accompanying type hint update and adjustment to Poke message construction are also good improvements.
I have one minor point of feedback on a defensive check added in convert_message, which appears to be inconsistent with the called function's signature, potentially leading to confusion.
| if abm is None: | ||
| return None |
There was a problem hiding this comment.
This check for None appears to be unreachable. The _convert_handle_message_event function is type-hinted to return AstrBotMessage and its implementation does not have a code path that returns None. This makes the check inconsistent with the function's current contract and could be confusing. If _convert_handle_message_event is not intended to return None, this check could be removed to avoid dead code.
| if "sub_type" in event: | ||
| if event["sub_type"] == "poke" and "target_id" in event: | ||
| abm.message.append(Poke(id=str(event["target_id"]))) | ||
| abm.message.append(Poke(qq=str(event["target_id"]), type="poke")) |
There was a problem hiding this comment.
已修复。已 rebase 到 upstream/master,Poke 构造保持 #5773 的 Poke(id=...) 不变,本 PR 不再改动这行
There was a problem hiding this comment.
这部分推送的代码还做了如下修复:过滤 aiocqhttp 适配器中的空消息事件
问题
在某些操作(如 skill 调用发送文件)完成后,部分 QQ 协议端(NapCat、Lagrange 等)会推送一条
post_type 为 "message" 但 message 为空数组、raw_message 为空字符串的幽灵消息事件。
该空消息会进入 pipeline,在私聊场景下触发 LLM 回复,询问用户为什么发了空白消息——但用户实际上并没有发送任何消息。
原因
_convert_handle_message_event 在返回前没有检查解析后的消息是否为空。
同类方法 _convert_handle_notice_event 已经有对应的空消息过滤逻辑,但 _convert_handle_message_event 缺少这一检查。
修复
- 在
_convert_handle_message_event末尾增加空消息检查:当abm.message为空且message_str为空白时,
记录 debug 日志并返回None,阻止空消息进入 pipeline。 - 将返回类型注解从
AstrBotMessage更新为AstrBotMessage | None以匹配新逻辑。
调用方convert_message已正确处理None返回值。
改动文件
astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py
Mobile QQ sends an empty
noticeevent (e.g. input status change) when the user taps the input box and then leaves the chat page. The aiocqhttp adapter did not filter out these empty notice events, causing them to enter the pipeline and get forwarded to the LLM as blank user messages.手机 QQ 在用户点击输入框后离开聊天页面时,会发送一个空的
notice事件(如输入状态变化通知)。aiocqhttp 适配器未过滤这些空通知事件,导致它们进入消息流水线并作为空白用户消息被转发给 LLM。Modifications / 改动点
File:
astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py_convert_handle_notice_event(core fix): Added a check at the end of the method — if no meaningful message component (e.g. Poke) was produced from the notice event, returnNoneto prevent it from entering the pipeline. Updated return type annotation toAstrBotMessage | None.convert_message(defensive): AddedNonecheck for_convert_handle_message_eventreturn value before accessingabm.sender.user_id._convert_handle_notice_event(核心修复):在方法末尾增加判断,若通知事件未产生任何有意义的消息组件(如 Poke),则返回None,阻止其进入流水线。同时更新返回类型注解为AstrBotMessage | None。convert_message(防御性措施):对_convert_handle_message_event的返回值增加None检查,防止访问abm.sender.user_id时出现异常。Screenshots or Test Results / 运行截图或测试结果
Before fix / 修复前:
Tapping the input box on mobile QQ and leaving the chat page produced empty messages that were sent to the LLM.
在手机 QQ 点击输入框后离开聊天页面,会产生空消息并被发送给 LLM。
After fix / 修复后:
Tapping the input box on mobile QQ and leaving the chat page no longer produces empty message logs. Normal messages are unaffected.
修复后,在手机 QQ 点击输入框后离开聊天页面不再产生空消息日志,正常消息不受影响。
Checklist / 检查清单
Summary by Sourcery
防止空的 aiocqhttp 通知事件被转换为用户消息,并强化消息转换的处理逻辑。
Bug 修复:
增强:
None检查,并在 aiocqhttp 适配器中调整戳一戳(poke)通知消息的构造方式。Original summary in English
Summary by Sourcery
Prevent empty aiocqhttp notice events from being converted into user messages and harden message conversion handling.
Bug Fixes:
Enhancements: