Repository navigation
fix(discord): reconnect every account after a network outage - #201415
Conversation
- The shared IDENTIFY limiter reserved a 5 s window when a socket started waiting, even when that socket was replaced before its turn. With four or more accounts retrying READY, the abandoned reservations pushed the queue ahead of real time, so the waiting accounts never sent IDENTIFY again until the process restarted. - Claim the window only when IDENTIFY is actually sent, on the monotonic clock. Fixes #162189
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR charges Discord’s shared five-second IDENTIFY window only when a current, open socket sends IDENTIFY. Example: Seven Discord accounts reconnect after a 100-second network outage.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR fixes a verified Discord recovery defect that remains on main, with no actionable defects found in the patch; exact-head CI is still running. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherDiscord’s Gateway client handles HELLO events, passes fresh identification through a process-wide limiter, and sends IDENTIFY over the current WebSocket before receiving READY. flowchart LR
A[Account lifecycle] --> B[Gateway WebSocket]
B --> C[HELLO handler]
C --> D[Shared IDENTIFY limiter]
D --> E[Current socket check]
E --> F[IDENTIFY send]
F --> G[READY and connected status]
Technical reviewBest possible solution: Keep the existing shared limiter as the sole pacing owner, committing each window synchronously with a live socket’s IDENTIFY send. Do we have a high-confidence way to reproduce the issue? Current-main source establishes abandoned IDENTIFY reservations, and supplied before/after Gateway traces reproduce the seven-account failure and recovery; no target code was executed during this review. Is this the best way to solve the issue? This is a focused root-cause repair: it changes reservation accounting at the existing owner, preserves socket identity and pacing checks, and extends the existing regression without adding recovery machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 77c61b36aab1. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +7, Tests +1. Total +8 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 18, 2026, 3:13 PM ET / 20:13 UTC (Revision 3). |
|
Gateway proof for #162189: real Gateway ( |
…b target - The extension declaration build has no Promise.withResolvers; use the executor form main used.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Exact-head rerun on 93ca882 (same harness, |
- The session-identity ratchet matches the phrase used in the previous comment.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Thanks @mattreyes0824 for the report, and @yashas-13 for the earlier attempt in #162377. This is merged in cf5cf7a: a Discord account that loses its connection during a network or DNS outage no longer stays stuck waiting for READY after the network comes back; it reconnects on its own. |
…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]>
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]>
…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]>
Baseline adaptation: Claim a monotonic IDENTIFY window only when the current socket sends, retaining the shipped identify serializer and reconnect paths. (cherry picked from commit cf5cf7a) Co-authored-by: RomneyDa <[email protected]>
When neither the selected endpoint nor the model row declares input, ClawRouter's fallback classified gpt-6.2-sol and gpt-6.2-astra as text-only. Add both upstream IDs and cover them in the fallback test. (cherry picked from commit 3bc20e2) Release adaptation: Cite the original PR’s November 18, 2026 live ClawRouter image proof in the legacy fallback; exact upstream IDs, explicit modality precedence, and text-only behavior for unrecognized models are unchanged. Follow-up audit: #205137’s catalog clock fixture is already equivalent (70a36ea), and #203898 is already integrated (fec6728). #207768 classifies catalog misses and #192450 adds Bedrock routing; neither is required by the exact-ID fallback. #201434 and #201415 mention the donor SHA as an unrelated verification baseline. Original #200878 has no additional follow-up reference at the pinned scan end. Co-authored-by: RomneyDa <[email protected]>
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 backofffor hours and only recovered after a full Gateway restart. Thanks @mattreyes0824 for the detailed report: the untouchedsession_start_limiton 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 builtdist/under Node) with 7 Discord accounts pointed throughDISCORD_API_URLat 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:connected=falseafter the health monitor restarted them. Control with 3 accounts on main: all recover, as the queue can keep up.connected=true.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.