Skip to content

fix(discord): reconnect every account after a network outage - #201415

Merged
obviyus merged 3 commits into
mainfrom
fix/discord-identify-window-162189
Nov 18, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/discord-identify-window-162189

Conversation

@obviyus

@obviyus obviyus commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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.

- 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
@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: S labels Nov 18, 2026
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Three accounts recover while four repeatedly time out without sending IDENTIFY.
  • After: All seven accounts identify five seconds apart and report connected within about 30 seconds.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with production-entry-point recovery traces, a reported red/green regression, and preserved stale-socket protection.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Real Gateway source and built-Node runs use the production Discord transport against an outage-injecting REST/WebSocket stand-in, recording IDENTIFY spacing and all seven accounts connected; the final head changes only a comment after the rerun, and live Discord message delivery was not exercised.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Some Discord accounts stop receiving messages after a network outage and recover only after restarting the Gateway.
Reason: The maintainer-authored direction restores automatic recovery with a narrow private implementation change and no new configuration or public contract.

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
Reviewed head: 91c31962a577d3bd55c87061d56fe1a95dba4377

Before merge

None.

Findings

None.

Agent review details

How this fits together

Discord’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]
Loading

Technical review

Best 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

  • Shared IDENTIFY reservation accounting changes intended behavior with a stated reason (f0adbd4: The available history carries this pacing mechanism through Discord client internalization and later private simplifications; it does not establish why abandoned waits should retain reservations.)
  • HELLO socket identity and delayed identification keeps the original intent (fix(discord): bind delayed identify to socket generation #82225: Prevent delayed identification from using a replacement socket before that socket receives its own HELLO.)
  • Limiter clock behavior keeps the original intent (c767b37: Bound IDENTIFY delays when the wall clock moves backward; monotonic scheduling preserves that intent without wall-clock dependence.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Gio Della-Libera: Raw commit 37cd829 adds extensions/discord/src/internal/gateway.test.ts:218 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 37cd82913fa3; files: extensions/discord/src/internal/gateway.test.ts)

PR surface

Source +7, Tests +1. Total +8 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 35 28 +7
Tests 1 5 4 +1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 40 32 +8

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Multiple Discord accounts can remain disconnected indefinitely after network recovery, interrupting an established channel workflow.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-18T19:48:49.222Z sha db4528e :: needs maintainer review before merge. :: none
  • reviewed 2026-11-18T20:01:55.906Z sha 93ca882 :: needs maintainer review before merge. :: none

Reviewed November 18, 2026, 3:13 PM ET / 20:13 UTC (Revision 3).

@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Gateway proof for #162189: real Gateway (ocx src, source tier; one more branch run on the built dist/ under Node), 7 Discord accounts pointed with DISCORD_API_URL at a local Discord REST + Gateway stand-in that drops every Gateway WebSocket for 100 s while the accounts start, then accepts them. The stand-in logs each IDENTIFY it receives. Main = merge base 3bc20e2, branch = db4528e. Tokens are fake.

label=base1 head=3bc20e28b022 (merge base) accounts=7 outage=100s after=300s
network restored at 2026-11-18T19:27:40.220Z; log ends 2026-11-18T19:32:40.313Z
--- IDENTIFY received by the Discord stand-in, per bot account
a1 identify=1 first=2026-11-18T19:27:40.227Z
a2 identify=0 first=-
a3 identify=1 first=2026-11-18T19:27:55.226Z
a4 identify=1 first=2026-11-18T19:27:45.228Z
a5 identify=0 first=-
a6 identify=0 first=-
a7 identify=0 first=-
--- gateway READY-wait timeouts after the network returned
count=63
2026-11-18T19:31:48.041Z discord: gateway READY wait timed out after 15000ms (attempt 20)
2026-11-18T19:32:15.361Z discord: gateway READY wait timed out after 15000ms (attempt 1)
2026-11-18T19:32:32.463Z discord: gateway READY wait timed out after 15000ms (attempt 2)
--- channels status (discord accounts)

label=base2 head=3bc20e28b022 (merge base) accounts=7 outage=100s after=300s
network restored at 2026-11-18T19:36:50.630Z; log ends 2026-11-18T19:41:53.496Z
--- IDENTIFY received by the Discord stand-in, per bot account
a1 identify=1 first=2026-11-18T19:37:05.921Z
a2 identify=0 first=-
a3 identify=1 first=2026-11-18T19:37:00.919Z
a4 identify=1 first=2026-11-18T19:36:50.919Z
a5 identify=0 first=-
a6 identify=0 first=-
a7 identify=0 first=-
--- gateway READY-wait timeouts after the network returned
count=62
2026-11-18T19:40:58.612Z discord: gateway READY wait timed out after 15000ms (attempt 20)
2026-11-18T19:41:24.477Z discord: gateway READY wait timed out after 15000ms (attempt 1)
2026-11-18T19:41:41.555Z discord: gateway READY wait timed out after 15000ms (attempt 2)
--- channels status (discord accounts)
a1 running=true connected=true
a2 running=true connected=false
a3 running=true connected=true
a4 running=true connected=true
a5 running=true connected=false
a6 running=true connected=false
a7 running=true connected=false

label=cand1 head=db4528eeb7bf content (uncommitted on 3bc20e28b022 at run time) accounts=7 outage=100s after=300s
network restored at 2026-11-18T19:27:58.448Z; log ends 2026-11-18T19:28:21.796Z
--- IDENTIFY received by the Discord stand-in, per bot account
a1 identify=1 first=2026-11-18T19:28:09.383Z
a2 identify=1 first=2026-11-18T19:28:29.387Z
a3 identify=1 first=2026-11-18T19:28:04.382Z
a4 identify=1 first=2026-11-18T19:28:24.386Z
a5 identify=1 first=2026-11-18T19:28:14.384Z
a6 identify=1 first=2026-11-18T19:27:59.381Z
a7 identify=1 first=2026-11-18T19:28:19.385Z
--- gateway READY-wait timeouts after the network returned
count=5
2026-11-18T19:28:04.717Z discord: gateway READY wait timed out after 15000ms (attempt 6)
2026-11-18T19:28:07.606Z discord: gateway READY wait timed out after 15000ms (attempt 5)
2026-11-18T19:28:21.793Z discord: gateway READY wait timed out after 15000ms (attempt 7)
--- channels status (discord accounts)

label=cand2 head=db4528eeb7bfd3b2790ee625fd8120a216688013 accounts=7 outage=100s after=300s
network restored at 2026-11-18T19:37:20.495Z; log ends 2026-11-18T19:42:23.198Z
--- IDENTIFY received by the Discord stand-in, per bot account
a1 identify=1 first=2026-11-18T19:37:26.274Z
a2 identify=1 first=2026-11-18T19:37:41.278Z
a3 identify=1 first=2026-11-18T19:37:51.282Z
a4 identify=1 first=2026-11-18T19:37:46.279Z
a5 identify=1 first=2026-11-18T19:37:31.276Z
a6 identify=1 first=2026-11-18T19:37:21.273Z
a7 identify=1 first=2026-11-18T19:37:36.276Z
--- gateway READY-wait timeouts after the network returned
count=5
2026-11-18T19:37:26.570Z discord: gateway READY wait timed out after 15000ms (attempt 6)
2026-11-18T19:37:29.474Z discord: gateway READY wait timed out after 15000ms (attempt 5)
2026-11-18T19:37:36.585Z discord: gateway READY wait timed out after 15000ms (attempt 6)
--- channels status (discord accounts)
a1 running=true connected=true
a2 running=true connected=true
a3 running=true connected=true
a4 running=true connected=true
a5 running=true connected=true
a6 running=true connected=true
a7 running=true connected=true

label=base-control3 head=3bc20e28b022 (merge base) accounts=3 outage=100s after=200s
network restored at 2026-11-18T19:37:30.450Z; log ends 2026-11-18T19:40:53.235Z
--- IDENTIFY received by the Discord stand-in, per bot account
a1 identify=1 first=2026-11-18T19:37:37.075Z
a2 identify=1 first=2026-11-18T19:37:47.074Z
a3 identify=1 first=2026-11-18T19:37:32.074Z
--- gateway READY-wait timeouts after the network returned
count=2
2026-11-18T19:37:32.066Z discord: gateway READY wait timed out after 15000ms (attempt 5)
2026-11-18T19:37:39.143Z discord: gateway READY wait timed out after 15000ms (attempt 6)
--- channels status (discord accounts)
a1 running=true connected=true
a2 running=true connected=true
a3 running=true connected=true

label=cand-dist-node head=db4528eeb7bf (built dist, Node 24.22.1) accounts=7 outage=100s after=240s
network restored at 2026-11-18T19:45:27.766Z; log ends 2026-11-18T19:45:42.765Z
--- IDENTIFY received by the Discord stand-in, per bot account
a1 identify=1 first=2026-11-18T19:45:28.062Z
a2 identify=1 first=2026-11-18T19:45:53.066Z
a3 identify=1 first=2026-11-18T19:45:38.063Z
a4 identify=1 first=2026-11-18T19:45:33.062Z
a5 identify=1 first=2026-11-18T19:45:43.064Z
a6 identify=1 first=2026-11-18T19:45:58.066Z
a7 identify=1 first=2026-11-18T19:45:48.064Z
--- gateway READY-wait timeouts after the network returned
count=6
2026-11-18T19:45:35.704Z discord: gateway READY wait timed out after 15000ms (attempt 3)
2026-11-18T19:45:36.961Z discord: gateway READY wait timed out after 15000ms (attempt 6)
2026-11-18T19:45:42.763Z discord: gateway READY wait timed out after 15000ms (attempt 4)
--- channels status (discord accounts)
a1 running=true connected=true
a2 running=true connected=true
a3 running=true connected=true
a4 running=true connected=true
a5 running=true connected=true
a6 running=true connected=true
a7 running=true connected=true

--- main, run 2: the health monitor restarts the stuck accounts with a fresh client; they still send no IDENTIFY
2026-11-19T01:10:59.390+05:30 [health-monitor] [discord:a5] health-monitor: restarting (reason: disconnected)
2026-11-19T01:10:59.610+05:30 [health-monitor] [discord:a6] health-monitor: restarting (reason: disconnected)
2026-11-19T01:10:59.622+05:30 [health-monitor] [discord:a7] health-monitor: restarting (reason: disconnected)
2026-11-19T01:11:09.391+05:30 [discord] [a2] starting provider
2026-11-19T01:11:39.614+05:30 [discord] [a5] starting provider
2026-11-19T01:11:49.622+05:30 [discord] [a6] starting provider

--- focused regression (extensions/discord/src/internal/gateway.test.ts)
main:    Tests 1 failed | 20 passed (21) (does not identify from a stale HELLO or let it delay the replacement socket 6ms)
branch:  Tests 46 passed (46) (gateway, heartbeat and lifecycle tests)

…b target

- The extension declaration build has no Promise.withResolvers; use the executor form main used.
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Nov 18, 2026
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Exact-head rerun on 93ca882 (same harness, ocx src; the only change since db4528e swaps Promise.withResolvers back to the executor form for the extension declaration build):

label=cand3-head head=93ca882f4c2748d93b6a3f3d81cd13c7007c60b7 accounts=7 outage=100s after=240s
network restored at 2026-11-18T19:58:55.352Z; log ends 2026-11-18T20:02:58.716Z
--- IDENTIFY received by the Discord stand-in, per bot account
a1 identify=1 first=2026-11-18T19:59:01.107Z
a2 identify=1 first=2026-11-18T19:59:21.110Z
a3 identify=1 first=2026-11-18T19:59:06.108Z
a4 identify=1 first=2026-11-18T19:58:56.106Z
a5 identify=1 first=2026-11-18T19:59:11.109Z
a6 identify=1 first=2026-11-18T19:59:26.111Z
a7 identify=1 first=2026-11-18T19:59:16.109Z
--- gateway READY-wait timeouts after the network returned
count=5
2026-11-18T19:59:02.962Z discord: gateway READY wait timed out after 15000ms (attempt 3)
2026-11-18T19:59:04.218Z discord: gateway READY wait timed out after 15000ms (attempt 6)
2026-11-18T19:59:10.059Z discord: gateway READY wait timed out after 15000ms (attempt 4)
--- channels status (discord accounts)
a1 running=true connected=true
a2 running=true connected=true
a3 running=true connected=true
a4 running=true connected=true
a5 running=true connected=true
a6 running=true connected=true
a7 running=true connected=true

- The session-identity ratchet matches the phrase used in the previous comment.
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit cf5cf7a into main Nov 18, 2026
97 checks passed
@obviyus
obviyus deleted the fix/discord-identify-window-162189 branch November 18, 2026 20:23
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

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.

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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

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)

1 participant