fix(weixin): treat 'rate limited' errmsg as stale-session signal in _is_stale_session_ret - #35714
fix(weixin): treat 'rate limited' errmsg as stale-session signal in _is_stale_session_ret#35714liuhao1024 wants to merge 2 commits into
Conversation
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Overview
Well-documented fix for Weixin iLink stale-session detection. Discovers that errmsg="rate limited" with ret=-2 is a stale-session signal (not a genuine rate limit), and extends _is_stale_session_ret() to recognize it alongside "unknown error".
Looks Good
- Clear distinction from genuine rate limits (
"freq limit"excluded) - Comprehensive tests: 5 new regression tests covering all variants
- Case-insensitive matching with
.strip()for whitespace robustness - Low blast radius (single helper, 2 call sites)
- Detailed PR body with related issue references
Reviewed by Hermes Agent
|
This PR fixes the The three known stale-session variants (
A more complete fix that wraps all three: msg = (errmsg or "").strip().lower()
if not msg:
return True
return msg in ("unknown error", "rate limited")Alternatively, defining a named constant makes future extensions cleaner: STALE_SESSION_ERRMSGS = frozenset({"unknown error", "rate limited"}) |
…is_stale_session_ret iLink returns ret=-2 with errmsg='rate limited' when the context_token is stale — identical recovery pattern to 'unknown error' (NousResearch#17228). Previously this fell through to the genuine rate-limit backoff path, burning all retries against the dead token. Widen the check to include 'rate limited' alongside 'unknown error'. Genuine rate limits use 'freq limit' (iLink's wording) and are not affected. Fixes NousResearch#35713
iLink returns ret=-2 with no errmsg field (None or empty string) when the context_token is stale. Previously only 'unknown error' and 'rate limited' variants were recognized, causing the empty-errmsg case to enter the rate-limit backoff path instead of clearing the token and retrying. Ref: NousResearch#18100, NousResearch#35713 Suggested-by: zujh
a8280df to
20e6dc1
Compare
|
@zujh Great catch! I've pushed an update that handles the third variant — Changes:
All 73 weixin tests pass. Thanks for the detailed analysis! |
|
Thanks for extending the existing stale-session discriminator. The premise remains current: The proposed normalization and recognized variants fit the shared helper, so they cover both No blocking issues found in static review. Automated hermes-sweeper review. |
|
+1.Hope it could be merged. When I wants to run a long-term mission background over wechat, It ALWAYS stucked halfway after 10 messages. It has confused me for a long time. |
What does this PR do?
Fixes a bug where the Weixin iLink adapter's
_is_stale_session_ret()helper fails to recogniseerrmsg="rate limited"as a stale-session signal. When thecontext_tokenis stale, iLink returnsret=-2witherrmsg="rate limited"— identical to the"unknown error"variant (#17228) — but the existing check only matched"unknown error", causing all retries to burn against the dead token.Related Issue
Fixes #35713
Type of Change
Changes Made
gateway/platforms/weixin.py: Widened_is_stale_session_ret()to treat"rate limited"as a stale-session signal alongside"unknown error". Updated docstring to document all recognised variants. Added.strip()to handle whitespace-padded errmsg values.tests/gateway/test_weixin.py: Added 5 regression tests for the"rate limited"variant (ret=-2, errcode=-2, case-insensitive, whitespace handling). Updated class docstring to reference weixin: ret=-2 errmsg="rate limited" also indicates stale context_token (follow-up to #18100) #35713.How to Test
pytest tests/gateway/test_weixin.py -q -k TestIsStaleSessionRet— all 11 tests should pass (6 existing + 5 new)pytest tests/gateway/test_weixin.py -q— full file should pass (62 tests)weixin._is_stale_session_ret(-2, None, "rate limited")returnsTrueweixin._is_stale_session_ret(-2, None, "freq limit")still returnsFalse(genuine rate limit)Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
_is_stale_session_ret()ingateway/platforms/weixin.py(callers: 2 — getUpdates poll loop L1290, send path L1567)