{"record":{"id":"96b14fd3dd781d80","repo":"sipeed/picoclaw","slug":"failed-to-start-stream-client-w","errorCode":null,"errorMessage":"failed to start stream client: %w","messagePattern":"failed to start stream client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/channels/dingtalk/dingtalk.go","lineNumber":85,"sourceCode":"\tlogger.InfoC(\"dingtalk\", \"Starting DingTalk channel (Stream Mode)...\")\n\n\tc.ctx, c.cancel = context.WithCancel(ctx)\n\n\t// Create credential config\n\tcred := client.NewAppCredentialConfig(c.clientID, c.clientSecret)\n\n\t// Create the stream client with options\n\tc.streamClient = client.NewStreamClient(\n\t\tclient.WithAppCredential(cred),\n\t\tclient.WithAutoReconnect(true),\n\t)\n\n\t// Register chatbot callback handler (IChatBotMessageHandler is a function type)\n\tc.streamClient.RegisterChatBotCallbackRouter(c.onChatBotMessageReceived)\n\n\t// Start the stream client\n\tif err := c.streamClient.Start(c.ctx); err != nil {\n\t\treturn fmt.Errorf(\"failed to start stream client: %w\", err)\n\t}\n\n\tc.SetRunning(true)\n\tlogger.InfoC(\"dingtalk\", \"DingTalk channel started (Stream Mode)\")\n\treturn nil\n}\n\n// Stop gracefully stops the DingTalk channel\nfunc (c *DingTalkChannel) Stop(ctx context.Context) error {\n\tlogger.InfoC(\"dingtalk\", \"Stopping DingTalk channel...\")\n\n\tif c.cancel != nil {\n\t\tc.cancel()\n\t}\n\n\tif c.streamClient != nil {\n\t\tc.streamClient.Close()\n\t}","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/channels/dingtalk/dingtalk.go#L67-L103","documentation":"The DingTalk Stream SDK's Start() failed while establishing the WebSocket long connection to DingTalk's open platform (built with WithAppCredential + WithAutoReconnect and a chatbot callback router registered). The underlying SDK error is wrapped with %w, so the auth or network cause is visible in the chain.","triggerScenarios":"Start(ctx) on the DingTalkChannel when: client_id/client_secret are wrong (gateway auth fails), the machine cannot reach the DingTalk stream endpoints, a corporate firewall/proxy blocks wss, or the robot is not published/enabled on the platform.","commonSituations":"Credentials copied from the wrong DingTalk app type (enterprise app vs robot), robot still in draft/not released, server in a region without egress to api.dingtalk.com, DingTalk platform outage, config edited but process not restarted.","solutions":["Re-verify the client_id/client_secret pair against the robot's credentials on DingTalk Open Platform and that the robot is published/enabled","Test connectivity from the host: curl https://api.dingtalk.com (and check wss egress)","Read the dingtalk SDK logger output (routed to the 'dingtalk' logger) for the exact handshake/auth failure","Restart the process after fixing config; retry Start on transient network errors"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-flight connectivity + credential check before Start\nreq, _ := http.NewRequest(http.MethodGet, \"https://oapi.dingtalk.com/gettoken?appkey=\"+clientID+\"&appsecret=\"+clientSecret, nil)\nresp, err := http.DefaultClient.Do(req)\nif err != nil || resp.StatusCode != 200 {\n    return fmt.Errorf(\"dingtalk unreachable or bad credentials: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := ch.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to start stream client\") {\n        // inspect wrapped cause: auth vs network; fix credentials or egress before retrying\n        log.Printf(\"dingtalk start failed: %v\", err)\n    }\n    return err\n}","preventionTips":["Verify the robot is created, published, and enabled on DingTalk Open Platform before deploying","Confirm egress to DingTalk stream endpoints (wss) from the deployment network","Smoke-test the appKey/appSecret pair with gettoken before first Start","Restart the channel (not just retry Start on the same client) after credential fixes"],"tags":["dingtalk","websocket","startup","authentication","network"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}