11// Gateway WebSocket connection handler owns pre-auth limits, handshake auth, presence, and message-handler attachment.
22import { randomUUID } from "node:crypto" ;
33import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce" ;
4- import { WebSocket , type RawData , type WebSocketServer } from "ws" ;
4+ import type { RawData , WebSocket , WebSocketServer } from "ws" ;
55import { WORKER_PROTOCOL_MAX_PAYLOAD_BYTES } from "../../../packages/gateway-protocol/src/index.js" ;
66import { GATEWAY_STARTUP_PENDING_CLOSE_CAUSE } from "../../../packages/gateway-protocol/src/startup-unavailable.js" ;
77import { getRuntimeConfig } from "../../config/io.js" ;
@@ -25,6 +25,7 @@ import {
2525 MAX_BUFFERED_BYTES ,
2626 MAX_PAYLOAD_BYTES ,
2727 MAX_PREAUTH_PAYLOAD_BYTES ,
28+ WEBSOCKET_OPEN_READY_STATE ,
2829} from "../server-constants.js" ;
2930import type { GatewayRequestContext , GatewayRequestHandlers } from "../server-methods/types.js" ;
3031import { formatError } from "../server-utils.js" ;
@@ -349,7 +350,7 @@ export function attachGatewayWsConnectionHandler(params: AttachGatewayWsConnecti
349350 if ( closed ) {
350351 return { kind : "unavailable" } as const ;
351352 }
352- if ( socket . readyState !== WebSocket . OPEN ) {
353+ if ( socket . readyState !== WEBSOCKET_OPEN_READY_STATE ) {
353354 // Keep pending node results revocable until their close handler drains admitted work.
354355 if ( client ?. connect . role === "node" && nodeLifecycleDispatch . hasActive ( ) ) {
355356 retainClientUntilNodeDrain = true ;
0 commit comments