Skip to content

fix(qqbot): resolve start() when abort signal already fired - #109896

Closed
ZengWen-DT wants to merge 3 commits into
openclaw:mainfrom
ZengWen-DT:fix/qqbot-gateway-startup-abort
Closed

ZengWen-DT wants to merge 3 commits into
openclaw:mainfrom
ZengWen-DT:fix/qqbot-gateway-startup-abort

Conversation

@ZengWen-DT

@ZengWen-DT ZengWen-DT commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where stopping the QQBot gateway during or immediately after startup could leave GatewayConnection.start() pending forever when the caller AbortSignal was already aborted. The previous lifecycle also continued connecting after an early abort, which could leave a socket created during shutdown outside cleanup ownership.

Why This Change Was Made

start() registered abort listeners after work had already begun without normalizing an already-fired signal. The fix makes abort handling idempotent at registration, skips connection work for pre-aborted starts, and checks lifecycle ownership after each asynchronous startup stage. A socket created after an in-flight abort is closed before it can be adopted. Risk is limited to the QQBot connection startup and shutdown path; no config or protocol surface changes.

User Impact

QQBot channel stop/restart no longer hangs when shutdown overlaps startup, and startup does not retain a WebSocket that finishes opening after its lifecycle owner has stopped.

Evidence

Live configured-account proof (redacted):

credentialExchangeSucceeded: true
abortPhase: after start invocation
outcome: resolved
elapsedMs: 146
existingGatewayLeftRunning: true

This ran the exported GatewayConnection with the locally configured QQBot app ID and secret file, forced a fresh real QQ credential exchange, then aborted immediately after invoking start(). The patched lifecycle resolved in 146 ms after the real credential request and stopped before gateway URL/socket adoption. The already-running live Gateway was left online, and no messages were sent.

Deterministic before proof on the original implementation:

label: before-fix
timedOut: true
elapsedMs: 501
resolved: false
exit: 1

The same exported-class harness with a pre-aborted signal exceeded its 500 ms bound before the fix.

Focused regression tests:

$ node scripts/run-vitest.mjs extensions/qqbot/src/engine/gateway/gateway-connection.test.ts
Test Files  1 passed (1)
Tests       9 passed (9)

Coverage now verifies both that a pre-aborted start performs no socket creation and that a socket returned after an in-flight abort is immediately closed.

Additional checks:

$ pnpm format extensions/qqbot/src/engine/gateway/gateway-connection.ts extensions/qqbot/src/engine/gateway/gateway-connection.test.ts
Finished on 2 files

$ git diff --check
# clean

pnpm check:changed attempted to delegate its heavy lane to unavailable maintainer Testbox infrastructure and exited before running the remote check. Full type/lint/build gates are therefore left to GitHub Actions. A full active-service restart was not performed because it would disrupt the existing live channel.

AI-assisted: Codex and Cursor; proof runs executed on this machine.

@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. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 4, 2026, 11:18 AM ET / 15:18 UTC.

ClawSweeper review

What this changes

The PR adds QQBot gateway abort checks after credential, gateway-URL, and WebSocket setup, with tests for pre-abort startup and late socket disposal.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep this PR open: it usefully fences late QQBot resources after shutdown, but its startup promise still waits for an in-flight token request after abort, leaving a user-visible shutdown stall.

Priority: P1
Reviewed head: 546ab4da73aab0cef551d3a2f8b59a7f4b041ef0

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong real behavior evidence supports a useful repair, but a P1 shutdown-settlement gap remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body includes redacted configured-account after-fix output with a resolved abort outcome and a before-fix timeout, supplemented by focused regression tests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes redacted configured-account after-fix output with a resolved abort outcome and a before-fix timeout, supplemented by focused regression tests.
Evidence reviewed 6 items Current pre-abort behavior: Current main already invokes shutdown for an already-aborted signal, sets the lifecycle state before its first await, and skips connect; the PR's remaining value is the in-flight resource race.
PR lifecycle fences: The PR adds post-await abort checks and closes a WebSocket returned after shutdown before assigning it as the active connection.
Remaining shutdown stall: start() awaits connect before observing the shutdown result, while token acquisition accepts no caller abort signal and its network request is allowed 30 seconds.
Findings 1 actionable finding [P1] Settle start while credential exchange is still pending
Security None None.

How this fits together

QQBot account startup obtains credentials, resolves a gateway URL, and opens a WebSocket that carries channel events. Gateway shutdown supplies an abort signal that must end startup promptly and prevent resources created afterward from becoming active.

flowchart LR
  A[Gateway account start] --> B[QQBot connection startup]
  B --> C[Credential exchange]
  C --> D[Gateway URL lookup]
  D --> E[WebSocket creation]
  E --> F[Active channel connection]
  G[Shutdown abort signal] --> B
  G --> E
Loading

Before merge

  • Settle start while credential exchange is still pending (P1) - The added guard runs only after getAccessToken() resolves, but start() awaits connect() before it observes shutdown. An abort during the token request therefore still keeps the caller pending for up to the 30-second token timeout. This remains the prior P1 blocker; make shutdown settle independently and cover a deferred-token abort.
  • Resolve merge risk (P2) - Without decoupling startup settlement from the in-flight token request, stopping QQBot can still wait up to the token request's 30-second timeout before the start promise resolves.
  • Complete next step (P2) - A narrow mechanical lifecycle repair and focused regression test can resolve the remaining blocker without a product or API decision.

Findings

  • [P1] Settle start while credential exchange is still pending — extensions/qqbot/src/engine/gateway/gateway-connection.ts:304
Agent review details

Security

None.

PR surface

Source +21, Tests +54. Total +75 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 21 0 +21
Tests 1 54 0 +54
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 75 0 +75

Review metrics

Metric Value Why it matters
Production vs test LOC production +21, tests +54 The production growth is justified by QQBot lifecycle ownership and is accompanied by focused regression coverage, but the remaining pending-token path still needs proof.

Merge-risk options

Maintainer options:

  1. Settle shutdown independently of token exchange (recommended)
    Keep the late abort fences, but observe shutdown without serially awaiting credential exchange and add a deferred-token regression test.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Decouple GatewayConnection.start() settlement from a pending credential request after abort; retain late-resource disposal fences and add a deferred-token regression proving prompt settlement with no later URL or socket creation.

Technical review

Best possible solution:

Keep the late-resource guards, but make shutdown settle start immediately while the in-flight connection path finishes only enough work to fence and dispose late resources.

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

Yes—use a deferred token exchange, abort after it begins, and assert that start settles before releasing the token; current source shows it instead waits for connect.

Is this the best way to solve the issue?

No—the late-resource guards are correct, but they do not make start settle while token acquisition remains pending; the lifecycle owner should observe shutdown concurrently.

Full review comments:

  • [P1] Settle start while credential exchange is still pending — extensions/qqbot/src/engine/gateway/gateway-connection.ts:304
    The added guard runs only after getAccessToken() resolves, but start() awaits connect() before it observes shutdown. An abort during the token request therefore still keeps the caller pending for up to the 30-second token timeout. This remains the prior P1 blocker; make shutdown settle independently and cover a deferred-token abort.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A QQBot stop/start overlap can keep the awaited channel lifecycle pending for the credential timeout.
  • merge-risk: 🚨 availability: This PR changes gateway startup and shutdown ordering, where an incomplete repair can stall or leak a live channel connection.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes redacted configured-account after-fix output with a resolved abort outcome and a before-fix timeout, supplemented by focused regression tests.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes redacted configured-account after-fix output with a resolved abort outcome and a before-fix timeout, supplemented by focused regression tests.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/qqbot/src/engine/gateway/gateway-connection.test.ts.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • Peter Steinberger: Recent QQBot gateway restart and ingress work appears in the relevant file history, with the largest sampled contribution count for this gateway area. (role: recent QQBot gateway contributor; confidence: medium; commits: 8d89ddd8c22b, 2438a9cc3cd8; files: extensions/qqbot/src/engine/gateway/gateway-connection.ts, extensions/qqbot/src/engine/gateway/gateway.ts)
  • Vincent Koc: Current-line blame attributes the checked-out gateway snapshot to this recent commit, though shallow history limits stronger ownership attribution. (role: recent area contributor; confidence: low; commits: ee397f0c59fe; files: extensions/qqbot/src/engine/gateway/gateway-connection.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Make start settle on abort while credential exchange is pending, then add the deferred-token regression proof.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (7 earlier review cycles)
  • reviewed 2026-07-17T10:03:23.332Z sha 1235f5e3457da345300e34d51f16c3a39abfbf5a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T12:13:29.235Z sha 91379c2 :: needs changes before merge. :: [P1] Handle the error before closing a connecting socket
  • reviewed 2026-07-17T14:22:06.496Z sha 124f858 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T15:04:07.119Z sha 124f858 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-19T01:58:44.441Z sha 546ab4d :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T08:05:13.126Z sha 546ab4d :: needs changes before merge. :: [P1] Return before starting credential exchange
  • reviewed August 4, 2026, 11:18 AM ET / 15:18 UTC sha unknown :: needs changes before merge. :: [P1] Settle start while credential exchange is still pending

GatewayConnection.start() waited on an abort listener that never runs
when the caller's AbortSignal is already aborted, leaving channel stop
hung. Check abortSignal.aborted before registering the listener.

Co-authored-by: Cursor <[email protected]>
@ZengWen-DT
ZengWen-DT force-pushed the fix/qqbot-gateway-startup-abort branch from 1235f5e to 91379c2 Compare July 17, 2026 12:06
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed 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. labels Jul 17, 2026
ws.close() on a CONNECTING socket emits an error from abortHandshake().
Without a listener, Node treats it as unhandled and terminates the Gateway.
Attach a noop error handler before disposal, and update the late-socket test
to model real ws connecting-state error emission.
@ZengWen-DT

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 17, 2026
LZY3538 added a commit to LZY3538/openclaw that referenced this pull request Jul 18, 2026
When the gateway stop AbortSignal is already aborted at construction
time, the addEventListener('abort', onAbort) listener never fires per
the AbortSignal spec. This leaves waitForExit pending forever, hanging
channel shutdown. The fix resolves onAbort immediately when
abortSignal.aborted is already true, matching the pre-aborted handling
pattern in WhatsApp connection-controller (openclaw#109903) and QQBot
gateway-connection (openclaw#109896).

Co-Authored-By: Claude <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 31, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 31, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for this fix! Unfortunately this PR is no longer landable here: QQBot was externalized in #107295 (landed as 84c7d45f15cd), and extensions/qqbot no longer exists in this repository. The channel now ships as @tencent-connect/openclaw-qqbot, maintained by the Tencent Connect team at https://github.com/tencent-connect/openclaw-qqbot.

If the problem still exists in the external package's 2.x code, please port the patch to that repository — the maintainers there own this surface now. Closing as unlandable against current main; this is not a judgment on the fix itself.

@steipete steipete closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: qqbot merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants