Repository navigation
Description
Summary
When a Feishu/WebSocket connection is closed before the handshake completes, Node.js emits an uncaughtException with the message "WebSocket was closed before the connection was established". This error is not classified as benign by isBenignUncaughtExceptionError() in unhandled-rejections--*.js, causing the gateway process to crash.
Current Behavior (v2026.5.28)
The benign error handler in dist/unhandled-rejections--*.js covers:
- Network errors:
ECONNREFUSED,EHOSTUNREACH,ENETUNREACH,EAI_AGAIN,ENOTFOUND,ETIMEDOUT,UND_ERR_CONNECT_TIMEOUT,UND_ERR_DNS_RESOLVE_FAILED,UND_ERR_CONNECT - I/O errors:
EPIPE,EIO
But it does not cover WebSocket close messages, which are a common transient failure during Feishu gateway reconnection.
The uncaughtException handler in dist/index.js (line ~42) and dist/cli/run-main.js (line ~416) calls isBenignUncaughtExceptionError() which returns false for WebSocket close errors, leading to process.exit(1).
Suggested Fix
Option A (preferred): Add WebSocket close messages to the benign error classification in unhandled-rejections--*.js:
// In isBenignUncaughtExceptionError():
const msg = typeof error === 'string' ? error : (error?.message || '');
if (msg.includes("WebSocket was closed before the connection was established")) {
return true;
}Option B: Add a dedicated guard in the uncaughtException handler in index.js and cli/run-main.js, between the benign check and the fatal log:
const msg = formatUncaughtError(error);
if (typeof msg === "string" && msg.includes("WebSocket was closed before the connection was established")) {
console.warn("[openclaw] Ignored recoverable uncaught exception:", msg);
return;
}Environment
- OpenClaw version: 2026.5.28 (67ddc1a)
- Files:
dist/index.js,dist/cli/run-main.js,dist/unhandled-rejections--*.js - Node.js: v22+
- Related: The upstream
isBenignUncaughtExceptionErrorwas added in 2026.4.29 but doesn't cover this case
Impact
Gateway process crash, requiring automatic restart via LaunchAgent. During network instability, this can cause a crash loop, degrading all channel availability.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon May 30, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 30, 2026, 2:24 AM ET / 06:24 UTC.
Summary
Keep open: current
origin/mainand the latest release still miss the exactwspre-handshake close message in the benign uncaught-exception classifier, while the global handlers exit on non-benign uncaught exceptions. This is a narrow gateway/channel availability bug with no canonical duplicate found.Reproducibility: Source-level reproduction is clear for the classifier gap:
isBenignUncaughtExceptionError(new Error("WebSocket was closed before the connection was established"))follows the false path on currentorigin/main. I did not run a live Feishu gateway crash reproduction.Ways to help us reproduce this
Next step
This is a narrow source-proven availability fix in the shared uncaught-exception classifier with clear tests and no config or product decision needed.
Review details
Best possible solution:
Add a narrow central benign-classifier case for the exact
wspre-handshake close error with focused regression coverage, then verify the Feishu/gateway path no longer exits the process.Do we have a high-confidence way to reproduce the issue?
Source-level reproduction is clear for the classifier gap:
isBenignUncaughtExceptionError(new Error("WebSocket was closed before the connection was established"))follows the false path on currentorigin/main. I did not run a live Feishu gateway crash reproduction.Is this the best way to solve the issue?
Yes: the maintainable fix is to centralize the exact
wstransient close classification insrc/infra/unhandled-rejections.tswith tests, rather than duplicating guards insrc/index.tsandsrc/cli/run-main.ts.AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 94df665cdcc9.
Label changes
Label changes:
P1: A transient channel WebSocket reconnect can take down the gateway process and degrade channel availability for real users.impact:crash-loop: The issue is specifically about an uncaught exception causing gateway exits and possible supervised restart loops.issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.clawsweeper:needs-live-repro: Current issue advisory state selects this label.clawsweeper:queueable-fix: Current issue advisory state selects this label.clawsweeper:fix-shape-clear: Current issue advisory state selects this label.Label justifications:
P1: A transient channel WebSocket reconnect can take down the gateway process and degrade channel availability for real users.impact:crash-loop: The issue is specifically about an uncaught exception causing gateway exits and possible supervised restart loops.Evidence reviewed
Acceptance criteria:
What I checked:
origin/main,isBenignUncaughtExceptionErroronly treats configured network codes/message-code regexes plusEPIPE/EIOas benign; the exactwsclose-before-open message is not matched. (src/infra/unhandled-rejections.ts:94, 94df665cdcc9)isBenignUncaughtExceptionError; otherwise they format a fatal error and callprocess.exit(1). (src/index.ts:97, 94df665cdcc9)ws@8.21.0constructsWebSocket was closed before the connection was establishedwhenclose()orterminate()is called while the socket is stillCONNECTING, then schedules error emission throughabortHandshake. (websockets/ws@8.21.0/lib/websocket.js:305)ws@8.21.0, starts aWSClient, and cleanup callswsClient.close(), making the reported close-before-established path relevant to the channel. (extensions/feishu/src/monitor.transport.ts:164, 94df665cdcc9)wsclose-before-open message. (src/infra/unhandled-rejections.test.ts:405, 94df665cdcc9)v2026.5.27points at27ae826f65256c7fbd1d78475fca87b674a53e7band contains the same classifier shape and Feishuws@8.21.0, so there is no shipped fix to close against. (src/infra/unhandled-rejections.ts:94, 27ae826f6525)Likely related people:
723b5085d935296575fa7eba8cd99aad7fc86c77. (role: introduced current behavior and recent area contributor; confidence: high; commits: 723b5085d935; files:src/infra/unhandled-rejections.ts,src/infra/unhandled-rejections.test.ts,extensions/feishu/src/monitor.transport.ts)@m1heng, which is relevant because the report names Feishu WebSocket reconnect behavior. (role: Feishu plugin owner signal; confidence: medium; files:extensions/feishu/package.json)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.fix: classify ws pre-handshake close as benign
steipete commentedon May 30, 2026
Fixed on
mainby PR #88298, merged asf327073fb3f2004472daecfdcc4d0e5efe848838.Proof:
PR CI proof on head
58af55a5474e33a9662041da7d4591b60ad62f60:The fix keeps the central uncaught-exception classifier narrow: the exact upstream
wspre-handshake close error is benign, while broader prefixed WebSocket errors remain fatal.fix: classify ws pre-handshake close as benign
fix: classify ws pre-handshake close as benign
fix: classify ws pre-handshake close as benign