Skip to content

fix: keep weixin_oc polling after inbound timeouts#6915

Merged
Soulter merged 2 commits intoAstrBotDevs:masterfrom
1zzxy1:fix/weixin-oc-inbound-timeout
Mar 25, 2026
Merged

fix: keep weixin_oc polling after inbound timeouts#6915
Soulter merged 2 commits intoAstrBotDevs:masterfrom
1zzxy1:fix/weixin-oc-inbound-timeout

Conversation

@1zzxy1
Copy link
Contributor

@1zzxy1 1zzxy1 commented Mar 25, 2026

Summary

  • treat weixin_oc inbound long-poll timeouts as recoverable instead of exiting the adapter loop
  • keep the adapter polling after TimeoutError from getupdates
  • add a regression test covering the timeout recovery path

Closes #6901

Testing

  • uv run --group dev pytest tests/test_weixin_oc_adapter.py -q

Summary by Sourcery

Handle Weixin OC inbound long-poll timeouts as recoverable errors so the adapter continues polling instead of exiting.

Bug Fixes:

  • Prevent the Weixin OC adapter run loop from terminating when inbound long-polling getupdates calls raise asyncio.TimeoutError.

Tests:

  • Add a regression test verifying the Weixin OC adapter continues polling, logs the timeout, and shuts down cleanly after an inbound long-poll timeout.

@auto-assign auto-assign bot requested review from Soulter and anka-afk March 25, 2026 03:30
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 25, 2026
@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 addresses an issue where the weixin_oc adapter would cease operation if an inbound long-poll request timed out. The changes introduce robust error handling for asyncio.TimeoutError within the polling mechanism, allowing the adapter to log the timeout and continue its polling cycle without interruption. This ensures the weixin_oc integration remains resilient and continuously processes updates even under transient network conditions or slow responses.

Highlights

  • Timeout Handling: The weixin_oc adapter now gracefully handles asyncio.TimeoutError during inbound long-polling, treating these timeouts as recoverable events rather than fatal errors that stop the adapter.
  • Continuous Polling: The adapter's main loop will continue to poll for updates even after encountering an asyncio.TimeoutError from the _poll_inbound_updates method, ensuring service continuity.
  • Regression Test: A new regression test has been added to specifically cover the scenario where an inbound long-poll timeout occurs, verifying that the adapter recovers and continues its operation as expected.
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.

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.

@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 25, 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 modifies the weixin_oc_adapter to gracefully handle asyncio.TimeoutError during inbound long-polling, logging the timeout and ensuring the polling loop continues. A new test case has been added to verify this behavior. The review suggests an improvement in the new test to use patch.object for mocking, which would enhance robustness and clarity.

Comment on lines +35 to +40
adapter._poll_inbound_updates = fake_poll_inbound_updates # type: ignore[method-assign]

with patch(
"astrbot.core.platform.sources.weixin_oc.weixin_oc_adapter.logger"
) as mock_logger:
await adapter.run()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve test robustness and clarity, consider using patch.object as a context manager for monkey-patching. This practice ensures that the original method is restored automatically after the test, even in case of errors, and it eliminates the need for a type: ignore comment.

    with patch.object(adapter, '_poll_inbound_updates', new=fake_poll_inbound_updates):
        with patch('astrbot.core.platform.sources.weixin_oc.weixin_oc_adapter.logger') as mock_logger:
            await adapter.run()

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 25, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 25, 2026
@Soulter Soulter merged commit 2031f3d into AstrBotDevs:master Mar 25, 2026
6 checks passed
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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants