Skip to content

fix(weixin): add rate-limit circuit breaker - #26904

Closed
haran2001 wants to merge 1 commit into
NousResearch:mainfrom
haran2001:fix/weixin-rate-limit-circuit
Closed

haran2001 wants to merge 1 commit into
NousResearch:mainfrom
haran2001:fix/weixin-rate-limit-circuit

Conversation

@haran2001

Copy link
Copy Markdown
Contributor

Summary

  • Add a localized Weixin/iLink sendmessage rate-limit circuit breaker so repeated -2 frequency-limit responses stop follow-up sends during a cooldown instead of spinning retry loops.
  • Serialize outbound text sends through an adapter-wide gate so concurrent bursts observe the opened circuit and fail fast after the first rate-limit response.
  • Keep Weixin one-shot media routing independent of unrelated optional adapter imports.

Duplicate PR check

Test Plan

  • python -m pytest tests/gateway/test_weixin.py::TestWeixinChunkDelivery::test_repeated_rate_limits_open_circuit_for_followup_sends tests/gateway/test_weixin.py::TestWeixinChunkDelivery::test_open_rate_limit_circuit_fails_fast_without_sendmessage tests/gateway/test_weixin.py::TestWeixinChunkDelivery::test_successful_send_after_cooldown_resets_rate_limit_state tests/gateway/test_weixin.py::TestWeixinChunkDelivery::test_concurrent_rate_limited_sends_are_serialized_by_gate tests/gateway/test_weixin.py::TestWeixinSendMessageIntegration::test_send_to_platform_routes_weixin_media_to_native_helper -q -o 'addopts='
  • python -m pytest tests/gateway/test_weixin.py -q -o 'addopts='
  • python -m pytest tests/tools/test_send_message_tool.py tests/tools/test_send_message_missing_platforms.py -q -o 'addopts='
  • git diff --check && python -m py_compile gateway/platforms/weixin.py tools/send_message_tool.py

Note: python -m pytest tests/gateway/ -q -o 'addopts=' was attempted locally but the broad gateway suite exhausted the macOS file descriptor limit and timed out with OSError: [Errno 24] Too many open files; the targeted Weixin/send-message coverage above passed.

Closes #26828

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/wecom WeCom / WeChat Work adapter labels May 16, 2026
@cardtest15-coder

This comment was marked as spam.

@haran2001

Copy link
Copy Markdown
Contributor Author

Local verification update after the automated reviewer comment:

The cardtest15-coder message appears to be a bot/shell invocation failure (/bin/sh: 1: Syntax error: "(" unexpected) rather than a code/test failure in this PR.

I re-ran the PR test plan locally on the PR branch:

python3 -m pytest tests/gateway/test_weixin.py::TestWeixinChunkDelivery::test_repeated_rate_limits_open_circuit_for_followup_sends tests/gateway/test_weixin.py::TestWeixinChunkDelivery::test_open_rate_limit_circuit_fails_fast_without_sendmessage tests/gateway/test_weixin.py::TestWeixinChunkDelivery::test_successful_send_after_cooldown_resets_rate_limit_state tests/gateway/test_weixin.py::TestWeixinChunkDelivery::test_concurrent_rate_limited_sends_are_serialized_by_gate tests/gateway/test_weixin.py::TestWeixinSendMessageIntegration::test_send_to_platform_routes_weixin_media_to_native_helper -q -o 'addopts='
python3 -m pytest tests/gateway/test_weixin.py -q -o 'addopts='
python3 -m pytest tests/tools/test_send_message_tool.py tests/tools/test_send_message_missing_platforms.py -q -o 'addopts='
git diff --check
python3 -m py_compile gateway/platforms/weixin.py tools/send_message_tool.py

Results:

5 passed
58 passed
130 passed, 3 warnings

git diff --check and py_compile also completed successfully.

@teknium1

teknium1 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Merged via PR #41718 (commit b8469a8 on main). Your circuit-breaker commit was cherry-picked onto current main with your authorship preserved via rebase-merge. The only adjustment was resolving a conflict in send_message_tool.py where the file had drifted to a registry-based structure — your intended single early-return for WEIXIN was preserved. Thanks @haran2001!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/wecom WeCom / WeChat Work adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WeChat (iLink) rate-limit retry storm causes gateway OOM and SIGKILL — no circuit breaker

4 participants