Skip to content

fix(weixin_oc): add error handling and retry logic for inbound updates polling#7041

Merged
Soulter merged 1 commit intomasterfrom
fix/7022
Mar 27, 2026
Merged

fix(weixin_oc): add error handling and retry logic for inbound updates polling#7041
Soulter merged 1 commit intomasterfrom
fix/7022

Conversation

@Soulter
Copy link
Copy Markdown
Member

@Soulter Soulter commented Mar 27, 2026

fixes: #7022

Modifications / 改动点

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

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


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Bug Fixes:

  • Add fallback error handling for Weixin OC inbound polling failures to avoid crashing the polling loop and retry after a short delay.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Mar 27, 2026
@Soulter Soulter merged commit 777b831 into master Mar 27, 2026
6 checks passed
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 left some high level feedback:

  • Catching a bare Exception inside the polling loop may mask programming/operational errors; consider narrowing this to the specific exception(s) expected from the poll call, or at least excluding asyncio.CancelledError and other critical exceptions.
  • Instead of logging only e in the error message, consider using logger.exception (or including exc_info=True) so that the full traceback is available for diagnosing repeated polling failures.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Catching a bare `Exception` inside the polling loop may mask programming/operational errors; consider narrowing this to the specific exception(s) expected from the poll call, or at least excluding `asyncio.CancelledError` and other critical exceptions.
- Instead of logging only `e` in the error message, consider using `logger.exception` (or including `exc_info=True`) so that the full traceback is available for diagnosing repeated polling failures.

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 27, 2026
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 introduces error handling for the inbound long-poll process in the WeChat Official Account adapter, ensuring that polling failures are logged and retried after a 5-second delay instead of crashing. Feedback suggests using logger.exception to capture full tracebacks for better debugging and replacing the hardcoded retry delay with a named constant to improve code maintainability.

Comment on lines +906 to +910
logger.error(
"weixin_oc(%s): poll inbound updates failed, will retry after 5 seconds: %s",
self.meta().id,
e,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using logger.exception here will provide a full traceback in the logs, which is very helpful for debugging the root cause of the polling failure. It's generally a good practice to log the full exception context for unexpected errors, even if they are being retried. logger.exception automatically includes exception information and should be used within an except block.

                    logger.exception(
                        "weixin_oc(%s): poll inbound updates failed, will retry after 5 seconds",
                        self.meta().id,
                    )

self.meta().id,
e,
)
await asyncio.sleep(5)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The retry delay 5 is a magic number. Consider defining it as a constant at the class or module level (e.g., POLL_RETRY_DELAY = 5) to improve readability and maintainability. This makes it easier to find and change the value in the future.

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: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 (个人微信) 在短暂断网/代理切换后退出轮询,无法自动恢复

1 participant