sipeed/picoclaw · error

mqtt subscribe failed

Error message

mqtt subscribe failed: %w

What it means

Wraps the error from the first subscribe call (inbound topic) in MQTTChannel.Start; the connection succeeded but subscribing to the agent's inbound topic failed (permissions, QoS, or malformed topic).

Solutions

  1. Check broker ACLs allow subscribing to the agent's topic
  2. Verify the topic prefix/agent_id produce a valid topic string
  3. Reconnect and resubscribe after fixing permissions
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at pkg/channels/mqtt/mqtt.go:116 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at pkg/channels/mqtt/mqtt.go:116

	opts.SetConnectionLostHandler(func(_ pahomqtt.Client, err error) {
		logger.WarnCF("mqtt", "MQTT connection lost", map[string]any{"error": err.Error()})
	})

	client := pahomqtt.NewClient(opts)
	token := client.Connect()
	if !token.WaitTimeout(10 * time.Second) {
		client.Disconnect(250)
		return fmt.Errorf("mqtt connect timed out after 10s (broker: %s)", c.cfg.Broker)
	}
	if err := token.Error(); err != nil {
		client.Disconnect(250)
		return fmt.Errorf("mqtt connect failed: %w", err)
	}

	if err := <-firstSubscribe; err != nil {
		client.Disconnect(250)
		return fmt.Errorf("mqtt subscribe failed: %w", err)
	}

	c.client = client
	c.SetRunning(true)

	logger.InfoCF("mqtt", "MQTT channel started", map[string]any{
		"broker":   c.cfg.Broker,
		"agent_id": c.cfg.AgentID,
	})
	return nil
}

// topicPrefix returns the configured topic prefix, normalizing slashes.
// Trailing slashes are stripped; the result may or may not have a leading slash
// depending on what the user configured.
func (c *MQTTChannel) topicPrefix() string {
	p := strings.TrimRight(c.cfg.TopicPrefix, "/")
	if p == "" {

View on GitHub (pinned to 49183d7e8d)