Skip to content

fix: surface weixin media send failures#8175

Merged
Soulter merged 3 commits into
AstrBotDevs:masterfrom
he-yufeng:fix/weixin-media-send-failure
May 14, 2026
Merged

fix: surface weixin media send failures#8175
Soulter merged 3 commits into
AstrBotDevs:masterfrom
he-yufeng:fix/weixin-media-send-failure

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

@he-yufeng he-yufeng commented May 13, 2026

Fixes #8160.

Summary

  • return a real error path when weixin_personal media segment sending fails
  • include traceback details for prepare-media failures, including timeout errors whose string is empty
  • add a focused unit test so failed media sends no longer look successful

Test plan

  • .venv/Scripts/python.exe -m pytest tests/unit/test_weixin_oc_adapter.py -q -p no:cacheprovider --basetemp .tmp/pytest
  • .venv/Scripts/python.exe -m ruff check astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py tests/unit/test_weixin_oc_adapter.py
  • .venv/Scripts/python.exe -m ruff format --check astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py tests/unit/test_weixin_oc_adapter.py
  • .venv/Scripts/python.exe -m py_compile astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py tests/unit/test_weixin_oc_adapter.py
  • git diff --check
  • Select-String secret scan on changed files

Summary by Sourcery

Handle Weixin personal outbound message failures more robustly and ensure they are surfaced to callers.

Bug Fixes:

  • Log full tracebacks for media preparation failures in the Weixin OC adapter.
  • Propagate failures from media and text segment sends by raising when any segment fails instead of silently succeeding.

Tests:

  • Add a unit test verifying that send_by_session raises when a media segment send fails.

@auto-assign auto-assign Bot requested review from LIghtJUNction and anka-afk May 13, 2026 11:03
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. labels May 13, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Consider including the session/user identifier in the RuntimeError message (e.g., self.meta().id or target_user) so failures are easier to trace back in logs and error reporting.
  • Instead of raising a generic RuntimeError, you might want to introduce or reuse a more specific exception type for outbound send failures so callers can distinguish this from other runtime issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider including the session/user identifier in the `RuntimeError` message (e.g., `self.meta().id` or `target_user`) so failures are easier to trace back in logs and error reporting.
- Instead of raising a generic `RuntimeError`, you might want to introduce or reuse a more specific exception type for outbound send failures so callers can distinguish this from other runtime issues.

## Individual Comments

### Comment 1
<location path="astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py" line_range="1651-1654" />
<code_context>
                 "weixin_oc(%s): outbound message ignored, no supported segments",
                 self.meta().id,
             )
+        if failed_segments:
+            raise RuntimeError(
+                f"weixin_oc failed to send {failed_segments} message segment(s)"
+            )
</code_context>
<issue_to_address>
**suggestion:** Include contextual identifiers in the exception message for easier traceability.

Right now the `RuntimeError` only reports the number of failed segments. Please include key identifiers (e.g. `self.meta().id`, `session.session_id` or `target_user`) so operators can correlate this failure with logs and external systems, e.g.: `f"weixin_oc({self.meta().id}, session={session.session_id}) failed to send {failed_segments} segment(s)"`.

```suggestion
        if failed_segments:
            raise RuntimeError(
                f"weixin_oc({self.meta().id}, target_user={target_user}) "
                f"failed to send {failed_segments} message segment(s)"
            )
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves error handling in the WeixinOC adapter by tracking failed message segments and raising a RuntimeError if any segment fails to send. It also updates the logging to include exception information for better debugging and adds a unit test to verify that the adapter correctly raises an error when media segments fail to send.

@he-yufeng
Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in 34beb5f: the RuntimeError now includes the WeixinOC adapter id and target_user, and the regression assertion checks that context. Validation passed: focused WeixinOC adapter test, py_compile on the touched files, and ruff check on the touched files.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 14, 2026
@Soulter Soulter merged commit 094c2de into AstrBotDevs:master May 14, 2026
20 checks passed
RC-CHN pushed a commit to RC-CHN/AstrBot that referenced this pull request May 18, 2026
* fix: surface weixin media send failures

* fix: include weixin send failure context

* Delete tests/unit/test_weixin_oc_adapter.py

---------

Co-authored-by: Weilong Liao <37870767+Soulter@users.noreply.github.com>
EterUltimate pushed a commit to EterUltimate/AstrBot that referenced this pull request May 19, 2026
* fix: surface weixin media send failures

* fix: include weixin send failure context

* Delete tests/unit/test_weixin_oc_adapter.py

---------

Co-authored-by: Weilong Liao <37870767+Soulter@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]在个人微信weixin_personal 中,如果文件发送超时,模型也会视作文件发送成功

2 participants