fix: isolate session waiters by sender - #9770
Open
icyaaaww wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/utils/session_waiter.py" line_range="101" />
<code_context>
- """默认实现,返回统一消息来源字符串作为会话标识符"""
- return event.unified_msg_origin
+ """Return a session identifier scoped to the current sender and chat."""
+ return f"{event.unified_msg_origin}:{event.get_sender_id()}"
</code_context>
<issue_to_address>
**issue (bug_risk):** The delimiter-based key `f"{event.unified_msg_origin}:{event.get_sender_id()}"` is not injective: a colon in the chat/session origin or sender ID produces the same key as a different origin/sender pair. Those distinct waiters overwrite or trigger one another in `USER_SESSIONS`.
**Triggers:** When a platform supplies a session origin or sender ID containing `:`.
**Suggested fix:** Encode the two components without ambiguity, for example by using a tuple key or length-prefixed/escaped serialization.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: astrbot/core/utils/session_waiter.py:101
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| """默认实现,返回统一消息来源字符串作为会话标识符""" | ||
| return event.unified_msg_origin | ||
| """Return a session identifier scoped to the current sender and chat.""" | ||
| return f"{event.unified_msg_origin}:{event.get_sender_id()}" |
Contributor
There was a problem hiding this comment.
issue (bug_risk): The delimiter-based key f"{event.unified_msg_origin}:{event.get_sender_id()}" is not injective: a colon in the chat/session origin or sender ID produces the same key as a different origin/sender pair. Those distinct waiters overwrite or trigger one another in USER_SESSIONS.
Triggers: When a platform supplies a session origin or sender ID containing :.
Suggested fix: Encode the two components without ambiguity, for example by using a tuple key or length-prefixed/escaped serialization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
DefaultSessionFilterreturned onlyevent.unified_msg_origin. For group messages, that origin identifies the group rather than the sender, so any member's next message could be routed into another member's active session waiter. This also contradicted the documented sender-scoped default behavior.Testing
uv run pytest tests/unit/test_session_waiter.py tests/unit/test_event_bus.py tests/unit/test_astr_message_event.py -q(97 passed)uv run ruff check astrbot/core/utils/session_waiter.py tests/unit/test_session_waiter.pyuv run ruff format --check astrbot/core/utils/session_waiter.py tests/unit/test_session_waiter.pyFull-suite note:
uv run pytest -qreached 2153 passed and 1 skipped; 39 existing Windows-specific/environment failures remained around symlink privileges, PowerShell quoting, and path expectations. No session waiter tests failed.Summary by Sourcery
Scope default session waiter identifiers to the originating chat and sender to prevent cross-user session routing.
Bug Fixes:
Tests: