Skip to content

fix(session_waiter): bind empty-mention waiter to the initiating sender (#9377) - #9422

Open
Qixuan112 wants to merge 2 commits into
AstrBotDevs:masterfrom
Qixuan112:fix/9377-empty-mention-waiter-sender-binding
Open

fix(session_waiter): bind empty-mention waiter to the initiating sender (#9377)#9422
Qixuan112 wants to merge 2 commits into
AstrBotDevs:masterfrom
Qixuan112:fix/9377-empty-mention-waiter-sender-binding

Conversation

@Qixuan112

@Qixuan112 Qixuan112 commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Fixes #9377

Problem

When a user sent an empty @mention (or wake-prefix-only message) in a group chat, the empty_mention_waiter used DefaultSessionFilter which keyed sessions only by event.unified_msg_origin (the group/conversation ID). This meant any subsequent message from any member in that group would trigger the waiter and be consumed via event.stop_event(), causing other members' messages to be silently intercepted.

Fix

Added a custom _SenderSessionFilter that includes event.get_sender_id() in the session key:

class _SenderSessionFilter(SessionFilter):
    def filter(self, ev: AstrMessageEvent) -> str:
        return f"{ev.unified_msg_origin}:{ev.get_sender_id()}"

This ensures the waiter only responds to messages from the same sender who initiated the empty mention, matching expected multi-user group chat behavior.

Changes

  • astrbot/builtin_stars/astrbot/main.py: imported SessionFilter, added a sender-scoped filter for empty_mention_waiter (+6/-1 lines)

Summary by Sourcery

Bug Fixes:

  • Ensure empty-mention waiters in group chats only consume follow-up messages from the original sender instead of any group member.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 28, 2026

@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 left some high level feedback:

  • Consider moving _SenderSessionFilter out of handle_empty_mention into module scope so it isn’t redefined on every call and can be reused or tested independently.
  • When building the session key in _SenderSessionFilter.filter, consider explicitly handling cases where get_sender_id() might be None or unexpected to avoid collisions or hard-to-debug behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider moving `_SenderSessionFilter` out of `handle_empty_mention` into module scope so it isn’t redefined on every call and can be reused or tested independently.
- When building the session key in `_SenderSessionFilter.filter`, consider explicitly handling cases where `get_sender_id()` might be `None` or unexpected to avoid collisions or hard-to-debug behavior.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 28, 2026
@Qixuan112

Copy link
Copy Markdown
Author

Addressed both suggestions in dfd6c00:

  • Moved _SenderSessionFilter to module scope so it's defined once and independently testable.
  • Guarded against empty/falsy sender_id in filter() by substituting a sentinel (__unknown_sender__), avoiding accidental key collisions if a platform fails to supply a sender ID.

(🤖 Addressed by Claude Code)

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

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 群聊中空提及等待器会截获其他成员的消息(session_waiter 未绑定发送者)

1 participant