{"record":{"id":"e0fb9bd03045ea89","repo":"slopus/happy","slug":"not-connected-to-openclaw-gateway","errorCode":null,"errorMessage":"Not connected to OpenClaw gateway","messagePattern":"Not connected to OpenClaw gateway","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/happy-cli/src/openclaw/OpenClawBackend.ts","lineNumber":116,"sourceCode":"      this.connectionReject = reject;\n    });\n\n    this.socket.connect(this.gatewayConfig);\n    await this.connectionReady;\n\n    this.sessionKey = this.socket.getMainSessionKey();\n    if (!this.sessionKey) {\n      throw new Error('No main session key from gateway');\n    }\n\n    const sessionId = this.sessionKey;\n    this.log(`Session started: ${sessionId}`);\n    return { sessionId };\n  }\n\n  async sendPrompt(sessionId: SessionId, prompt: string): Promise<void> {\n    if (!this.socket.isConnected()) {\n      throw new Error('Not connected to OpenClaw gateway');\n    }\n\n    this.lastDeltaText = null;\n\n    this.turnReady = new Promise<void>((resolve, reject) => {\n      this.turnResolve = resolve;\n      this.turnReject = reject;\n    });\n\n    this.emit({ type: 'status', status: 'running' });\n\n    const result = await this.socket.sendMessage(sessionId, prompt);\n    this.log(`Sent prompt, runId: ${result.runId}`);\n  }\n\n  async cancel(_sessionId: SessionId): Promise<void> {\n    if (this.sessionKey) {\n      await this.socket.abortRun(this.sessionKey);","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/openclaw/OpenClawBackend.ts#L98-L134","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reconnect (restart the backend / call startSession again) before sending the prompt","Check that the openclaw gateway process is still running (`ps aux | grep openclaw`) and restart it","Confirm the gateway URL is reachable (`curl` the OPENCLAW_GATEWAY_URL / --gateway-url endpoint)","Wrap prompt sending with connection-state checking or automatic reconnect logic"],"exampleFix":"// before\nawait backend.sendPrompt(sessionId, prompt);\n// after\nif (!backend.isConnected()) {\n  await backend.start(); // reconnect + startSession\n}\nawait backend.sendPrompt(sessionId, prompt);","handlingStrategy":"validation","validationCode":"if (!backend.isConnected()) {\n  await backend.start(); // reconnect before sending\n}","typeGuard":null,"tryCatchPattern":"try {\n  await backend.sendPrompt(sessionId, prompt);\n} catch (err) {\n  if (err.message === 'Not connected to OpenClaw gateway') {\n    await reconnectWithBackoff(backend);\n    await backend.sendPrompt(sessionId, prompt);\n  } else throw err;\n}","preventionTips":["Monitor socket disconnect events and auto-reconnect","Send a heartbeat/keepalive to detect dead gateway connections early","Check gateway process health before long-running prompt loops"],"tags":["openclaw","gateway","connection","websocket"],"backgroundTag":"not-connected","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}