fix(gateway): treat weixin ret=-2 with empty errmsg as stale context_token - #20797
Closed
XIYBHK wants to merge 1 commit into
Closed
fix(gateway): treat weixin ret=-2 with empty errmsg as stale context_token#20797XIYBHK wants to merge 1 commit into
XIYBHK wants to merge 1 commit into
Conversation
…token iLink sometimes returns ret=-2 with errmsg=None instead of 'unknown error'. _is_stale_session_ret only matched the 'unknown error' string, so the empty- errmsg variant fell through to the rate-limit branch and burned all retries against a dead token. Extend the check: if errmsg is empty/None, return True (stale session). Genuine rate limits always carry a populated errmsg (e.g. 'frequency limit', 'too frequently'), so the distinction remains reliable. Fixes NousResearch#18100. Follow-up to NousResearch#17228.
Collaborator
Author
|
Confirmed — #18105 (opened 2026-04-30) predates this one and implements the same fix with equivalent behavior (also strips/lowercases and treats I'll move the real-world |
12 tasks
Author
|
Closing as duplicate of #18105 per above. |
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.
What does this PR do?
_is_stale_session_retingateway/platforms/weixin.pyonly recognizedret=-2as a stalecontext_tokenwhenerrmsg == "unknown error". In the wild, iLink also returnsret=-2witherrmsg=None(empty) for the same stale-session condition. The previous check missed this variant, causing the adapter to fall through to the rate-limit branch and burn all retries against a dead token.This PR extends the check: if
errmsgis empty/None, we returnTrue(stale session). Genuine iLink rate limits always carry a populatederrmsgsuch as"frequency limit"or"too frequently", so the distinction remains reliable.Related Issue
Fixes #18100. Follow-up to #17228.
Type of Change
Changes Made
gateway/platforms/weixin.py: extend_is_stale_session_retto returnTruewhenerrmsgis empty/None(in addition to the existing"unknown error"match)tests/gateway/test_weixin.py: updateTestIsStaleSessionRet— replace the oldtest_ret_minus_2_with_no_errmsg_is_not_stale(which asserted the now-fixed wrong behavior) with two new regression tests coveringNoneand""errmsg via bothretanderrcodepathsHow to Test
pytest tests/gateway/test_weixin.py::TestIsStaleSessionRet -v_empty_errmsg_is_staletests.gateway.log— previously you'd seerate limited ... ret=-2 errcode=None errmsg=Nonerepeated until failure; with this fix the adapter correctly detects the stale token and attempts a tokenless retry.Checklist
Code
fix(gateway):)weixin.py+ its test)TestIsStaleSessionRetintest_weixin.py)Documentation & Housekeeping
cli-config.yaml.example— N/ACONTRIBUTING.mdorAGENTS.md— N/AScreenshots / Logs
Real-world
gateway.logshowing the bug (before fix):After a user-initiated inbound message refreshed the session, the next send went through immediately — confirming this is a stale-session signal, not a genuine frequency cap.