fix(weixin): broaden stale-session detection and strip context_token on rate-limit fallback - #22661
Open
rj-chenlinfeng wants to merge 2 commits into
Open
Conversation
added 2 commits
May 9, 2026 23:37
…on rate-limit fallback
Two bugs caused iLink errcode=-2 to be misidentified as genuine rate
limiting when it was actually a stale/expired session, leading to
infinite retries that always fail.
Bug 1: _is_stale_session_ret() only recognized errmsg "unknown error"
as a session-expiry signal, but iLink also returns empty strings,
"session expired", "token expired", etc. with errcode=-2. These
were all misclassified as rate-limit errors.
Before: (errmsg or "").lower() == "unknown error"
After: also match empty errmsg, "unknown error", and any string
containing "expire" (covers locale-dependent variants)
Bug 2: The rate-limit retry branch in _send_text_chunk() never cleared
context_token, so if errcode=-2 was actually a stale session that
slipped through _is_stale_session_ret, every retry would carry the
same expired token and always get -2 again — a dead loop until the
retry budget was exhausted.
Fix: strip context_token on the first rate-limit hit (with
retried_without_token guard), same as the explicit session-expired
branch. This provides a second safety net: even if the errmsg
doesn't match any known pattern, the degraded tokenless retry can
still succeed.
Together these changes ensure that stale iLink sessions are recovered
reliably regardless of the exact errmsg wording returned by the server.
Contributor
|
Thanks for investigating the ambiguous iLink Problems
Suggested changes
Automated hermes-sweeper review. |
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
Two bugs caused iLink
errcode=-2to be misidentified as genuine rate limiting when it was actually a stale/expired session, leading to infinite retries that always fail.Bug 1:
_is_stale_session_ret()only recognized"unknown error"iLink uses
errcode=-2for both rate limiting and session expiry. The function only matchederrmsg == "unknown error", but iLink also returns empty strings,"session expired","token expired", and other locale-dependent variants — all misclassified as rate-limit errors.Fix: Match empty errmsg,
"unknown error", and any string containing"expire".Bug 2: Rate-limit retry branch never cleared
context_tokenWhen
errcode=-2slipped through_is_stale_session_ret(), every retry carried the same expired token and always got-2again — a dead loop until the retry budget was exhausted.Fix: Strip
context_tokenon the first rate-limit hit (withretried_without_tokenguard), same as the explicit session-expired branch. This provides a second safety net: even if the errmsg doesn't match any known pattern, the degraded tokenless retry can still succeed.Files Changed
gateway/platforms/weixin.py— broaden_is_stale_session_ret()+ stripcontext_tokenin rate-limit fallbackTest Plan