Skip to content

fix: separate handler matching from wake state - #10774

Open
helo060228 wants to merge 2 commits into
AstrBotDevs:masterfrom
helo060228:feat/separate-wake-state
Open

helo060228 wants to merge 2 commits into
AstrBotDevs:masterfrom
helo060228:feat/separate-wake-state

Conversation

@helo060228

@helo060228 helo060228 commented Oct 26, 2026 •

Copy link
Copy Markdown

Summary

  • Keep event.is_wake focused on explicit user intent: @ mentions, wake prefixes, private-chat policy, and session waiters.
  • Expose matched plugin handlers through event.matched_handlers while preserving activated_handlers.
  • Allow ambient listener handlers to run without treating ordinary group messages as LLM wake-ups.

Verification

  • pytest tests/unit/test_waking_check_wake_state.py tests/unit/test_command_group_filter.py tests/unit/test_session_waiter_pipeline.py tests/unit/test_astr_message_event.py -q — 117 passed
  • ruff check astrbot/core/platform/astr_message_event.py astrbot/core/pipeline/waking_check/stage.py tests/unit/test_waking_check_wake_state.py
  • git diff --check

Closes #10699

Summary by Sourcery

Separate plugin handler matching from explicit wake-state determination so ambient listeners can process ordinary messages without waking the LLM.

New Features:

  • Expose plugin handlers that pass message filters through the event’s matched_handlers property.

Bug Fixes:

  • Prevent ordinary group messages matched by ambient listeners from being treated as LLM wake-ups.
  • Preserve explicit wake behavior for mentions and wake commands while allowing matched listeners to continue through processing.

Enhancements:

  • Clarify event wake-state semantics so is_wake represents explicit user intent rather than handler matching.

Tests:

  • Add coverage for ambient handler matching, process-stage continuation, and explicit mention wake-ups.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/platform/astr_message_event.py" line_range="103" />
<code_context>
+        """通过消息过滤器的插件处理器,不代表事件已唤醒机器人。"""
         self.is_at_or_wake_command = False
-        """是否是 At 机器人或者带有唤醒词或者是私聊(插件注册的事件监听器会让 is_wake 设为 True, 但是不会让这个属性置为 True)"""
+        """是否是 At 机器人或者带有唤醒词或者是私聊"""
         self._extras: dict[str, Any] = {}
         self._force_stopped: bool = False
</code_context>
<issue_to_address>
**Private chats misdocumented as always active**

When `friend_message_needs_wake_prefix` is enabled for a non-webchat private message, the field comment says every private chat sets `is_at_or_wake_command`, but `WakingCheckStage` leaves it false for private messages when `friend_message_needs_wake_prefix` is enabled (except webchat). Callers relying on the comment will misinterpret the event’s wake intent.

Clarify in the field comment that private chats set this flag only when prefix requirements allow it.
</issue_to_address>

### Comment 2
<location path="astrbot/core/platform/astr_message_event.py" line_range="100" />
<code_context>
         """用户是否是管理员。如果是管理员,这里是 admin"""
         self.is_wake = False
         """是否唤醒(是否通过 WakingStage)"""
+        self.matched_handlers: list[StarHandlerMetadata] = []
+        """通过消息过滤器的插件处理器,不代表事件已唤醒机器人。"""
         self.is_at_or_wake_command = False
</code_context>
<issue_to_address>
**New comments are not English**

The added and updated docstrings use Chinese, contrary to the repository rule that comments and logs be in English.

Write both docstrings in English.

Also at `astrbot/core/platform/astr_message_event.py:103`.
</issue_to_address>

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread astrbot/core/platform/astr_message_event.py Outdated
Comment thread astrbot/core/platform/astr_message_event.py
Describe matched_handlers as filter matches that do not imply a wake, and
state that private chats set is_at_or_wake_command only when prefix rules
allow it.

Co-authored-by: helo060228 <helo060228@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 「用户是否唤醒我」与「插件是否匹配到消息」应拆成两个独立状态

2 participants