sipeed/picoclaw · error

failed to start stream client: %w

Error message

failed to start stream client: %w

What it means

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.

Source

Thrown at pkg/channels/dingtalk/dingtalk.go:85

	logger.InfoC("dingtalk", "Starting DingTalk channel (Stream Mode)...")

	c.ctx, c.cancel = context.WithCancel(ctx)

	// Create credential config
	cred := client.NewAppCredentialConfig(c.clientID, c.clientSecret)

	// Create the stream client with options
	c.streamClient = client.NewStreamClient(
		client.WithAppCredential(cred),
		client.WithAutoReconnect(true),
	)

	// Register chatbot callback handler (IChatBotMessageHandler is a function type)
	c.streamClient.RegisterChatBotCallbackRouter(c.onChatBotMessageReceived)

	// Start the stream client
	if err := c.streamClient.Start(c.ctx); err != nil {
		return fmt.Errorf("failed to start stream client: %w", err)
	}

	c.SetRunning(true)
	logger.InfoC("dingtalk", "DingTalk channel started (Stream Mode)")
	return nil
}

// Stop gracefully stops the DingTalk channel
func (c *DingTalkChannel) Stop(ctx context.Context) error {
	logger.InfoC("dingtalk", "Stopping DingTalk channel...")

	if c.cancel != nil {
		c.cancel()
	}

	if c.streamClient != nil {
		c.streamClient.Close()
	}

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Re-verify the client_id/client_secret pair against the robot's credentials on DingTalk Open Platform and that the robot is published/enabled
  2. Test connectivity from the host: curl https://api.dingtalk.com (and check wss egress)
  3. Read the dingtalk SDK logger output (routed to the 'dingtalk' logger) for the exact handshake/auth failure
  4. Restart the process after fixing config; retry Start on transient network errors
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight connectivity + credential check before Start
req, _ := http.NewRequest(http.MethodGet, "https://oapi.dingtalk.com/gettoken?appkey="+clientID+"&appsecret="+clientSecret, nil)
resp, err := http.DefaultClient.Do(req)
if err != nil || resp.StatusCode != 200 {
    return fmt.Errorf("dingtalk unreachable or bad credentials: %v", err)
}

Try / catch

if err := ch.Start(ctx); err != nil {
    if strings.Contains(err.Error(), "failed to start stream client") {
        // inspect wrapped cause: auth vs network; fix credentials or egress before retrying
        log.Printf("dingtalk start failed: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/96b14fd3dd781d80. Report an issue: GitHub.