hermes - 💡(How to fix) Fix QQ Bot adapter: _read_events() silent loop after reconnect failure prevents further retries [1 pull requests]

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…

Error Message

  1. _read_events() returns silently without exception After a failed reconnect attempt, _read_events() should recognize the closed WebSocket and raise an exception, allowing _listen_loop() to continue retrying with proper backoff.

Root Cause

In gateway/platforms/qqbot/adapter.py, the _read_events() method (line 656) guards against a None WebSocket but not against a closed one:

async def _read_events(self) -> None:
    if not self._ws:
        raise RuntimeError("WebSocket not connected")

When _reconnect() fails (e.g., _get_gateway_url() times out at api.sgroup.qq.com/gateway), _open_ws() is never called, so self._ws still points to the old, closed ClientWebSocketResponse object. Since the old closed WS is not None but truthy:

  1. if not self._ws: – False (old closed WS is truthy), skips the raise
  2. while self._ws and not self._ws.closed: – False (self._ws.closed is True), loop body never entered
  3. _read_events() returns silently without exception
  4. backoff_idx is reset to 0 in _listen_loop()
  5. The cycle repeats forever, making no progress and logging nothing

Fix Action

Fixed

Code Example

async def _read_events(self) -> None:
    if not self._ws:
        raise RuntimeError("WebSocket not connected")
RAW_BUFFERClick to expand / collapse

Bug Description

When QQ Bot WebSocket reconnection fails (e.g., _get_gateway_url() raises, so _open_ws() is never called), the adapter enters an infinite silent loop that never retries reconnection. After entering this state, the QQ Bot remains permanently disconnected until the gateway process is restarted.

Root Cause

In gateway/platforms/qqbot/adapter.py, the _read_events() method (line 656) guards against a None WebSocket but not against a closed one:

async def _read_events(self) -> None:
    if not self._ws:
        raise RuntimeError("WebSocket not connected")

When _reconnect() fails (e.g., _get_gateway_url() times out at api.sgroup.qq.com/gateway), _open_ws() is never called, so self._ws still points to the old, closed ClientWebSocketResponse object. Since the old closed WS is not None but truthy:

  1. if not self._ws: – False (old closed WS is truthy), skips the raise
  2. while self._ws and not self._ws.closed: – False (self._ws.closed is True), loop body never entered
  3. _read_events() returns silently without exception
  4. backoff_idx is reset to 0 in _listen_loop()
  5. The cycle repeats forever, making no progress and logging nothing

Impact

After the first reconnect failure, the adapter silently stops trying. QQ Bot stays disconnected for hours until the gateway is manually restarted.

Expected Behavior

After a failed reconnect attempt, _read_events() should recognize the closed WebSocket and raise an exception, allowing _listen_loop() to continue retrying with proper backoff.

Proposed Fix

Change the guard in _read_events() from:

if not self._ws:

to:

if not self._ws or self._ws.closed:

Alternatively, set self._ws = None in _reconnect() on failure.

Environment

  • Hermes Agent version: current
  • OS: Linux (WSL)
  • Gateway: systemd service

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING