[Bug] provider_settings.wake_prefix 未随 #9215 豁免 WebChat,WebChat 仍须带前缀才触发 LLM
问题描述
#9215(commit ab4de0464,fix: exempt WebChat from friend wake prefix)已经让唤醒阶段的私聊判定豁免了 WebChat:
# astrbot/core/pipeline/waking_check/stage.py
# 检查是否是私聊
if event.is_private_chat() and (
not self.friend_message_needs_wake_prefix
or event.get_platform_name() == "webchat"
):
但**「额外唤醒前缀」这一层没有同步豁免**,导致在 WebChat 里仍然必须带前缀才能触发 LLM,而且是静默丢弃,用户完全看不出原因。
复现步骤
配置:
"wake_prefix": ["/"], // 唤醒前缀
"provider_settings": { "wake_prefix": "chat" }, // 额外唤醒前缀
"platform_settings": { "friend_message_needs_wake_prefix": true }
操作(WebChat 平台):
- 发送不带前缀的普通消息,例如
但我在网页对话里不需要这个-> 无任何响应。日志中只有core.event_bus的入站记录,之后没有retrieval、没有respond.stage、没有 agent 运行。 - 发送
/chat 但我在网页对话里不需要这个-> 正常响应。
日志实证(logs/astrbot.log):
20:31:38.121 [Core] [INFO] [core.event_bus:74]: [default] [webchat(webchat)] astrbot/astrbot: 但我在网页对话里不需要这个
(此后无任何输出,沉默)
20:44:07.441 [Core] [INFO] [core.event_bus:74]: [default] [webchat(webchat)] astrbot/astrbot: /chat 但我在网页对话里不需要这个
20:44:35.162 [Core] [INFO] [retrieval.dual_path:402]: 执行检索: query='但我在网页对话里不需要这个 [MSG_ID:...]'
20:44:36.086 [Core] [INFO] [respond.stage:212]: Prepare to send - astrbot/astrbot:
注意第 2 条的检索 query:/ 与 chat 被两层依次剥离,只剩用户原话。这印证了两层门槛叠加后的等效要求是 /chat。
相关代码
astrbot/core/pipeline/process_stage/method/agent_request.py
self.bot_wake_prefixs: list[str] = self.config["wake_prefix"]
self.prov_wake_prefix: str = self.config["provider_settings"]["wake_prefix"]
for bwp in self.bot_wake_prefixs:
if self.prov_wake_prefix.startswith(bwp):
...
self.prov_wake_prefix = self.prov_wake_prefix[len(bwp):]
astrbot/core/astr_main_agent.py(实际拦截点,无任何平台豁免)
if config.provider_wake_prefix and not event.message_str.startswith(
config.provider_wake_prefix
):
return None, None
上游 master 当前版本两处均与上述一致,即 #9215 之后这一层并未被处理。
期望行为
既然 #9215 的理由是「WebChat 是点对点会话,不应有私聊唤醒门槛」,那么同为唤醒门槛语义的 provider_settings.wake_prefix 也应一视同仁地对 WebChat 豁免,例如:
if (
config.provider_wake_prefix
and event.get_platform_name() != "webchat"
and not event.message_str.startswith(config.provider_wake_prefix)
):
return None, None
或退一步,在 WebChat 上至少不要静默丢弃,给出可排查的日志。
影响
WebChat 是面板内点对点会话,通常只有管理员本人使用,「前缀才放行」没有实际意义,却会造成「发了消息没反应」的困惑;排查成本高,因为拦截点是静默 return None, None。
环境
- AstrBot 版本:
4.28.1 - 平台:WebChat
platform_settings.friend_message_needs_wake_prefix = true
注:
provider_settings.wake_prefix出厂默认为空,此问题在默认配置下不出现;但该配置项一旦被设置(本例为chat),WebChat 便会被一并拦截。建议参考#9215的处理方式对齐。
结论:成立。在 master 69ae35a 上按报告配置(provider_settings.wake_prefix 非空 + platform_settings.friend_message_needs_wake_prefix = true + WebChat)可复现:不带前缀的消息被丢弃,且丢弃路径无任何日志。
根因:
astrbot/core/astr_main_agent.py:1451-1454@69ae35a(collect_initial_request):config.provider_wake_prefix非空且event.message_str不以它开头时直接return None, None,未做任何平台判定。#9215只修改了另一层:astrbot/core/pipeline/waking_check/stage.py:152-154的私聊唤醒判定,这一层未同步处理。- 静默的成因:
astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py:230-238,build_result is None且无 error extra 时直接return,既不回复也不记录日志。 - 同类路径还有第三方 runner:
astrbot/core/pipeline/process_stage/method/agent_sub_stages/third_party.py:283-286,同样无平台豁免。
补充核查(报告未涉及的部分):
唤醒门槛目前共三层,只有一层带平台豁免:
| 层 | 位置 | 平台豁免 |
|---|---|---|
bot 唤醒词(/) |
astrbot/core/pipeline/waking_check/stage.py:114-131 |
无(通用匹配) |
| 私聊需唤醒词 | astrbot/core/pipeline/waking_check/stage.py:152-154 |
有,webchat(#9215) |
| 额外唤醒前缀 | astrbot/core/astr_main_agent.py:1451-1454(内置)astrbot/core/pipeline/process_stage/method/agent_sub_stages/third_party.py:283-286(第三方) |
无 |
由此有两点值得一并确认:
- 影响范围不止 WebChat。该层是面向所有平台、所有会话类型的通用门槛,群聊同样受限:配置
provider_settings.wake_prefix后,群内 @ 机器人但消息不以该前缀开头,也会被静默丢弃。这一点比 WebChat 场景更容易遇到,表现同样是「发了消息没反应」。 - 外部平台私聊不算同类问题。QQ、Telegram、Discord、飞书、企微、钉钉、微信个人号等平台被要求带前缀,符合
#9215的既定取向(该 PR 说明中写明preserve the configured wake-prefix requirement for external private-chat platforms)。WebChat 是当前唯一「本应豁免而未豁免」的平台。 - 另供参考:
wecom_ai_bot在调度层有特判(astrbot/core/pipeline/scheduler.py:94),但唤醒层未做豁免。它是否与 WebChat 同属「应用内点对点」形态、应否享有同等豁免,交由维护者判断。
建议:
- 在
astr_main_agent.py:1451与third_party.py:283增加平台豁免,与#9215对齐(如event.get_platform_name() != "webchat")。 - 长期看,建议把「面板类平台豁免」抽成统一判定(例如按
platform_meta打标记),避免今后每新增一层门槛就漏一处。 - 静默分支补一条
logger.debug,便于排查此类「无响应」。 - 补回归用例:WebChat +
provider_wake_prefix;建议同时覆盖群聊带前缀 / 不带前缀两种路径。
建议标签:bug area:core priority: p2
以上为 AI 生成内容。