Skip to content

fix(discord): honor abortSignal during gateway READY retry backoff - #108561

Merged
steipete merged 4 commits into
openclaw:mainfrom
wangmiao0668000666:fix/discord-lifecycle-abort-backoff
Jul 16, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
wangmiao0668000666:fix/discord-lifecycle-abort-backoff

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

waitForGatewayReady in extensions/discord/src/monitor/provider.lifecycle.ts:402-405 slept the full DISCORD_GATEWAY_READY_RETRY_BACKOFF_MS = 2_000 between READY retry attempts using a bare setTimeout(resolve, ms) that never received the owning monitor's AbortSignal. When monitorDiscordAccount.stop() fires mid-backoff, the loop sits through the full 2 s before the next while (!params.abortSignal?.aborted) check at line 371 notices.

Sibling abort points around it are wired correctly: restartGatewayAfterReadyTimeout (line 396) already honors the signal at lines 73, 80, 115, 173. Only the backoff sleep itself was unwired. PR #104339 (open) replaces this fixed 2 s backoff with exponential backoff up to 30 s+, making the unwired sleep more visible once it lands — whichever PR merges first, the other rebases cleanly (disjoint lines).

Why This Change Was Made

The retry-backoff sleep is now sleepWithAbort(..., params.abortSignal) wrapped in try { ... } catch { return; }. sleepWithAbort (packages/retry/src/index.ts:36) rejects on abort, the same shape used by sibling callers channel.ts:713-717 and message-handler.retry.ts:52 inside this plugin. waitForGatewayReady is exposed via a testing export re-exported from test-api.ts so the regression test can drive the production path directly; signature and behavior for the existing caller at line 532 are unchanged.

The inner READY poll sleep at line 354-357 (DISCORD_GATEWAY_READY_POLL_MS = 250) is intentionally left alone: the enclosing while already re-checks abort every 250 ms, the same cadence as the poll.

No new config, no new env, no SDK change, no shared helper change.

User Impact

Stopping or restarting a Discord account while the gateway is mid READY retry no longer holds the loop for the remainder of the 2 s backoff. The loop now exits on the next abort event, the same cadence already used by the sibling session-conflict retry and channel startup delay. Happy-path behavior is unchanged.

Evidence

Fix before

[0ms] >>> abort fires
[1200ms] waitForGatewayReady resolved
elapsedMs: 2258
connectCalls: 1
disconnectCalls: 1

Abort fired 950 ms into the 2 000 ms backoff; the loop still waited the full backoff before returning — 1 050 ms wasted.

Fix after

[0ms] >>> abort fires
[1200ms] waitForGatewayReady resolved
elapsedMs: 1202
connectCalls: 1
disconnectCalls: 1

Same harness, same timing; the abort listener now interrupts the backoff sleep immediately — 1 ms response. connectCalls: 1 confirms no second restart cycle fired.

How the proof was produced

Uncommitted scratchpad/discord-lifecycle-abort-proof.ts drives the production waitForGatewayReady with a stub gateway whose isConnected stays false, a real AbortController, and real wall-clock timers. readyTimeoutMs = 200 so the first READY wait times out at ~200 ms, the gateway restart runs, then the 2 000 ms backoff starts. Abort fires at 1 200 ms (950 ms into the backoff).

Mutation proof

git stash push extensions/discord/src/monitor/provider.lifecycle.ts (keep test changes) → the new test fails with TypeError: waitForGatewayReady is not a function because the testing export is part of the fix.

Tests & checks

  • provider.lifecycle.test.ts 21/21 passed
  • extensions/discord/src/retry.test.ts 30/30 passed
  • tsgo -p tsconfig.extensions.json exit=0 (only pre-existing packages/net-policy errors)
  • tsgo -p test/tsconfig/tsconfig.extensions.test.json exit=0 (same pre-existing errors)
  • oxlint exit=0 on changed files
  • git diff --check clean

Prod-only non-test LOC: +10 / -6 on one file.

@steipete steipete self-assigned this Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 16, 2026, 12:12 AM ET / 04:12 UTC.

Summary
Replaces the Discord gateway READY retry’s fixed non-abortable sleep with an abort-aware sleep and adds direct regression coverage through the plugin test API.

PR surface: Source +9, Tests +47. Total +56 across 3 files.

Reproducibility: yes. from source inspection: aborting after a failed READY restart leaves the raw two-second timer running until its next loop check. The submitted wall-clock harness demonstrates that path, although this review did not establish it against a real Discord connection.

Review metrics: none identified.

Root-cause cluster
Relationship: canonical
Canonical: #108561
Summary: This PR is the focused candidate for the abort-during-backoff bug; the exponential-backoff PR changes delay policy but does not replace this cancellation requirement.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

Proof guidance:

  • [P1] Needs real behavior proof before merge: The before/after transcript uses production lifecycle code and real timers but a stub gateway; add a redacted live Discord account stop or restart transcript, log, or recording, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review.

Risk before merge

Maintainer options:

  1. Decide the mitigation before merge
    Keep one abort-aware READY retry delay regardless of whether the final policy remains fixed or becomes exponential, with focused regression coverage and a redacted live Discord account stop or restart transcript demonstrating prompt cancellation.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Contributor action is limited to supplying real Discord behavior proof and refreshing the overlapping branch; there is no concrete code defect for an automated repair worker.

Security
Cleared: The patch changes only Discord lifecycle cancellation and test exposure; it adds no dependency, credential, permission, workflow, download, or supply-chain surface.

Review details

Best possible solution:

Keep one abort-aware READY retry delay regardless of whether the final policy remains fixed or becomes exponential, with focused regression coverage and a redacted live Discord account stop or restart transcript demonstrating prompt cancellation.

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

Yes from source inspection: aborting after a failed READY restart leaves the raw two-second timer running until its next loop check. The submitted wall-clock harness demonstrates that path, although this review did not establish it against a real Discord connection.

Is this the best way to solve the issue?

Yes. Reusing the existing abort-aware sleep helper at the exact uncancellable delay is narrower and more maintainable than adding another timer or lifecycle abstraction, provided any exponential-backoff follow-up preserves the signal.

AGENTS.md: unclear because the file could not be read completely.

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

Label changes

Label changes:

  • add P2: This is a bounded Discord lifecycle responsiveness bug that can delay shutdown or restart by the remaining retry backoff but does not make the core runtime unusable.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded Discord lifecycle responsiveness bug that can delay shutdown or restart by the remaining retry backoff but does not make the core runtime unusable.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
Evidence reviewed

PR surface:

Source +9, Tests +47. Total +56 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 14 5 +9
Tests 1 47 0 +47
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 61 5 +56

What I checked:

Likely related people:

  • IVY-AI-gif: Authored the merged Discord gateway READY-race work associated with fix(discord): prevent Identify silent-drop race in gateway startup #68159, which concerns the same startup and reconnect lifecycle. (role: recent READY lifecycle contributor; confidence: medium; files: extensions/discord/src/monitor/provider.lifecycle.ts, extensions/discord/src/monitor/provider.lifecycle.test.ts)
  • vincentkoc: Recent shipped Discord gateway shutdown and buffered reconnect-exhaustion work touches the same cancellation and cleanup behavior. (role: recent adjacent lifecycle contributor; confidence: medium; files: extensions/discord/src/monitor/provider.lifecycle.ts)
  • ngutman: The Discord stale-socket drain and forced fresh-reconnect work associated with fix(discord): force fresh gateway reconnects #54697 is directly adjacent to this retry loop. (role: recent reconnect-path contributor; confidence: medium; files: extensions/discord/src/monitor/provider.lifecycle.ts, extensions/discord/src/monitor/provider.lifecycle.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

steipete and others added 2 commits July 16, 2026 02:53
@steipete
steipete merged commit 8090cb1 into openclaw:main Jul 16, 2026
27 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…penclaw#108561)

* fix(discord): honor abortSignal during gateway READY retry backoff

* fix(discord): avoid __testing alias to satisfy Knip production scan

* test(discord): make READY abort proof deterministic

Co-authored-by: wangmiao0668000666 <[email protected]>

* fix(retry): support unref abort sleeps

Co-authored-by: wangmiao0668000666 <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
SunnyShu0925 added a commit to SunnyShu0925/openclaw that referenced this pull request Jul 26, 2026
The bare setTimeout in ensureBrowserRunning prevents abort during the
250ms retry window. Replace with sleepWithAbort + .catch + throwIfAborted
so the caller's abort signal cancels promptly while preserving the
original abort reason in the error response.

Add a real-timer production-route proof test exercising the actual
registerBrowserTabRoutes handler with real performance.now() timers.

Related: openclaw#108561, openclaw#108408
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…penclaw#108561)

* fix(discord): honor abortSignal during gateway READY retry backoff

* fix(discord): avoid __testing alias to satisfy Knip production scan

* test(discord): make READY abort proof deterministic

Co-authored-by: wangmiao0668000666 <[email protected]>

* fix(retry): support unref abort sleeps

Co-authored-by: wangmiao0668000666 <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
@wangmiao0668000666
wangmiao0668000666 deleted the fix/discord-lifecycle-abort-backoff branch October 28, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants