{"record":{"id":"60a6045e92b5b1ad","repo":"chenhg5/cc-connect","slug":"wps-agentspace-not-connected","errorCode":null,"errorMessage":"wps-agentspace: not connected","messagePattern":"wps-agentspace: not connected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wps-agentspace/wpsagentspace.go","lineNumber":614,"sourceCode":"\t// Dispatch to handler\n\tif p.handler != nil {\n\t\tmsg := &core.Message{\n\t\t\tSessionKey: sessionKey,\n\t\t\tPlatform:   \"wps-agentspace\",\n\t\t\tContent:    content,\n\t\t\tReplyCtx:   rc,\n\t\t\tUserID:     chatID,\n\t\t}\n\t\tgo p.handler(p, msg)\n\t}\n\n\treturn nil\n}\n\n// sendText sends a text message to a chat.\nfunc (p *Platform) sendText(chatID, content string, rc *replyContext) error {\n\tif p.conn == nil {\n\t\treturn fmt.Errorf(\"wps-agentspace: not connected\")\n\t}\n\n\tmsg := messageData{\n\t\tRole:       \"assistant\",\n\t\tType:       \"answer\",\n\t\tContent:    content,\n\t\tSessionID:  rc.SessionID,\n\t\tChatID:     chatID,\n\t\tMessageID:  rc.MessageID,\n\t\tTimestamp:  time.Now().UnixMilli(),\n\t\tDeviceUUID: p.deviceUuid,\n\t\tDeviceName: p.deviceName,\n\t}\n\n\treturn p.writeJSON(\"message\", msg)\n}\n\n// sendTyping sends a typing indicator.","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wps-agentspace/wpsagentspace.go#L596-L632","documentation":"sendText returns the sentinel error \"wps-agentspace: not connected\" when p.conn is nil, i.e. the platform has no active WebSocket session. This happens whenever a reply/send is attempted outside the window between a successful init and the deferred conn cleanup in connect (wpsagentspace.go:379-386). It is a state error telling the caller the message could not be delivered and should be retried after reconnection.","triggerScenarios":"Engine replies to a user message while connectLoop is between attempts (socket dropped, backoff pending); Stop() was called and closed the connection; sendText races with the deferred cleanup that nils p.conn; the platform never connected because earlier dial/init errors kept failing.","commonSituations":"Agent finishes a long-running task just as the AgentSpace WebSocket drops, so the reply finds no socket; cc-connect was stopped/restarted while a pipeline was mid-reply; server outage means no connection is ever established, so every send fails with this error.","solutions":["Ensure the write path goes through p.sendCh / writeLoop so sends are queued and flushed on reconnect instead of requiring a live conn, or retry after connectLoop re-establishes the session","Check connectLoop logs for why the connection is down (dial/init/read errors upstream) and fix that root cause","If this happens at shutdown, treat it as expected: messages cannot be delivered after Stop()","Verify network connectivity to agentspace.wps.cn and valid credentials so a connection can be maintained"],"exampleFix":"// before\nfunc (p *Platform) sendText(chatID, content string, rc *replyContext) error {\n\tif p.conn == nil {\n\t\treturn fmt.Errorf(\"wps-agentspace: not connected\")\n\t}\n\t...\n}\n// after — snapshot conn under lock to avoid racing the cleanup in connect\nfunc (p *Platform) sendText(chatID, content string, rc *replyContext) error {\n\tp.mu.Lock()\n\tconn := p.conn\n\tp.mu.Unlock()\n\tif conn == nil {\n\t\treturn fmt.Errorf(\"wps-agentspace: not connected\")\n\t}\n\t...\n}","handlingStrategy":"retry","validationCode":"// caller-side pre-check\np.mu.Lock()\nconnected := p.conn != nil\np.mu.Unlock()\nif !connected { /* queue message or wait for reconnect before replying */ }","typeGuard":null,"tryCatchPattern":"if err := platform.Send(msg); err != nil {\n\tif strings.Contains(err.Error(), \"not connected\") {\n\t\t// transient: re-enqueue and deliver after reconnect\n\t}\n}","preventionTips":["Route all sends through the writeLoop queue rather than writing directly to p.conn","Check connection health before long-running agent tasks that end in a reply","Add retry-with-backoff around Send for transient disconnects","Monitor connectLoop status; alert if the platform stays disconnected"],"tags":["websocket","state","connection"],"backgroundTag":"not-connected","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}