fix: split long qqofficial messages by 4000-char limit - #9592
Open
wcqqq1214 wants to merge 2 commits into
Open
Conversation
wcqqq1214
marked this pull request as ready for review
August 7, 2026 14:33
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
_split_message, usingremaining = remaining[split_point:].lstrip()can drop leading spaces/newlines between chunks, so the concatenated chunks no longer exactly match the original text for typical prose; consider avoiding.lstrip()or narrowing what you strip to preserve content faithfully. - The fallback order for
_SPLIT_PATTERNScurrently relies on dictionary insertion order; if the paragraph → line → sentence → word priority is important long-term, consider switching to an explicit ordered sequence to make the intended split hierarchy clearer and less fragile.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_split_message`, using `remaining = remaining[split_point:].lstrip()` can drop leading spaces/newlines between chunks, so the concatenated chunks no longer exactly match the original text for typical prose; consider avoiding `.lstrip()` or narrowing what you strip to preserve content faithfully.
- The fallback order for `_SPLIT_PATTERNS` currently relies on dictionary insertion order; if the paragraph → line → sentence → word priority is important long-term, consider switching to an explicit ordered sequence to make the intended split hierarchy clearer and less fragile.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Modifications / 改动点
Fixes #9591 — QQ Official replies longer than 4000 chars get truncated by the platform (error code 40054007). The qqofficial adapter previously sent the full text as-is with no length-based splitting, mirroring how the Telegram adapter splits long messages at 4096 chars.
astrbot/core/platform/sources/qqofficial/qqofficial_message_event.pyQQ_MAX_LENGTH = 4000and_split_message(), which splits over-long text at natural boundaries (paragraph → line → sentence → word → hard cut), aligned with the Telegram adapter's_split_message._split_message_chain_by_length(): applied after the existing media-based split, splitting text-only and media-caption chains longer than 4000 chars into multiple ≤4000-char messages. Media components are kept in the first chunk._post_send(), when a C2C streaming flush splits into multiple chains, only the last chain carries thestreampayload (the rest are sent non-stream), keeping the QQ stream session id continuous so the finalstate=10terminates correctly.astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py_send_by_session_common()so proactive pushes are split too.tests/test_qqofficial_message_length_split.py(new)This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Verification steps: ask the bot for a reply longer than 4000 characters via the QQ Official adapter, then confirm the reply arrives as multiple consecutive messages, each within the limit, with no truncation.
Real verification log (local run with temporary instrumentation; a 4425-char reply split into 2 messages, both sent successfully, no 40054007 error):
Temporary instrumentation code used for the verification above (added only to observe the split count; not part of this PR's final diff):
Screenshot / 截图位置:
In the second image, you can see that the message is split correctly.
Note:
ruff check .andruff format --check .pass, and the targeted test file passes (8 tests).Checklist / 检查清单
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
/ 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。
/ 我确保没有引入新依赖库。
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Enforce QQ Official single-message length limits by splitting long texts and ensure streaming and proactive messages are sent as multiple bounded chunks.
Bug Fixes:
Enhancements:
Tests: