Repository navigation
Conversation
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/platform/sources/qqofficial/qqofficial_message_event.py" line_range="698-711" />
<code_context>
- ret = await send_func(fallback_payload)
- logger.info("[QQOfficial] 使用主动发送接口发送成功。")
- return ret
- except _QQOFFICIAL_SEND_API_ERRORS as fallback_err:
- err = fallback_err
- payload = fallback_payload
-
- if not isinstance(err, botpy.errors.ServerError):
- raise
</code_context>
<issue_to_address>
**Markdown fallback is skipped**
When the passive send fails for a non-Markdown reason and the active retry is rejected for Markdown, `_send_with_markdown_fallback` propagates the active retry's Markdown error before attempting the plain-content downgrade, so the message is lost.
Route Markdown rejection from the active retry through the plain-content fallback.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the fallback classification or reply-reference handling is wrong, the code can send an unintended proactive or duplicate message, or retry with an invalid reference; those messages are externally delivered and cannot be undone by reverting the change. The impact is bounded to affected sends, but correcting the code will not retract messages already sent.
Blocking findings: astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py:711
|
The sourcery finding was real. Traced it: a passive send failing for a non-markdown reason (expired msg_id) drops into the active retry with the markdown payload still intact, and when that retry is rejected for markdown the error propagated before any plain-content downgrade, so the message was lost. Fixed in 0d456f6: the active retry's markdown rejection now routes through the same plain-content downgrade (markdown popped, msg_type 2 to 0, stream newline fix kept). The reference retry order is unchanged, so a valid message_reference still survives. Added a regression test that pins the three-call sequence (passive fail, active markdown rejection, downgraded send) and verified it goes red without the fix. |
When the QQ official API refuses a native markdown payload, the fallback used to drop msg_id and resend through the active-message interface, which runs into the 304049 active-message rate limit and loses the reply threading. Reorder the fallback so a rejected markdown degrades to a plain content reply that keeps msg_id (passive reply, msg_type reset from 2 to 0, stream trailing newline restored). The stream newline repair retry also keeps msg_id. Only errors that are not markdown rejections take the active-send fallback, and if the active retry itself hits the markdown rejection (the passive failure was unrelated, e.g. an expired msg_id) it downgrades to plain content too instead of losing the message. Fallback raises are chained so the original rejection stays visible in logs.
0d456f6 to
c0321a2
Compare
|
重建说明:这个 PR 原本叠在 #10401 的两个提交上。#10489 已把出站 message_reference 的填充合进 master(595f990b6),走的是 msg_idx 语义,比 #10401 的裸 id 透传更正确,所以叠放部分整个摘掉,改为在 master 上重放本修复,diff 现在只剩 fallback 重排和 4 个测试。此前那个 follow-up(主动重试也撞 markdown 拒绝时同样降级纯 content)也一并带上了。 验证:tests/test_qqofficial_group_message_create.py 41/41 过;拿 master 版 helper 跑 markdown-rejected 和 stream-newline 两个用例定败(负对照),本分支定过。 |
…d of the fallback The markdown-rejected (50056) path must keep msg_id and degrade to a plain content passive reply. Dropping msg_id first turns a passive reply into an active message, which burns the active quota and can fail outright (304049). Upstream added event_id to the active-send fallback; the merge keeps that while restoring the markdown-rejected intercept before the fallback so msg_id is not dropped on that path. The later markdown handler upstream carries runs after the fallback and cannot prevent the msg_id drop, so the intercept is still needed. Validation (CPU): tests/test_qqofficial_group_message_create.py 43 passed.
Sourcery withdrew this approval because the latest commits introduced blocking findings.
|
Fixed in Reproduced locally as |
|
@Soulter @clown145 Could you review When QQOfficial rejects a Markdown send, this keeps the fallback as a passive reply instead of retrying into another active delivery path. The quoted reply IDs remain explicit rather than inferred from an earlier message. @clown145, your recent QQOfficial event changes are the closest ownership match. Could you check that the fallback does not duplicate or reclassify the outgoing message? |
|
@Soulter @clown145 The current-master merge is now Could you review the fallback ordering? Markdown rejection and the stream-newline correction keep |
Linked issuesChecked at commit a7de68e #10420 [Bug] QQ频道消息无法回复:markdown 回退顺序有误,误用主动消息导致 304049 限频 · 2 of 2 met
|
Fixes #10420.
When the QQ official API refuses a native markdown payload, the current fallback in
_send_with_markdown_fallbackdropsmsg_idand resends through the active-message interface. Active messages are quota limited (304049), so a rejected markdown turns an ordinary reply into a rate-limit error and the message is lost.This branch is based directly on current master. The earlier #10401 dependency was removed after #10489 landed the message_reference behavior in master.
Modifications / 改动点
qqofficial_message_event.py: reorder the fallback so a rejected markdown degrades to a plaincontentreply that keepsmsg_id, staying a passive reply (msg_type reset from 2 to 0, stream trailing newline restored before the retry). The stream newline correction also runs before the active-send fallback, so that retry keepsmsg_idinstead of becoming a proactive message. Only unrelated errors go to the active-send fallback, which keeps the message_reference two-stage retry landed through #10489. Fallback raises are chained so the original rejection stays visible in the logs.test_qqofficial_group_message_create.py: four tests covering the markdown-rejected passive path, the non-markdown active fallback, the stream newline retry, and markdown rejection after an active retry.Screenshots or Test Results / 运行截图或测试结果
On merged head
a7de68ed1c6b1149ab50948e067f0cbe070f8dd3, all eight QQOfficial test modules pass 144 tests under Python 3.12.12. The stream newline test failed before the ordering fix withKeyError: msg_idand now passes together with the active-send control. Red/green was also verified for the original markdown-rejected behaviors. Current master841295fa938d2cd028b9e0cb832f293c5c5c0d4bis merged without a rebase or force push.ruff check,ruff format --check, and PR-scopedgit diff --checkpass on both touched files. No live QQ traffic or credentials were used.Checklist / 检查清单
Summary by Sourcery
Keep QQOfficial markdown fallback replies passive to avoid unnecessary active-message quota failures and lost messages.
Bug Fixes:
Tests: