Skip to content

fix: keep weixin_oc polling after getupdates timeout#6902

Closed
superjackche wants to merge 2 commits intoAstrBotDevs:masterfrom
superjackche:fix/6901-weixin-oc-long-poll-timeout
Closed

fix: keep weixin_oc polling after getupdates timeout#6902
superjackche wants to merge 2 commits intoAstrBotDevs:masterfrom
superjackche:fix/6901-weixin-oc-long-poll-timeout

Conversation

@superjackche
Copy link

@superjackche superjackche commented Mar 24, 2026

Fixes #6901.

Modifications / 改动点

This PR prevents weixin_oc from exiting when the inbound ilink/bot/getupdates long-poll hits a normal asyncio.TimeoutError.

  • handle the timeout at the getupdates request boundary inside WeixinOCAdapter._poll_inbound_updates()

  • keep other inbound processing failures on the existing fatal path, so the fix does not mask unrelated errors

  • add regression tests for both the timeout case and the non-timeout error case

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

make pr-test-full
924 passed, 5 warnings in 50.40s
Smoke test passed
Dashboard build passed

.venv/bin/pytest tests/test_weixin_oc_adapter.py
2 passed in 0.98s

Checklist / 检查清单

Summary by Sourcery

Handle Weixin OC inbound long-poll timeouts without stopping the adapter loop.

Bug Fixes:

  • Prevent the Weixin OC adapter from exiting when ilink/bot/getupdates long-polling hits a normal asyncio.TimeoutError.

Tests:

  • Add regression tests to ensure the adapter continues running after a long-poll timeout and still stops on non-timeout inbound errors.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the Weixin Official Account (OC) adapter by preventing its polling mechanism from halting due to expected getupdates long-poll timeouts. It ensures continuous operation for message retrieval while preserving the intended error handling for other critical inbound processing issues, thereby improving the adapter's stability and reliability.

Highlights

  • Error Handling: Implemented asyncio.TimeoutError catching within the _poll_inbound_updates() method of the WeixinOCAdapter to prevent the adapter loop from terminating due to getupdates long-poll timeouts.
  • Adapter Resilience: Ensured that the adapter continues polling after a getupdates timeout, while maintaining the existing fatal path for other non-timeout inbound processing failures.
  • Regression Tests: Added new regression tests to verify that the adapter correctly handles both long-poll timeouts (continuing to poll) and other inbound errors (stopping the loop).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@superjackche superjackche marked this pull request as ready for review March 24, 2026 12:27
Copilot AI review requested due to automatic review settings March 24, 2026 12:27
@auto-assign auto-assign bot requested review from Soulter and advent259141 March 24, 2026 12:27
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 24, 2026
Copy link
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 effectively resolves the issue where the weixin_oc adapter would crash due to a long-poll timeout. The implementation correctly catches the asyncio.TimeoutError within _poll_inbound_updates, ensuring the adapter remains operational. The addition of regression tests is a valuable contribution, as they thoroughly validate both the fix for timeout scenarios and the preservation of failure behavior for other errors. The changes are well-executed and enhance the adapter's stability.

@dosubot dosubot bot added the area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. label Mar 24, 2026
Copy link
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 reviewed your changes and they look great!


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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes issue #6901 by making the weixin_oc adapter resilient to normal inbound ilink/bot/getupdates long-poll timeouts, so it continues polling instead of exiting the adapter run() loop.

Changes:

  • Handle asyncio.TimeoutError inside WeixinOCAdapter._poll_inbound_updates() and treat it as a non-fatal polling boundary case.
  • Preserve existing fatal behavior for non-timeout exceptions to avoid masking unrelated inbound failures.
  • Add regression tests covering both the timeout-retry path and the non-timeout error path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py Catch inbound long-poll timeout at the request boundary and return to the main loop without aborting the adapter.
tests/test_weixin_oc_adapter.py Add tests ensuring run() continues after a timeout and stops on a non-timeout inbound exception.

@Soulter
Copy link
Member

Soulter commented Mar 25, 2026

#6915 has a better way to fix this issue, thanks!

@Soulter Soulter closed this Mar 25, 2026
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. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] weixin_oc 的 getupdates 长轮询超时后会导致适配器退出

3 participants