Skip to content

fix(gateway): refresh QQBot sessions before timeout - #39583

Closed
weathour wants to merge 3 commits into
NousResearch:mainfrom
weathour:fix/qqbot-session-refresh
Closed

fix(gateway): refresh QQBot sessions before timeout#39583
weathour wants to merge 3 commits into
NousResearch:mainfrom
weathour:fix/qqbot-session-refresh

Conversation

@weathour

@weathour weathour commented Jun 5, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes QQBot gateway session refresh so long-running sessions proactively reconnect/resume before the QQ gateway closes them with 4009 Session timed out.

The adapter now:

  • starts a proactive session-refresh timer after READY;
  • restarts the timer after RESUMED;
  • scopes each timer to the websocket active when the timer was created, so stale timers cannot close newer websockets;
  • avoids scheduling refresh timers when no websocket is active;
  • treats closed/closing websocket states as QQCloseError so the existing reconnect/resume path runs instead of silently returning.

Related Issue

No issue number.

Related PRs checked to avoid duplication:

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Changes Made

  • gateway/platforms/qqbot/adapter.py
    • Add SESSION_REFRESH_SECONDS and _session_refresh_task lifecycle.
    • Start/restart refresh timer on READY / RESUMED.
    • Cancel refresh timer on disconnect.
    • Ensure refresh timers are bound to the captured websocket and do not act on stale or missing sockets.
    • Convert closed/CLOSING/CLOSED/ERROR websocket states to QQCloseError for reconnect handling.
  • tests/gateway/test_qqbot.py
    • Cover READY/RESUMED refresh lifecycle.
    • Cover disconnect cancellation.
    • Cover stale websocket and None websocket no-op behavior.
    • Cover closed/CLOSING frame handling.
    • Cover no-loop synchronous dispatch without coroutine warnings.

How to Test

  1. scripts/run_tests.sh tests/gateway/test_qqbot.py
  2. venv/bin/python scripts/check-windows-footguns.py --diff origin/main
  3. git diff --check origin/main..HEAD

All passed locally after rebasing onto latest origin/main.

Checklist

Code

  • I've read the Contributing Guide.
  • My commit messages follow Conventional Commits.
  • I searched existing PRs to make sure this isn't a duplicate.
  • My PR contains only changes related to this fix.
  • I've run the relevant test suite and all tests pass.
  • I've added tests for my changes.
  • I've tested on my platform: Linux.

Documentation & Housekeeping

  • I've updated relevant documentation — N/A, behavior is covered by tests and inline comments.
  • I've updated cli-config.yaml.example — N/A, no config keys added.
  • I've updated CONTRIBUTING.md or AGENTS.md — N/A, no workflow/architecture docs changed.
  • I've considered cross-platform impact; Windows footgun check passed.
  • I've updated tool descriptions/schemas — N/A, no tool schema changed.

Screenshots / Logs

Validation:

scripts/run_tests.sh tests/gateway/test_qqbot.py
=> 169 tests passed

venv/bin/python scripts/check-windows-footguns.py --diff origin/main
=> No Windows footguns found (2 file(s) scanned)

git diff --check origin/main..HEAD
=> passed

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/qqbot QQ Bot adapter comp/gateway Gateway runner, session dispatch, delivery labels Jun 5, 2026
@weathour weathour closed this by deleting the head repository Jun 17, 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.

2 participants