fix: apply forward threshold to send_message_to_user#9242
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates message_tools.py to apply the aiocqhttp forward threshold to tool messages, wrapping long messages in a merged-forward node when they exceed the threshold. It also adds corresponding unit tests. The review feedback highlights two key improvements: first, adding defensive handling in message_tools.py for cases where get_config returns None or the threshold is not a valid integer; second, fixing a false-positive unit test where a missing mock for get_platform_name caused the threshold logic to be bypassed entirely.
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.
8675f88 to
4ed9bca
Compare
4ed9bca to
ac70a21
Compare
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The forward-threshold logic you’ve added here duplicates behavior that likely already exists in
ResultDecorateStage; consider extracting this into a shared helper so the QQ forwarding rules stay consistent in one place. - Instead of manually iterating over
message_chain.chainto computeword_cntforComp.Plaincomponents, you could reusemessage_chain.get_plain_text()and take its length, which would simplify the logic and reduce the risk of divergence ifMessageChainbehavior changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The forward-threshold logic you’ve added here duplicates behavior that likely already exists in `ResultDecorateStage`; consider extracting this into a shared helper so the QQ forwarding rules stay consistent in one place.
- Instead of manually iterating over `message_chain.chain` to compute `word_cnt` for `Comp.Plain` components, you could reuse `message_chain.get_plain_text()` and take its length, which would simplify the logic and reduce the risk of divergence if `MessageChain` behavior changes.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
thanks for your contribution, but we have no plan on this feature. |
Fixes #8678.
Modifications / 改动点
Apply the existing
platform_settings.forward_thresholdrule tosend_message_to_useroutput.Limit conversion to messages sent from an
aiocqhttpevent through the same adapter instance, where a valid bot UIN is available.Preserve plain-message behavior for cron, cross-platform, cross-instance, and non-
aiocqhttpsends.Keep current-session duplicate reply suppression unchanged by recording plain text before wrapping the message in a forward node.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Verification:
uv run pytest tests/unit/test_message_tools.py tests/unit/test_func_tool_manager.py tests/unit/test_astr_agent_tool_exec.py -q— 50 passed.uv run ruff format --check .— 480 files already formatted.uv run ruff check .— passed.git diff --check origin/master— passed.Regression coverage includes the strict
>boundary, same-instance forwarding, current-session deduplication, and the cron/cross-platform fallback to plain messages.Checklist / 检查清单
Summary by Sourcery
Apply QQ forward-threshold handling to SendMessageToUserTool while preserving existing plain-message behavior and current-session deduplication.
Bug Fixes:
Tests: