{"record":{"id":"3557298f979cf12b","repo":"chenhg5/cc-connect","slug":"wecom-ws-not-connected","errorCode":null,"errorMessage":"wecom-ws: not connected","messagePattern":"wecom-ws: not connected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/websocket.go","lineNumber":567,"sourceCode":"func (p *WSPlatform) Stop() error {\n\tif p.cancel != nil {\n\t\tp.cancel()\n\t}\n\tp.mu.Lock()\n\tconn := p.conn\n\tp.mu.Unlock()\n\tif conn != nil {\n\t\treturn conn.Close()\n\t}\n\treturn nil\n}\n\n// writeJSON sends a JSON message over the WebSocket connection with mutex protection.\nfunc (p *WSPlatform) writeJSON(v any) error {\n\tp.mu.Lock()\n\tdefer p.mu.Unlock()\n\tif p.conn == nil {\n\t\treturn fmt.Errorf(\"wecom-ws: not connected\")\n\t}\n\treturn p.conn.WriteJSON(v)\n}\n\n// writeAndWaitAck sends a frame and waits for the server ack before returning.\n// Falls back to non-blocking on timeout to avoid deadlocks.\nfunc (p *WSPlatform) writeAndWaitAck(ctx context.Context, frame map[string]any, reqID string) error {\n\treturn p.writeAndWaitAckWithTimeout(ctx, frame, reqID, wsAckTimeout)\n}\n\nfunc (p *WSPlatform) writeAndWaitAckWithTimeout(ctx context.Context, frame map[string]any, reqID string, timeout time.Duration) error {\n\tresult, err := p.writeAndWaitResult(ctx, frame, reqID, timeout)\n\tif errors.Is(err, errWSAckTimeout) {\n\t\tslog.Debug(\"wecom-ws: ack timeout, proceeding\", \"req_id\", reqID)\n\t\treturn nil\n\t}\n\tif err != nil {\n\t\treturn err","sourceCodeStart":549,"sourceCodeEnd":585,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/websocket.go#L549-L585","documentation":"Guard in writeJSON: the WebSocket connection field p.conn is nil while a frame is being sent, meaning the WeCom AI-Bot socket is not currently established — either the initial handshake has not completed yet, a reconnect is in progress, or Stop() has torn the connection down. It is a state guard, not a network failure: the write never reached the wire.","triggerScenarios":"Thrown at platform/wecom/websocket.go:567 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Have callers (Reply, heartbeat, writeAndWaitResult) wait for the connection-ready signal from runConnection before sending","Buffer or re-queue outgoing frames so they flush after reconnection instead of being dropped","Ensure Stop() drains pending sends before nil-ing conn","Surface the error so the engine can retry the message once the socket is back"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}