fix(waking_check): guard wake-prefix check against empty message chain#8832
Open
he-yufeng wants to merge 1 commit into
Open
fix(waking_check): guard wake-prefix check against empty message chain#8832he-yufeng wants to merge 1 commit into
he-yufeng wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds a safety check to ensure that the messages list is not empty before attempting to access its first element in WakingCheckStage.process. This prevents potential IndexError crashes when processing events with empty message chains. Additionally, corresponding unit tests have been introduced to verify this fix. I have no further feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
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.
问题
WakingCheckStage在群聊里检查 wake-prefix 时,会无条件地访问messages[0]:当
messages = event.get_messages()为空列表时,这里会抛IndexError: list index out of range。两种常见触发:wake_prefix配成了空字符串""(让机器人对任何消息都唤醒),此时message_str.startswith("")恒为真;message_str)但消息段列表为空(例如某些转发 / 系统类负载)。只要同时满足「群聊 + message_str 命中 wake_prefix + 消息段为空」,唤醒检查就会崩在
messages[0]。修复
在
isinstance(messages[0], At)前加一个and messages短路:消息段为空时不是「@ 了别人」,应当正常唤醒,而不是崩溃。改动只有一行,其余分支行为不变。测试
新增
tests/unit/test_waking_check_stage.py,覆盖空 wake-prefix 和非空 wake-prefix 两种情况下消息段为空的场景。两个用例在改动前都会因messages[0]抛IndexError,改动后通过;tests/unit/test_astr_message_event.py(78 个)保持全绿。Summary by Sourcery
Prevent group wake-prefix checking from crashing on events with an empty message chain.
Bug Fixes:
Tests: