Skip to content

fix(qqbot): retry gateway URL fetch with cache fallback#17256

Open
dwc1997 wants to merge 1 commit into
NousResearch:mainfrom
dwc1997:fix/qqbot-gateway-retry-11493
Open

fix(qqbot): retry gateway URL fetch with cache fallback#17256
dwc1997 wants to merge 1 commit into
NousResearch:mainfrom
dwc1997:fix/qqbot-gateway-retry-11493

Conversation

@dwc1997

@dwc1997 dwc1997 commented Apr 29, 2026

Copy link
Copy Markdown

Add bounded retries when resolving the QQ WebSocket gateway URL, cache the last successful URL, and fall back to it on transient failures. Align gateway URL tests with the qqbot.adapter module path for asyncio.sleep patching.

What does this PR do?

QQ’s WebSocket reconnect path resolves the gateway URL via the REST /gateway endpoint. When that call fails transiently, reconnect could fail even though a recently valid gateway URL was already known.

This PR hardens _get_gateway_url() by:

  • Retrying gateway URL resolution a few times with short, bounded backoff (GATEWAY_URL_RETRY_DELAYS).
  • Caching the last successfully resolved gateway URL on the adapter.
  • Falling back to the cached URL if all retries still fail.

Tests cover retry-then-success and cache-fallback behavior. asyncio.sleep is patched at gateway.platforms.qqbot.adapter.asyncio.sleep to match the refactored module layout.

Related Issue

Fixes #11493

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • gateway/platforms/qqbot/constants.py — add GATEWAY_URL_RETRY_DELAYS.
  • gateway/platforms/qqbot/adapter.py — retry + cache + fallback in _get_gateway_url() while preserving existing headers (including User-Agent).
  • tests/gateway/test_qqbot.py — add TestGatewayUrlFetch regression tests; fix asyncio.sleep patch target for the qqbot adapter package path.

How to Test

  1. Run:

    python -m pytest -o addopts="-m 'not integration'" tests/gateway/test_qqbot.py -q -k "TestGatewayUrlFetch"

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

@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 Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Appears to be a resubmission of closed #17240 (same retry + cache fallback approach for QQ gateway URL). Maintainer should verify this supersedes it cleanly.

@dwc1997

dwc1997 commented Apr 29, 2026

Copy link
Copy Markdown
Author

Appears to be a resubmission of closed #17240 (same retry + cache fallback approach for QQ gateway URL). Maintainer should verify this supersedes it cleanly.

Thanks for calling this out.

#17256 is a clean resubmission of the previously closed #17240.
I closed #17240 because the PR description/template fields were incomplete and not clear enough for review context, not because the technical fix was invalid.

This PR keeps the same core fix (bounded retry + cached gateway URL fallback), is rebased on current main, and includes only the QQ-related changes with updated test alignment.

Add bounded retries when resolving the QQ WebSocket gateway URL, cache the last successful URL, and fall back to it on transient failures. Align gateway URL tests with the qqbot.adapter module path for asyncio.sleep patching.
@dwc1997 dwc1997 force-pushed the fix/qqbot-gateway-retry-11493 branch from a33505c to 9f8c1e6 Compare May 1, 2026 03:37
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 WebSocket session timeout and failure to fetch gateway URL

2 participants