fix: recognize ret=-2 as stale-session signal in Weixin adapter (#17228) - #17287
Closed
vominh1919 wants to merge 1 commit into
Closed
fix: recognize ret=-2 as stale-session signal in Weixin adapter (#17228)#17287vominh1919 wants to merge 1 commit into
vominh1919 wants to merge 1 commit into
Conversation
The Weixin adapter only recognized errcode=-14 as a session-expired signal. However, iLink also returns ret=-2 with errmsg="unknown error" for the same underlying condition (stale session). The adapter treated ret=-2 as a rate-limit, exhausting retries with the same stale context_token instead of refreshing the session. Added _is_stale_session_ret() helper that distinguishes ret=-2 with "unknown error" from genuine rate limits. Updated both the poll loop and _send_text_chunk to use the helper. Fixes NousResearch#17228
Contributor
3 tasks
6 tasks
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.
Problem
The Weixin adapter's session-expired fallback only recognizes
errcode=-14as a stale-session signal. In practice, iLink also returnsret=-2witherrmsg="unknown error"for the same underlying condition — typically when a cron job tries to push a message to a chat that hasn't had user activity for many hours.The adapter treats
ret=-2as a rate-limit, exhausting retries with the same stalecontext_tokeninstead of refreshing the session. Cron deliveries silently fail on the Weixin leg.Fix
Added
_is_stale_session_ret()helper function that distinguishesret=-2witherrmsg="unknown error"from genuine rate limits. Updated both the poll loop (_run_poll_loop) and_send_text_chunkto use the helper.3 changes in
gateway/platforms/weixin.py:_is_stale_session_ret()helper (centralizes the dual-meaning logic)_send_text_chunkstale-session check (lines ~1519-1522)Before vs After
Tests
No existing tests cover this specific behavior. The fix is minimal and follows the same pattern as the existing
errcode=-14handling.Fixes #17228