fix(qqbot): fallback to Identify after 3 consecutive Resume failures - #26025
Closed
zxzxzx258 wants to merge 1 commit into
Closed
fix(qqbot): fallback to Identify after 3 consecutive Resume failures#26025zxzxzx258 wants to merge 1 commit into
zxzxzx258 wants to merge 1 commit into
Conversation
When the QQ Bot WebSocket disconnects and the old session_id expires on the server side, the adapter enters an infinite Resume loop — it never falls back to a fresh Identify handshake, so the bot stays offline indefinitely. Root cause: _send_resume clears session_id+last_seq immediately on any exception, losing the session data needed for subsequent Resume attempts. But the close-code handler (4009) also clears the session, creating a race that always loses. Fix: 1. Track _resume_fail_count — only clear session after 3 consecutive Resume failures, allowing transient network glitches to retry. 2. Separate close-code 4009 (session timeout, can Resume per QQ docs) from 4006/4007 (session truly invalid, must re-Identify). 3. Reset _resume_fail_count on successful fresh Identify (READY). Fixes #22179
Collaborator
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
When the QQ Bot WebSocket disconnects and the old session_id expires on the server side, the adapter enters an infinite Resume loop — it never falls back to a fresh Identify handshake, so the bot stays offline indefinitely until manually restarted.
Reported in #22179, and also partially covered by #19648, #19821, #15490.
Root cause
_send_resume clears session_id+last_seq immediately on any exception, losing the session data needed for subsequent Resume attempts. Combined with close-code handler treating 4009 (session timeout) the same as 4006/4007 (session invalid), the first transient Resume failure triggers a cascade that destroys the session before the server even gets a chance to properly reject it.
Fix
Three changes:
Resume fail counter — Track _resume_fail_count. Only clear session after 3 consecutive Resume failures, letting transient network glitches retry. Mirrors the Discord-style gateway pattern that QQ Bot's protocol is based on.
Close-code 4009 / 4006-4007 separation — Per QQ Official docs, close-code 4009 (session timeout) explicitly supports Resume — the session_id is still valid. Only codes 4006/4007 indicate a truly invalid session that requires fresh Identify.
Reset counter on READY — Reset _resume_fail_count on successful fresh Identify, so the bot recovers normally after a full re-connect.
Testing
Existing qqbot test suite (144 tests) passes without changes. The fix is incremental — the fail counter is internal state that only activates on an error path.
Closes #22179