hermes - ✅(Solved) Fix QQBot stops reconnecting after failed reconnect leaves websocket closed [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#17703Fetched 2026-04-30 06:45:56
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
labeled ×4cross-referenced ×1subscribed ×1

The QQBot adapter can stop reconnecting after a failed reconnect attempt if the previous websocket object remains present but closed.

Error Message

WebSocket error: WebSocket closed Reconnecting in 2s (attempt 1)... Reconnect failed: Failed to get QQ Bot gateway URL: [Errno 8] nodename nor servname provided, or not known

Root Cause

QQAdapter._read_events() only raises when self._ws is missing. If self._ws is still assigned but already closed, the read loop condition is false and the method returns normally:

if not self._ws:
    raise RuntimeError("WebSocket not connected")

while self._running and self._ws and not self._ws.closed:
    ...

That normal return makes _listen_loop() treat the read as a clean exit, reset reconnect bookkeeping, and skip the exception path that would call _reconnect() again.

Fix Action

Fix

Raise RuntimeError("WebSocket closed") when _read_events() is entered with an already-closed websocket object. Add a regression test to make sure closed-but-present websocket objects cannot be treated as a clean read termination.

PR fix notes

PR #17704: fix(qqbot): keep reconnecting after closed websocket

Description (problem / solution / changelog)

Summary

  • Treat an already-closed QQBot websocket as an error in _read_events()
  • Keep the listener on the existing reconnect path after a failed reconnect leaves self._ws closed
  • Add a regression test for closed-but-present websocket objects

Fixes #17703

Test Plan

  • python -m pytest tests/gateway/test_qqbot.py -q

Changed files

  • gateway/platforms/qqbot/adapter.py (modified, +2/-0)
  • tests/gateway/test_qqbot.py (modified, +20/-1)

Code Example

WebSocket error: WebSocket closed
Reconnecting in 2s (attempt 1)...
Reconnect failed: Failed to get QQ Bot gateway URL: [Errno 8] nodename nor servname provided, or not known

---

if not self._ws:
    raise RuntimeError("WebSocket not connected")

while self._running and self._ws and not self._ws.closed:
    ...
RAW_BUFFERClick to expand / collapse

Summary

The QQBot adapter can stop reconnecting after a failed reconnect attempt if the previous websocket object remains present but closed.

What happens

After a QQBot websocket disconnect, the reconnect path may fail transiently while fetching a fresh gateway URL, for example during a DNS or network outage:

WebSocket error: WebSocket closed
Reconnecting in 2s (attempt 1)...
Reconnect failed: Failed to get QQ Bot gateway URL: [Errno 8] nodename nor servname provided, or not known

After that, the adapter may remain disconnected indefinitely. Subsequent sends only report that the platform is not connected, but no further reconnect attempts are made.

Root cause

QQAdapter._read_events() only raises when self._ws is missing. If self._ws is still assigned but already closed, the read loop condition is false and the method returns normally:

if not self._ws:
    raise RuntimeError("WebSocket not connected")

while self._running and self._ws and not self._ws.closed:
    ...

That normal return makes _listen_loop() treat the read as a clean exit, reset reconnect bookkeeping, and skip the exception path that would call _reconnect() again.

Expected behavior

A closed websocket should be treated as a disconnected state. _read_events() should raise so _listen_loop() continues through the existing reconnect path.

Reproduction

A minimal reproduction is to set adapter._ws to a websocket-like object where closed == True and call _read_events() while the adapter is running. The method currently returns without raising, which prevents the listener from continuing reconnect handling.

Fix

Raise RuntimeError("WebSocket closed") when _read_events() is entered with an already-closed websocket object. Add a regression test to make sure closed-but-present websocket objects cannot be treated as a clean read termination.

extent analysis

TL;DR

Raise a RuntimeError in _read_events() when the websocket object is closed to trigger the reconnect mechanism.

Guidance

  • Modify the _read_events() method to check if self._ws is closed and raise a RuntimeError if it is.
  • Ensure the reconnect path is triggered when a closed websocket object is detected.
  • Add a regression test to verify that a closed-but-present websocket object is handled correctly and does not prevent reconnect attempts.
  • Review the _listen_loop() method to confirm it correctly handles the RuntimeError exception raised by _read_events() and initiates the reconnect process.

Example

if not self._ws or self._ws.closed:
    raise RuntimeError("WebSocket not connected or closed")

Notes

This fix assumes that the _listen_loop() method is correctly implemented to handle the RuntimeError exception and initiate the reconnect process. Additional testing may be necessary to ensure the reconnect mechanism works as expected in all scenarios.

Recommendation

Apply the workaround by modifying the _read_events() method to raise a RuntimeError when the websocket object is closed, as this will allow the reconnect mechanism to be triggered and prevent the adapter from remaining disconnected indefinitely.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

A closed websocket should be treated as a disconnected state. _read_events() should raise so _listen_loop() continues through the existing reconnect path.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix QQBot stops reconnecting after failed reconnect leaves websocket closed [1 pull requests, 1 participants]