Skip to content

fix(qqbot): stop 100% CPU spin when WebSocket is closed but not None (#31193, #31771)#40574

Merged
teknium1 merged 1 commit into
mainfrom
salvage/40497-qqbot-spin
Jun 7, 2026
Merged

fix(qqbot): stop 100% CPU spin when WebSocket is closed but not None (#31193, #31771)#40574
teknium1 merged 1 commit into
mainfrom
salvage/40497-qqbot-spin

Conversation

@teknium1

@teknium1 teknium1 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a 100% CPU busy-loop in the QQ bot adapter when the WebSocket is closed but the object isn't None. Closes #31193 and #31771.

_read_events() returned normally in that state (its while condition is false on entry); _listen_loop treats a normal return as a clean read, resets backoff to 0, and immediately retries — pinning a core. Raising on entry routes it through the proper reconnect/backoff path.

Changes

  • gateway/platforms/qqbot/adapter.py: raise RuntimeError when self._ws.closed on entry to _read_events.
  • tests/gateway/test_qqbot.py: regression tests for closed-ws and None-ws entry.

Validation

TestReadEventsClosedWsGuard 2 passed.

Salvaged from #40497 (@xushibo) and the byte-identical #40291 (@cnfi); both credited.

…31193, #31771)

_read_events() returned normally when self._ws was closed-but-non-None
(the while-condition is false on entry). _listen_loop treats a normal
return as a clean read, resets backoff to 0, and immediately retries —
a tight busy-loop pinning CPU. Raising on entry routes it through the
reconnect/backoff path instead.

Co-authored-by: xushibo <xushibo@users.noreply.github.com>
Co-authored-by: cnfi <cnfi@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/40497-qqbot-spin vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9962 on HEAD, 9962 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5167 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@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 Jun 6, 2026
@mohamedorigami-jpg

Copy link
Copy Markdown
Contributor

Clean and minimal fix for the busy-loop. The guard correctly raises RuntimeError instead of letting the while condition short-circuit to False on a closed-but-non-None ws. However, the test for ws is None also raises RuntimeError via the same path -- but the existing pre-check if not self._ws: raise RuntimeError("WebSocket not connected") on line ~683 already handles that case. The new self._ws.closed check runs after that pre-check, so for a None ws, we never reach the new code (the not self._ws guard raises first). The test_read_events_raises_when_ws_none test expects the same RuntimeError but is actually testing the pre-existing guard, not the new one. Consider adjusting the ws=None test to verify via the specific error message ("WebSocket not connected" vs "WebSocket closed") so the regression coverage is unambiguous, or remove it if the pre-existing guard is already tested elsewhere.

@teknium1 teknium1 merged commit 3eeca46 into main Jun 7, 2026
23 checks passed
@teknium1 teknium1 deleted the salvage/40497-qqbot-spin branch June 7, 2026 01:44
changman pushed a commit to changman/hermes-agent that referenced this pull request Jun 10, 2026
…ousResearch#31193, NousResearch#31771) (NousResearch#40574)

_read_events() returned normally when self._ws was closed-but-non-None
(the while-condition is false on entry). _listen_loop treats a normal
return as a clean read, resets backoff to 0, and immediately retries —
a tight busy-loop pinning CPU. Raising on entry routes it through the
reconnect/backoff path instead.

Co-authored-by: xushibo <xushibo@users.noreply.github.com>
Co-authored-by: cnfi <cnfi@users.noreply.github.com>
alt-glitch pushed a commit that referenced this pull request Jun 14, 2026
…31193, #31771) (#40574)

_read_events() returned normally when self._ws was closed-but-non-None
(the while-condition is false on entry). _listen_loop treats a normal
return as a clean read, resets backoff to 0, and immediately retries —
a tight busy-loop pinning CPU. Raising on entry routes it through the
reconnect/backoff path instead.

Co-authored-by: xushibo <xushibo@users.noreply.github.com>
Co-authored-by: cnfi <cnfi@users.noreply.github.com>
davidgut1982 pushed a commit to davidgut1982/hermes-agent that referenced this pull request Jun 17, 2026
…ousResearch#31193, NousResearch#31771) (NousResearch#40574)

_read_events() returned normally when self._ws was closed-but-non-None
(the while-condition is false on entry). _listen_loop treats a normal
return as a clean read, resets backoff to 0, and immediately retries —
a tight busy-loop pinning CPU. Raising on entry routes it through the
reconnect/backoff path instead.

Co-authored-by: xushibo <xushibo@users.noreply.github.com>
Co-authored-by: cnfi <cnfi@users.noreply.github.com>
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
…ousResearch#31193, NousResearch#31771) (NousResearch#40574)

_read_events() returned normally when self._ws was closed-but-non-None
(the while-condition is false on entry). _listen_loop treats a normal
return as a clean read, resets backoff to 0, and immediately retries —
a tight busy-loop pinning CPU. Raising on entry routes it through the
reconnect/backoff path instead.

Co-authored-by: xushibo <xushibo@users.noreply.github.com>
Co-authored-by: cnfi <cnfi@users.noreply.github.com>
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.

QQ Bot Reconnect Busy Loop Causes 100% CPU Spin

3 participants