Skip to content

fix(qqbot): fallback to Identify after 3 consecutive Resume failures - #26025

Closed
zxzxzx258 wants to merge 1 commit into
NousResearch:mainfrom
zxzxzx258:fix/qqbot-resume-fallback
Closed

fix(qqbot): fallback to Identify after 3 consecutive Resume failures#26025
zxzxzx258 wants to merge 1 commit into
NousResearch:mainfrom
zxzxzx258:fix/qqbot-resume-fallback

Conversation

@zxzxzx258

Copy link
Copy Markdown

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:

  1. 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.

  2. 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.

  3. 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

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
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/qqbot QQ Bot adapter labels May 15, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix with #22384 and #22422 for #22179 (QQBot Resume death-loop). Also related to #21073 (4009 close-code handling).

@zxzxzx258 zxzxzx258 closed this by deleting the head repository May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/qqbot QQ Bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(qqbot): Reconnect loop with stale session — adapter never falls back to fresh Identify

2 participants