sipeed/picoclaw · error

mqtt: publish failed

Error message

mqtt: publish failed: %w

What it means

Fired in MQTTChannel.Send when the Publish token for the response topic reports an error after Wait(). Means the broker rejected or failed the outbound publish (connection dropped, QoS issue, or permissions), so the message delivery fails with the wrapped error.

Solutions

  1. Verify the MQTT connection is alive before publishing (auto-reconnect settings)
  2. Retry the publish; paho reconnects are usually transient
  3. Check broker-side limits such as max packet size or ACLs
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at pkg/channels/mqtt/mqtt.go:250 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/5ff701288217f5f0. Report an issue: GitHub.

Appendix: source

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

	}

	clientID := strings.TrimPrefix(msg.ChatID, "mqtt:")
	if clientID == msg.ChatID {
		logger.WarnCF("mqtt", "Send called with unexpected chatID format", map[string]any{"chat_id": msg.ChatID})
		return nil, nil
	}

	topic := fmt.Sprintf("%s/%s/%s/response", c.topicPrefix(), c.cfg.AgentID, clientID)

	data, err := json.Marshal(mqttPayload{Text: msg.Content})
	if err != nil {
		return nil, fmt.Errorf("mqtt: failed to marshal outbound payload: %w", err)
	}

	token := c.client.Publish(topic, c.qos, false, data)
	token.Wait()
	if err := token.Error(); err != nil {
		return nil, fmt.Errorf("mqtt: publish failed: %w", err)
	}

	logger.DebugCF("mqtt", "Published response", map[string]any{"topic": topic})
	return nil, nil
}

View on GitHub (pinned to 49183d7e8d)