Skip to content

fix(discord): bound repeated READY recovery - #162377

Closed
yashas-13 wants to merge 2 commits into
openclaw:mainfrom
yashas-13:fix/162189-discord-ready-recovery-v2
Closed

yashas-13 wants to merge 2 commits into
openclaw:mainfrom
yashas-13:fix/162189-discord-ready-recovery-v2

Conversation

@yashas-13

Copy link
Copy Markdown
Contributor

Closes #162189

Summary

  • bound consecutive Discord READY recovery attempts to 10
  • escalate persistent READY failures by ending the lifecycle so the outer provider supervisor can recreate the Discord client
  • publish a distinct startup-recovery-exhausted status and add a focused regression test

Root cause

After a Discord DNS/network outage, the READY wait loop could reconnect the same client indefinitely after the network recovered. The reported installation remained in READY-wait retries for hours and only recovered after a full Gateway restart.

Fix

After 10 consecutive startup READY timeouts, the lifecycle now reports startup-recovery-exhausted and throws a bounded lifecycle error instead of reconnecting forever. The existing provider lifecycle cleanup path remains responsible for tearing down the client; the outer provider supervisor can then recreate the provider.

Normal transient recovery is unchanged for attempts 1–9, and successful READY still clears the recovery state.

Regression

Added a lifecycle test proving:

  • nine reconnects are attempted;
  • the tenth timeout escalates instead of reconnecting again;
  • the provider stop path has not been entered yet;
  • the status records startup-recovery-exhausted.

No local test execution is claimed; validation is delegated to CI.

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: XS labels Oct 1, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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 Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR limits Discord startup readiness failures to ten timeouts, reports exhaustion, and adds a regression test for handing failure to the account restart supervisor.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused recovery change has useful signal, but missing transport teardown and runtime proof prevent merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

This remains useful work for an unresolved Discord recovery problem, but the new exhaustion path leaves the old transport running and the PR lacks real recovery proof.

Priority: P1
Reviewed head: 32b6606f6ec2e1228027a95a4da82bda7276e8df

Before merge

  • Add real behavior proof - The changed Discord lifecycle is covered only by an unexecuted mocked regression; no after-fix trace shows exhaustion, old-client shutdown, replacement startup, and recovered READY. Provide redacted terminal output or logs from the real transport path, including an injected outage if needed. Screenshots or recordings may supplement that trace. Remove tokens, IP addresses, phone numbers, and private endpoints; updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Disconnect the exhausted gateway before rejecting the lifecycle (P1) - On the tenth timeout, this throw skips waitForDiscordGatewayStop, which normally calls gateway.disconnect(). The lifecycle’s finally only removes observers and bindings, and cleanupDiscordProviderStartup skips disconnect because lifecycleStarted is already true. Consequently the socket or scheduled reconnect from the ninth attempt remains active while the outer supervisor creates another client. Stop the predecessor transport on this exit path and update the regression to verify teardown before replacement.
  • Resolve merge risk - Exhaustion can leave the previous Discord socket and reconnect machinery active alongside the replacement client.
  • Complete next step - Repair transport teardown on exhaustion, run the focused regression, and supply redacted after-fix recovery evidence before merge.

Findings

  • [P1] Disconnect the exhausted gateway before rejecting the lifecycle — extensions/discord/src/monitor/provider.lifecycle.ts:351-352
Agent review details

How this fits together

The Discord lifecycle waits for the bot connection to become ready and publishes account health. Failed provider tasks reach the Gateway’s account supervisor, which can start a replacement Discord client.

flowchart TD
 A[Discord connection] --> B[Wait for readiness]
 B --> C{Ready before retry limit}
 C -->|Yes| D[Receive Discord events]
 C -->|No| E[Stop old transport]
 E --> F[Account restart supervisor]
 F --> A
Loading

Technical review

Best possible solution:

Give lifecycle teardown responsibility for stopping the old transport before account recreation, while preserving transient retries and accurate recovery status.

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

Yes from source: ten startup timeouts reach the new throw while bypassing the only normal lifecycle disconnect path. No runtime reproduction or tests were executed in this read-only review.

Is this the best way to solve the issue?

The bounded handoff is appropriate, but the patch is incomplete because it assumes cleanup stops a transport that it actually leaves running.

Full review comments:

  • [P1] Disconnect the exhausted gateway before rejecting the lifecycle — extensions/discord/src/monitor/provider.lifecycle.ts:351-352
    On the tenth timeout, this throw skips waitForDiscordGatewayStop, which normally calls gateway.disconnect(). The lifecycle’s finally only removes observers and bindings, and cleanupDiscordProviderStartup skips disconnect because lifecycleStarted is already true. Consequently the socket or scheduled reconnect from the ninth attempt remains active while the outer supervisor creates another client. Stop the predecessor transport on this exit path and update the regression to verify teardown before replacement.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b58f2a2c3327.

Merge-risk options

Maintainer options:

  1. Stop the predecessor before replacement (recommended)
    Repair lifecycle teardown and verify that exhaustion disables the old transport before a new client starts.

Security

None.

Evidence

What I checked:

PR surface

Source +17, Tests +25. Total +42 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 17 0 +17
Tests 1 25 0 +25
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 42 0 +42

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #162189
Summary: This PR explicitly targets the reported unbounded startup READY recovery route.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The linked report describes multiple Discord accounts unable to recover for hours after a network outage.
  • merge-risk: 🚨 message-delivery: The new restart path can retain an active predecessor connection alongside its replacement, risking conflicting event delivery.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Repair exhaustion teardown and demonstrate a failing-before, passing-after regression that verifies the predecessor transport stops.
  • Add a redacted production-path recovery trace showing a replacement client reaches READY, and record the focused test’s measured duration.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 1, 2026, 12:15 AM ET / 04:15 UTC.

obviyus added a commit that referenced this pull request Nov 18, 2026
Root cause: extensions/discord/src/internal/gateway-identify-limiter.ts:10 reserved the shared 5 s IDENTIFY window as soon as a socket started waiting, even when that socket was replaced before its turn, so with four or more Discord accounts retrying READY the abandoned reservations pushed the queue further ahead of real time on every retry and the waiting accounts never sent IDENTIFY again.

Fixes #162189

## What Problem This Solves

After a network or DNS outage, a Gateway running several Discord bot accounts could bring only some of them back. The rest kept logging `gateway READY wait timed out ... reconnecting with backoff` for hours and only recovered after a full Gateway restart. Thanks @mattreyes0824 for the detailed report: the untouched `session_start_limit` on the stuck accounts (they never sent IDENTIFY) pointed straight at this.

## User Impact

Every Discord account reconnects and receives messages again once the network comes back, without restarting the Gateway.

## Why This Change Was Made

All Discord accounts in one Gateway share one IDENTIFY pacing window (one IDENTIFY per 5 s). It handed out the next slot to whoever started waiting, before knowing whether that caller would still identify. When the network returns, each stuck account reconnects every ~17 s (15 s READY wait plus 2 s backoff) and joins the queue again; its previous wait is abandoned because the socket was replaced, but its slot stayed reserved. With four or more accounts the queue grows faster than time passes, every waiter is replaced before its turn, and the queue never drains. A process restart was the only thing that reset it, which matches the report (3 of 7 accounts recovered, 4 never identified).

Now a slot is claimed only by an IDENTIFY that is actually sent, so replaced sockets leave the window free for the next live one. The window also uses the monotonic clock, so a wall-clock step cannot stall it.

This replaces #162377 (thanks @yashas-13 for the first fix attempt): it bounded the READY retries and restarted the account, but the restarted account joins the same process-wide queue, which is still pushed far ahead. The proof below shows this directly: on main the health monitor already restarts the stuck accounts with a fresh client, and they still never send IDENTIFY.

## Evidence

Real Gateway (`ocx src`, source tier, plus one branch run on the built `dist/` under Node) with 7 Discord accounts pointed through `DISCORD_API_URL` at a local Discord REST + Gateway stand-in. The stand-in drops every Gateway WebSocket for 100 s while the accounts start, then accepts them again; it logs each IDENTIFY it receives. Two runs per side plus a control, on merge base 3bc20e2 and branch head db4528e:

- Before (main): after the network returned, only 3 of 7 accounts sent IDENTIFY; the other 4 sent none in the next 5 minutes and kept timing out on READY (both runs). In run 2 they still reported `connected=false` after the health monitor restarted them. Control with 3 accounts on main: all recover, as the queue can keep up.
- After (this branch): all 7 accounts sent IDENTIFY within about 30 s, 5 s apart, and the READY timeouts stopped (both source runs and the built Node run); run 2 and the Node run report every account `connected=true`.
- The focused gateway regression test fails on main and passes here.

Proof lines: #201415 (comment) (main vs branch, two runs each, control, Node run) and #201415 (comment) (rerun on the exact head 93ca882).

Merge danger: two-way door. The change is local to Discord IDENTIFY pacing and writes no state; a revert fully restores the old behavior. Blast radius if wrong: Discord accounts identifying too fast (rate limited) or too slowly at startup.

Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Thank you @yashas-13 for working on this. The root cause turned out to be the shared Discord IDENTIFY limiter: it booked a slot as soon as a socket started waiting and kept it when that socket was replaced, so with several accounts retrying READY every slot was booked ahead and no socket ever sent IDENTIFY, even after an account restart. #201415 (cf5cf7a) books the slot only when IDENTIFY is actually sent; in a 7-account outage test all accounts reconnected within about 30 s. Bounding the READY retries alone would still leave restarted accounts behind the same booked queue, so I'm closing this one as covered, with thanks for the early diagnosis.

@obviyus obviyus closed this Nov 18, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
…w#201415)

Root cause: extensions/discord/src/internal/gateway-identify-limiter.ts:10 reserved the shared 5 s IDENTIFY window as soon as a socket started waiting, even when that socket was replaced before its turn, so with four or more Discord accounts retrying READY the abandoned reservations pushed the queue further ahead of real time on every retry and the waiting accounts never sent IDENTIFY again.

Fixes openclaw#162189

## What Problem This Solves

After a network or DNS outage, a Gateway running several Discord bot accounts could bring only some of them back. The rest kept logging `gateway READY wait timed out ... reconnecting with backoff` for hours and only recovered after a full Gateway restart. Thanks @mattreyes0824 for the detailed report: the untouched `session_start_limit` on the stuck accounts (they never sent IDENTIFY) pointed straight at this.

## User Impact

Every Discord account reconnects and receives messages again once the network comes back, without restarting the Gateway.

## Why This Change Was Made

All Discord accounts in one Gateway share one IDENTIFY pacing window (one IDENTIFY per 5 s). It handed out the next slot to whoever started waiting, before knowing whether that caller would still identify. When the network returns, each stuck account reconnects every ~17 s (15 s READY wait plus 2 s backoff) and joins the queue again; its previous wait is abandoned because the socket was replaced, but its slot stayed reserved. With four or more accounts the queue grows faster than time passes, every waiter is replaced before its turn, and the queue never drains. A process restart was the only thing that reset it, which matches the report (3 of 7 accounts recovered, 4 never identified).

Now a slot is claimed only by an IDENTIFY that is actually sent, so replaced sockets leave the window free for the next live one. The window also uses the monotonic clock, so a wall-clock step cannot stall it.

This replaces openclaw#162377 (thanks @yashas-13 for the first fix attempt): it bounded the READY retries and restarted the account, but the restarted account joins the same process-wide queue, which is still pushed far ahead. The proof below shows this directly: on main the health monitor already restarts the stuck accounts with a fresh client, and they still never send IDENTIFY.

## Evidence

Real Gateway (`ocx src`, source tier, plus one branch run on the built `dist/` under Node) with 7 Discord accounts pointed through `DISCORD_API_URL` at a local Discord REST + Gateway stand-in. The stand-in drops every Gateway WebSocket for 100 s while the accounts start, then accepts them again; it logs each IDENTIFY it receives. Two runs per side plus a control, on merge base d28eb7d and branch head db4528e:

- Before (main): after the network returned, only 3 of 7 accounts sent IDENTIFY; the other 4 sent none in the next 5 minutes and kept timing out on READY (both runs). In run 2 they still reported `connected=false` after the health monitor restarted them. Control with 3 accounts on main: all recover, as the queue can keep up.
- After (this branch): all 7 accounts sent IDENTIFY within about 30 s, 5 s apart, and the READY timeouts stopped (both source runs and the built Node run); run 2 and the Node run report every account `connected=true`.
- The focused gateway regression test fails on main and passes here.

Proof lines: openclaw#201415 (comment) (main vs branch, two runs each, control, Node run) and openclaw#201415 (comment) (rerun on the exact head 93ca882).

Merge danger: two-way door. The change is local to Discord IDENTIFY pacing and writes no state; a revert fully restores the old behavior. Blast radius if wrong: Discord accounts identifying too fast (rate limited) or too slowly at startup.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
Root cause: extensions/discord/src/internal/gateway-identify-limiter.ts:10 reserved the shared 5 s IDENTIFY window as soon as a socket started waiting, even when that socket was replaced before its turn, so with four or more Discord accounts retrying READY the abandoned reservations pushed the queue further ahead of real time on every retry and the waiting accounts never sent IDENTIFY again.

Fixes #162189

## What Problem This Solves

After a network or DNS outage, a Gateway running several Discord bot accounts could bring only some of them back. The rest kept logging `gateway READY wait timed out ... reconnecting with backoff` for hours and only recovered after a full Gateway restart. Thanks @mattreyes0824 for the detailed report: the untouched `session_start_limit` on the stuck accounts (they never sent IDENTIFY) pointed straight at this.

## User Impact

Every Discord account reconnects and receives messages again once the network comes back, without restarting the Gateway.

## Why This Change Was Made

All Discord accounts in one Gateway share one IDENTIFY pacing window (one IDENTIFY per 5 s). It handed out the next slot to whoever started waiting, before knowing whether that caller would still identify. When the network returns, each stuck account reconnects every ~17 s (15 s READY wait plus 2 s backoff) and joins the queue again; its previous wait is abandoned because the socket was replaced, but its slot stayed reserved. With four or more accounts the queue grows faster than time passes, every waiter is replaced before its turn, and the queue never drains. A process restart was the only thing that reset it, which matches the report (3 of 7 accounts recovered, 4 never identified).

Now a slot is claimed only by an IDENTIFY that is actually sent, so replaced sockets leave the window free for the next live one. The window also uses the monotonic clock, so a wall-clock step cannot stall it.

This replaces #162377 (thanks @yashas-13 for the first fix attempt): it bounded the READY retries and restarted the account, but the restarted account joins the same process-wide queue, which is still pushed far ahead. The proof below shows this directly: on main the health monitor already restarts the stuck accounts with a fresh client, and they still never send IDENTIFY.

## Evidence

Real Gateway (`ocx src`, source tier, plus one branch run on the built `dist/` under Node) with 7 Discord accounts pointed through `DISCORD_API_URL` at a local Discord REST + Gateway stand-in. The stand-in drops every Gateway WebSocket for 100 s while the accounts start, then accepts them again; it logs each IDENTIFY it receives. Two runs per side plus a control, on merge base 3bc20e2 and branch head db4528e:

- Before (main): after the network returned, only 3 of 7 accounts sent IDENTIFY; the other 4 sent none in the next 5 minutes and kept timing out on READY (both runs). In run 2 they still reported `connected=false` after the health monitor restarted them. Control with 3 accounts on main: all recover, as the queue can keep up.
- After (this branch): all 7 accounts sent IDENTIFY within about 30 s, 5 s apart, and the READY timeouts stopped (both source runs and the built Node run); run 2 and the Node run report every account `connected=true`.
- The focused gateway regression test fails on main and passes here.

Proof lines: #201415 (comment) (main vs branch, two runs each, control, Node run) and #201415 (comment) (rerun on the exact head 93ca882).

Merge danger: two-way door. The change is local to Discord IDENTIFY pacing and writes no state; a revert fully restores the old behavior. Blast radius if wrong: Discord accounts identifying too fast (rate limited) or too slowly at startup.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit cf5cf7a)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…w#201415)

Root cause: extensions/discord/src/internal/gateway-identify-limiter.ts:10 reserved the shared 5 s IDENTIFY window as soon as a socket started waiting, even when that socket was replaced before its turn, so with four or more Discord accounts retrying READY the abandoned reservations pushed the queue further ahead of real time on every retry and the waiting accounts never sent IDENTIFY again.

Fixes openclaw#162189

## What Problem This Solves

After a network or DNS outage, a Gateway running several Discord bot accounts could bring only some of them back. The rest kept logging `gateway READY wait timed out ... reconnecting with backoff` for hours and only recovered after a full Gateway restart. Thanks @mattreyes0824 for the detailed report: the untouched `session_start_limit` on the stuck accounts (they never sent IDENTIFY) pointed straight at this.

## User Impact

Every Discord account reconnects and receives messages again once the network comes back, without restarting the Gateway.

## Why This Change Was Made

All Discord accounts in one Gateway share one IDENTIFY pacing window (one IDENTIFY per 5 s). It handed out the next slot to whoever started waiting, before knowing whether that caller would still identify. When the network returns, each stuck account reconnects every ~17 s (15 s READY wait plus 2 s backoff) and joins the queue again; its previous wait is abandoned because the socket was replaced, but its slot stayed reserved. With four or more accounts the queue grows faster than time passes, every waiter is replaced before its turn, and the queue never drains. A process restart was the only thing that reset it, which matches the report (3 of 7 accounts recovered, 4 never identified).

Now a slot is claimed only by an IDENTIFY that is actually sent, so replaced sockets leave the window free for the next live one. The window also uses the monotonic clock, so a wall-clock step cannot stall it.

This replaces openclaw#162377 (thanks @yashas-13 for the first fix attempt): it bounded the READY retries and restarted the account, but the restarted account joins the same process-wide queue, which is still pushed far ahead. The proof below shows this directly: on main the health monitor already restarts the stuck accounts with a fresh client, and they still never send IDENTIFY.

## Evidence

Real Gateway (`ocx src`, source tier, plus one branch run on the built `dist/` under Node) with 7 Discord accounts pointed through `DISCORD_API_URL` at a local Discord REST + Gateway stand-in. The stand-in drops every Gateway WebSocket for 100 s while the accounts start, then accepts them again; it logs each IDENTIFY it receives. Two runs per side plus a control, on merge base 3bc20e2 and branch head db4528e:

- Before (main): after the network returned, only 3 of 7 accounts sent IDENTIFY; the other 4 sent none in the next 5 minutes and kept timing out on READY (both runs). In run 2 they still reported `connected=false` after the health monitor restarted them. Control with 3 accounts on main: all recover, as the queue can keep up.
- After (this branch): all 7 accounts sent IDENTIFY within about 30 s, 5 s apart, and the READY timeouts stopped (both source runs and the built Node run); run 2 and the Node run report every account `connected=true`.
- The focused gateway regression test fails on main and passes here.

Proof lines: openclaw#201415 (comment) (main vs branch, two runs each, control, Node run) and openclaw#201415 (comment) (rerun on the exact head 93ca882).

Merge danger: two-way door. The change is local to Discord IDENTIFY pacing and writes no state; a revert fully restores the old behavior. Blast radius if wrong: Discord accounts identifying too fast (rate limited) or too slowly at startup.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit cf5cf7a)

Release adaptation: None; migrate limiter and all gateway callers together.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. 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. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Discord accounts still wedge in READY-wait loop after DNS outage on 2026.9.4 (regression/incomplete fix of #125813)

2 participants