slopus/happy · error
Not connected to gateway
Error message
Not connected to gateway
What it means
OpenClawSocket.request() sends a JSON-RPC-style request frame over the gateway WebSocket. It validates that the WebSocket exists and status === 'connected' before generating a request ID; otherwise the request could never receive a response. Called by sendMessage and abortRun, so both fail with this error when the transport is down.
Source
Thrown at packages/happy-cli/src/openclaw/OpenClawSocket.ts:154
this.pairingRequestId = null;
this.doConnect();
}
}
onStatusChange(handler: OpenClawStatusHandler): () => void {
this.statusListeners.add(handler);
handler(this.status, undefined, { pairingRequestId: this.pairingRequestId ?? undefined });
return () => this.statusListeners.delete(handler);
}
onEvent(handler: OpenClawEventHandler): () => void {
this.eventListeners.add(handler);
return () => this.eventListeners.delete(handler);
}
async request<T = unknown>(method: string, params?: unknown, timeoutMs = 15000): Promise<T> {
if (!this.ws || this.status !== 'connected') {
throw new Error('Not connected to gateway');
}
const id = randomUUID();
const frame = { type: 'req', id, method, params };
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
this.pending.delete(id);
reject(new Error(`Request timeout: ${method}`));
}, timeoutMs);
this.pending.set(id, {
resolve: (value) => {
clearTimeout(timeout);
resolve(value as T);
},
reject: (error) => {
clearTimeout(timeout);View on GitHub (pinned to b824cd0a46)
Solutions
- Wait for the socket's connected event/status before issuing requests
- Reconnect the socket and retry the request once connection is re-established
- Check gateway availability and logs; the request timeout (15s default) may indicate the connection died earlier
Example fix
// before
await socket.sendMessage(msg);
// after
if (socket.status !== 'connected') {
await socket.connect(gatewayConfig);
}
await socket.sendMessage(msg); Defensive patterns
Strategy: validation
Validate before calling
if (!socket.isConnected()) {
await socket.connect(gatewayConfig);
} Type guard
const canRequest = (s: OpenClawSocket): boolean => s.ws !== null && s.status === 'connected';
Try / catch
try {
return await socket.request<T>(method, params);
} catch (err) {
if (err.message === 'Not connected to gateway') {
await socket.connect(gatewayConfig);
return await socket.request<T>(method, params);
}
throw err;
} Prevention
- Await the socket 'connected' status before issuing any request
- Add a reconnect-with-backoff wrapper around request/sendMessage/abortRun
- Treat the 15s request timeout as a signal the connection may have died
When it happens
Trigger: Calling request() (directly or via sendMessage/abortRun) when this.ws is null/undefined or this.status !== 'connected' — before connection completes, after a disconnect, or during a reconnect window.
Common situations: Aborting a run after the gateway connection dropped; sending a message concurrently with a reconnect; timeout of the initial connect causing later calls to run against a closed socket.
Related errors
- Not connected to OpenClaw gateway
- RPC target disconnected
- The chosen rewind point is no longer present in the source C
- Resume session handler not available
- Unsupported Claude goal action
AI-assisted analysis of slopus/happy@b824cd0a46 (2026-08-31).
Data as JSON: /api/errors/34473b3ec6597ae0.
Report an issue: GitHub.