fix(qqbot): accept is_reconnect kwarg in connect() to fix reconnect - #55494
Closed
Bartok9 wants to merge 1 commit into
Closed
fix(qqbot): accept is_reconnect kwarg in connect() to fix reconnect#55494Bartok9 wants to merge 1 commit into
Bartok9 wants to merge 1 commit into
Conversation
QQAdapter.connect() was declared async def connect(self), but the gateway reconnect watcher always calls adapter.connect(is_reconnect=...) via _connect_adapter_with_timeout(). After a disconnect, the reconnect raised TypeError: connect() got an unexpected keyword argument 'is_reconnect', so QQ Bot never reconnected. Match the PlatformAdapter.connect() contract (every other adapter already does); QQ keeps its own resume state and has no separate update queue, so the flag is accepted and ignored. Fixes NousResearch#54679
Collaborator
Duplicate of #52966 — identical one-line fix (adding the keyword-only |
Contributor
Author
|
Thanks @alt-glitch — you're right, this is the same one-line fix as #52966, which is the earliest still-open PR in the cluster. Closing this in favor of #52966 to keep triage clean. 🙏 |
11 tasks
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
QQAdapter.connect()now accepts the keyword-onlyis_reconnectflag, matching thePlatformAdapter.connect()contract every other adapter already implements.Root Cause
Symptom — After v0.17.0, QQ Bot fails to reconnect after a disconnection; the log shows
QQAdapter.connect() got an unexpected keyword argument 'is_reconnect'.Root cause —
gateway/run.py::_connect_adapter_with_timeout()always forwardsadapter.connect(is_reconnect=is_reconnect)(added in #46621 so adapters can distinguish a cold boot from a watcher reconnect). Every platform adapter declaresasync def connect(self, *, is_reconnect: bool = False)— exceptgateway/platforms/qqbot/adapter.py, which still had the old signatureasync def connect(self). On the reconnect path (run.pyline ~6855,is_reconnect=True) the keyword binding raisesTypeError, so the reconnect attempt dies and QQ never comes back.Evidence —
grep "async def connect" gateway/platforms/*.py gateway/platforms/*/adapter.pyshows qqbot is the lone outlier;run.py:3132/3135always pass the kwarg. New testtest_connect_callable_with_is_reconnect_kwargreproduces the exactTypeErroron the old signature.Fix + why this level — Fix at the adapter signature (the source of the contract violation), not by wrapping the call site in
try/except TypeError(the issue’s alternative). The base class already documents the flag; bringing qqbot into line is the correct, narrowest fix and avoids masking realTypeErrors at the call site. QQ keeps its own server-side resume state (_session_id/_last_seq) and has no separate update queue to preserve, so the flag is accepted and ignored per the base-class note that adapters without such a queue may ignore it.Scope / risk — One-line signature change + docstring; behavior is unchanged for the existing cold-boot path (
is_reconnectdefaults toFalse). No other call sites touched.Tests
Added
TestQQConnectIsReconnectKwarg(2 cases) intests/gateway/test_qqbot.py:test_connect_signature_accepts_is_reconnect— asserts the keyword-only param withFalsedefault.test_connect_callable_with_is_reconnect_kwarg— callsconnect(is_reconnect=True)(forced early return viaAIOHTTP_AVAILABLE=False), asserts noTypeError.Real captured output:
Without the fix:
With the fix (full qqbot suite):
(the 4 warnings are pre-existing coroutine-cleanup warnings unrelated to this change)
Fixes #54679