openclaw - 💡(How to fix) Fix Discord WebSocket heartbeat ACK timeout caused by agent startup blocking Node.js event loop [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#75769Fetched 2026-05-02 05:30:29
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Timeline (top)
closed ×1commented ×1

Error Message

  1. [discord] gateway error: Error: Gateway heartbeat ACK timeout

Root Cause

The Discord WebSocket heartbeat handler runs on the same Node.js event loop as agent startup. When core-plugin-tools and system-prompt phases block the loop for 9–12s each, the heartbeat timer cannot fire, causing Discord to close the WebSocket.

Fix Action

Fix / Workaround

Attempted Mitigations

Code Example

core-plugin-tools: ~9200ms
system-prompt: ~8500ms
stream-setup: ~8300ms
session-resource-loader: ~4400ms
bundle-tools: ~1800ms
Total prep: ~33000ms

---

liveness warning: reasons=event_loop_delay eventLoopDelayMaxMs=10000–13000ms eventLoopUtilization=0.99
RAW_BUFFERClick to expand / collapse

Problem

When a Discord message triggers an agent run, the startup phases block the Node.js event loop for ~33–47 seconds. Since Discord requires WebSocket heartbeats every ~41.25s, the heartbeat ACK times out during startup, dropping the Discord connection. The reply is then lost with AbortError: This operation was aborted.

Environment

  • OpenClaw version: 2026.4.29
  • Channel: Discord
  • Agent model: anthropic/claude-haiku-4-5
  • Server: OCI ARM64, 4 vCPU, 6GB RAM

Observed Behavior

Every Discord message that triggers a cold or warm run consistently causes:

  1. startup stages: totalMs=~14000ms
  2. prep stages: totalMs=~33000ms (total: ~47s)
  3. [discord] gateway error: Error: Gateway heartbeat ACK timeout
  4. discord final reply failed: AbortError: This operation was aborted

Prep stage breakdown (per run, consistent):

core-plugin-tools: ~9200ms
system-prompt: ~8500ms
stream-setup: ~8300ms
session-resource-loader: ~4400ms
bundle-tools: ~1800ms
Total prep: ~33000ms

Event loop saturation during startup:

liveness warning: reasons=event_loop_delay eventLoopDelayMaxMs=10000–13000ms eventLoopUtilization=0.99

Attempted Mitigations

  • Disabled 56 of 72 enabled plugins → core-plugin-tools 14s → 9s (still too slow)
  • Reduced session-memory from 30 to 10 messages
  • Reduced workspace context files
  • Set contextInjection: continuation-skip for agent
  • Network latency to Anthropic: 127ms — not a network problem

Root Cause

The Discord WebSocket heartbeat handler runs on the same Node.js event loop as agent startup. When core-plugin-tools and system-prompt phases block the loop for 9–12s each, the heartbeat timer cannot fire, causing Discord to close the WebSocket.

Expected Behavior / Suggested Fixes

  • Move Discord WebSocket heartbeat to a Worker Thread
  • Lazy-load / cache plugin tool schemas across runs
  • Reduce core-plugin-tools load time for warm runs

Impact

Discord is essentially unusable — every message response risks dropping the connection and losing the reply silently.

extent analysis

TL;DR

Move the Discord WebSocket heartbeat to a Worker Thread to prevent event loop blocking and timeouts.

Guidance

  • Identify the critical startup phases (core-plugin-tools and system-prompt) that block the event loop and explore optimization opportunities.
  • Consider lazy-loading or caching plugin tool schemas to reduce load times for warm runs.
  • Verify the event loop utilization and heartbeat timer functionality after implementing the suggested fixes.

Example

// Pseudo-code example of moving Discord WebSocket heartbeat to a Worker Thread
const { Worker } = require('worker_threads');

const heartbeatWorker = new Worker('./heartbeat.js');
heartbeatWorker.on('message', (event) => {
  // Handle heartbeat events
});

Notes

The provided breakdown of prep stages and event loop saturation suggests that optimizing core-plugin-tools and system-prompt phases will have the most significant impact on reducing startup times.

Recommendation

Apply the workaround of moving the Discord WebSocket heartbeat to a Worker Thread, as this directly addresses the root cause of the issue and prevents event loop blocking.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Discord WebSocket heartbeat ACK timeout caused by agent startup blocking Node.js event loop [1 comments, 2 participants]