Conversation
The iLink adapter used a fixed 3-second backoff on rate-limit errors (ret=-2 / errcode=-2), which was shorter than typical WeChat rate-limit windows. Messages that should have succeeded after a longer wait were instead dropped after exhausting all retries. Changes: - Rate-limit retries now use exponential backoff (base × 2^attempt) with ±25% jitter to avoid thundering-herd - New _parse_retry_after() helper extracts server-supplied retry hints (retry_after / retry_after_seconds / retry_after_ms / backoff fields) - Chat-level cooldown: when rate-limiting is detected on a chat, inter-chunk delay increases from 1.5s to 5s to prevent cascading failures across multi-chunk messages - Configurable via WEIXIN_RATE_LIMIT_BACKOFF_BASE and WEIXIN_RATE_LIMIT_CHUNK_COOLDOWN env vars / config.yaml keys Before: 3s → 3s → 3s → 3s (12s window, typically too short) After: 1s → 2s → 4s → 8s → 16s (31s window with server hints)
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for investigating Weixin delivery loss. The retry concern remains relevant, but this patch needs reconciliation with current main before it can be safely salvaged.
Problems
- Current main's circuit breaker opens on the first rate-limit response by default:
_rate_limit_circuit_thresholddefaults to1atgateway/platforms/weixin.py:1179-1185, and_record_rate_limit_event()runs before the retry wait atgateway/platforms/weixin.py:1802-1807. The proposed exponential wait would therefore not run under the default current behavior. - The diff removes the native-attachment path filters. Current Weixin
send()retains them atgateway/platforms/weixin.py:1853-1856; the helpers validate paths atgateway/platforms/base.py:3497-3520as part of the safety fix in41d2c758c. - The new
WEIXIN_RATE_LIMIT_*behavioral environment variables conflict with the repository config policy, and the new retry/cooldown behavior has no tests.
Suggested changes
- Reconcile exponential retry with the current circuit-breaker policy and add deterministic tests around that transition.
- Keep both media-path filters and expose any needed tuning through
gateway.platforms.weixin.extraonly.
Automated hermes-sweeper review.
| @@ -1210,6 +1234,14 @@ def __init__(self, config: PlatformConfig): | |||
| extra.get("send_chunk_retry_delay_seconds") | |||
Collaborator
There was a problem hiding this comment.
Please do not add these new user-facing behavioral environment variables. Keep any necessary tuning under gateway.platforms.weixin.extra and validate it there; the repository policy reserves .env variables for secrets.
| # Extract MEDIA: tags and bare local file paths before text delivery. | ||
| media_files, cleaned_content = self.extract_media(content) | ||
| media_files = self.filter_media_delivery_paths(media_files) | ||
| _, image_cleaned = self.extract_images(cleaned_content) |
Collaborator
There was a problem hiding this comment.
Retain both attachment-path filters removed by this hunk. Current main uses them to validate native-upload paths (gateway/platforms/base.py:3497-3520); removing them would undo the protection from 41d2c758c.
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an issue where the WeChat iLink adapter's rate-limit retry strategy
used a fixed 3-second backoff per attempt, causing messages to be silently
dropped when the rate-limit window exceeded ~12 seconds (total retry time).
Closes #31131
Changes
gateway/platforms/weixin.py_parse_retry_after()(new)retry_after/retry_after_seconds/retry_after_ms/backoffhints from iLink rate-limit responsesbase x 2^attemptwith +-25% jitter_rate_limited_atdict tracks per-chat rate-limit timestamps;send()increases inter-chunk delay after rate-limiting is detectedWEIXIN_RATE_LIMIT_BACKOFF_BASE/rate_limit_backoff_base_seconds,WEIXIN_RATE_LIMIT_CHUNK_COOLDOWN/rate_limit_chunk_cooldown_secondsComparison
Screenshots