slopus/happy · error

Not connected to OpenClaw gateway

Error message

Not connected to OpenClaw gateway

What it means

sendPrompt() requires an active WebSocket connection to the OpenClaw gateway before it will forward a prompt. It checks this.socket.isConnected() and throws if the socket has dropped or was never opened. This prevents prompts from being silently lost when the transport is down.

Solutions

  1. Reconnect (restart the backend / call startSession again) before sending the prompt
  2. Check that the openclaw gateway process is still running (`ps aux | grep openclaw`) and restart it
  3. Confirm the gateway URL is reachable (`curl` the OPENCLAW_GATEWAY_URL / --gateway-url endpoint)
  4. Wrap prompt sending with connection-state checking or automatic reconnect logic

Example fix

// before
await backend.sendPrompt(sessionId, prompt);
// after
if (!backend.isConnected()) {
  await backend.start(); // reconnect + startSession
}
await backend.sendPrompt(sessionId, prompt);
Defensive patterns

Strategy: validation

Validate before calling

if (!backend.isConnected()) {
  await backend.start(); // reconnect before sending
}

Try / catch

try {
  await backend.sendPrompt(sessionId, prompt);
} catch (err) {
  if (err.message === 'Not connected to OpenClaw gateway') {
    await reconnectWithBackoff(backend);
    await backend.sendPrompt(sessionId, prompt);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling OpenClawBackend.sendPrompt() when the underlying socket status is anything other than connected — e.g. after the gateway process exited, the WebSocket closed, or startSession() was never successfully completed.

Common situations: Gateway restarted or crashed between session start and prompt send; network interruption closed the WebSocket; calling sendPrompt on a backend that failed to connect; long idle period where the gateway closed the connection.

Related errors


AI-assisted analysis of slopus/happy@b824cd0a46 (2026-08-31). Data as JSON: /api/errors/e0fb9bd03045ea89. Report an issue: GitHub.

Appendix: source

Thrown at packages/happy-cli/src/openclaw/OpenClawBackend.ts:116

      this.connectionReject = reject;
    });

    this.socket.connect(this.gatewayConfig);
    await this.connectionReady;

    this.sessionKey = this.socket.getMainSessionKey();
    if (!this.sessionKey) {
      throw new Error('No main session key from gateway');
    }

    const sessionId = this.sessionKey;
    this.log(`Session started: ${sessionId}`);
    return { sessionId };
  }

  async sendPrompt(sessionId: SessionId, prompt: string): Promise<void> {
    if (!this.socket.isConnected()) {
      throw new Error('Not connected to OpenClaw gateway');
    }

    this.lastDeltaText = null;

    this.turnReady = new Promise<void>((resolve, reject) => {
      this.turnResolve = resolve;
      this.turnReject = reject;
    });

    this.emit({ type: 'status', status: 'running' });

    const result = await this.socket.sendMessage(sessionId, prompt);
    this.log(`Sent prompt, runId: ${result.runId}`);
  }

  async cancel(_sessionId: SessionId): Promise<void> {
    if (this.sessionKey) {
      await this.socket.abortRun(this.sessionKey);

View on GitHub (pinned to b824cd0a46)