Skip to content

fix(qqbot): pass timeoutMs to token fetch in doFetchToken - #102950

Closed
hugenshen wants to merge 1 commit into
openclaw:mainfrom
hugenshen:fix/qqbot-token-fetch-timeout
Closed

hugenshen wants to merge 1 commit into
openclaw:mainfrom
hugenshen:fix/qqbot-token-fetch-timeout

Conversation

@hugenshen

Copy link
Copy Markdown
Contributor

What Problem This Solves

TokenManager.doFetchToken in extensions/qqbot/src/engine/api/token.ts calls
fetchWithSsrFGuard to POST credentials to https://bots.qq.com/app/getAppAccessToken
without a timeoutMs or top-level signal. If bots.qq.com accepts the TCP connection
but never sends an HTTP response (stalled server, network middlebox, or proxy delay), the
token fetch hangs indefinitely.

This is especially impactful because the token endpoint is on the critical path for every
authenticated QQBot API call. Every message send, API call, and upload eventually calls
getAccessToken, which goes through doFetchToken when the cache is empty or expired.
A stalled token fetch blocks all QQBot operations with no timeout error surfaced.

The sibling ApiClient.request method and executeChannelApi both implement 30-second
timeouts via AbortController + signal. The stt.ts transcription helper passes
timeoutMs directly. doFetchToken was the only call site with no timeout of any kind.

Why This Change Was Made

fetchWithSsrFGuard accepts a top-level timeoutMs parameter (defined in
src/infra/net/fetch-guard.ts:80). Adding timeoutMs: QQBOT_TOKEN_TIMEOUT_MS to the
single fetchWithSsrFGuard call site in doFetchToken closes the gap. The 30-second
constant matches the DEFAULT_TIMEOUT_MS used in ApiClient and channel-api.ts,
keeping the timeout policy consistent across all QQBot HTTP call sites.

User Impact

Before: If bots.qq.com accepts but never answers, every QQBot operation requiring
auth hangs indefinitely — no timeout error, no lane release. Under concurrent usage,
multiple stalled token fetches accumulate and singleflight collapses them into one pending
promise, but that promise also never resolves.

After: doFetchToken fails with an abort/timeout error after 30 seconds. The caller
receives a concrete network error, the lane is released, and the singleflight map is
cleared. Subsequent calls can retry.

Evidence

Branch: fix/qqbot-token-fetch-timeout
Base: upstream/main (9775f09194)
Node: v22.22.0 — macOS Darwin 24.3.0 arm64

Regression tests

$ node scripts/run-vitest.mjs extensions/qqbot/src/engine/api/token.test.ts

 RUN  v4.1.9 /Users/shen/Documents/GitHub/openclaw

 Test Files  1 passed (1)
      Tests  7 passed (7)
   Start at  23:11:37
   Duration  799ms (transform 408ms, setup 127ms, import 539ms, tests 63ms, environment 0ms)

7 tests pass: the 6 pre-existing cases (including the RFC 2544 SSRF regression for #88984)
plus the new "passes timeoutMs to fetchWithSsrFGuard on every token fetch" case.

The existing "wraps malformed access token JSON" test uses an exact toHaveBeenCalledWith
assertion — it now includes timeoutMs: 30_000 and still passes, confirming the field is
forwarded on real calls.

Source-level proof

QQBOT_TOKEN_TIMEOUT_MS = 30_000 is defined in token.ts and forwarded as timeoutMs
in the single fetchWithSsrFGuard call in doFetchToken. No other call sites are
affected; the other QQBot fetchWithSsrFGuard callers already implement timeout via
AbortController + signal (api-client.ts, channel-api.ts, media-chunked.ts, media.ts)
or timeoutMs (stt.ts).

Diff summary

extensions/qqbot/src/engine/api/token.ts      |  5 +++++ (constant + timeoutMs field)
extensions/qqbot/src/engine/api/token.test.ts | 14 ++++++++++++++ (updated exact assertion + new regression test)

Reproduction sketch (end-to-end, not run)

  1. Stand up a TCP server that accepts connections and sends a valid TLS handshake but
    never emits an HTTP response.
  2. Route bots.qq.com to that server via /etc/hosts.
  3. Trigger any QQBot message that requires a token refresh (empty or expired cache).
  4. Before fix: doFetchToken never resolves — all QQBot operations stall indefinitely.
  5. After fix: fetch aborts after 30 s with a timeout error, error is logged, caller
    receives "Network error getting access_token: ...", gateway can continue.

What was not tested: live bots.qq.com stall scenario with a real QQ Bot application.
Crabbox/Testbox remote CI was not available at submission time.

  • AI-assisted (Cursor / Claude Sonnet 4.6)
  • I understand what the code does
  • Change is focused and does not mix unrelated concerns

@clawsweeper

clawsweeper Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close this PR as superseded by #102897.

So I’m closing this here and keeping the remaining discussion on #102897.

Review details

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible with high confidence: current doFetchToken passes no timeoutMs or signal, and fetchWithSsrFGuard only installs a timeout abort signal when one of those inputs is provided. I did not run a live no-response QQBot token endpoint in this read-only review.

Is this the best way to solve the issue?

Yes for the code shape: using the existing fetchWithSsrFGuard timeoutMs option is the narrowest owner-boundary fix, and this PR also updates the stale exact test expectation. It still needs real behavior proof before merge.

Security review:

Security review cleared: The diff only adds a timeout parameter to an existing guarded, capture-disabled QQBot token request and introduces no dependency, workflow, permission, SSRF-policy, or secret-handling change.

AGENTS.md: found and applied where relevant.

What I checked:

  • linked superseding PR: fix(qqbot): add 30s request timeout to token endpoint fetch #102897 (fix(qqbot): add 30s request timeout to token endpoint fetch) is still open as the canonical replacement.
  • cluster evidence: the durable review links that PR in the work cluster or recommended risk path.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • vincentkoc: Recent history includes guarded QQBot token/API fetch work and token response body bounding near this same reliability surface. (role: recent token-path contributor; confidence: high; commits: b855b1d047ee, 8594af21e999, e085fa1a3ffd; files: extensions/qqbot/src/engine/api/token.ts, extensions/qqbot/src/engine/api/token.test.ts, extensions/qqbot/src/engine/api/api-client.ts)
  • sliverp: History shows Sliverp introduced the QQBot channel and later authored the merged token-fetch RFC2544 SSRF policy fix on this guarded request path. (role: QQBot feature and token-policy contributor; confidence: high; commits: bf6f506dfae6, 0552ec899f38; files: extensions/qqbot/src/api.ts, extensions/qqbot/src/engine/api/token.ts, extensions/qqbot/src/engine/api/token.test.ts)
  • steipete: History for fetchWithSsrFGuard includes request-local undici dispatcher and guarded fetch changes by steipete, and he merged the recent current-main commit that carried these token files forward. (role: network runtime contributor and recent merger; confidence: medium; commits: a084e465369c, 1b9ec88d9cc5, 0e626690cd5d; files: src/infra/net/fetch-guard.ts, src/infra/net/undici-runtime.ts, extensions/qqbot/src/engine/api/token.ts)
  • Pandah97: Current-main blame for the token fetch call points to the squash-merged PR that brought the current token files onto main, though broader QQBot history points to other owners too. (role: current-file recent contributor; confidence: low; commits: 0e626690cd5d, 24b4c98ba01f; files: extensions/qqbot/src/engine/api/token.ts, extensions/qqbot/src/engine/api/token.test.ts)

Codex review notes: model internal, reasoning high; reviewed against 3c048ef05297.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: qqbot P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant