docs/book/src/sop/connectivity.md
This document describes how external events trigger SOP runs.
ZeroClaw routes MQTT/webhook/cron/peripheral events through a unified SOP dispatcher (dispatch_sop_event).
Key behaviors:
SopAuditLogger.ExecuteStep actions are logged as pending (not silently executed).Configure broker access with zeroclaw config set channels.mqtt.<field> <value> — the keys land under [channels.mqtt] in the stored config. See the Config reference for all fields. The use_tls flag must match the scheme of broker_url (mqtts:// ⇒ true, mqtt:// ⇒ false).
In SOP.toml:
[[triggers]]
type = "mqtt"
topic = "sensors/alert"
condition = "$.severity >= 2"
MQTT payload is forwarded into SOP event payload (event.payload), then shown in step context.
POST /sop/{*rest}: SOP-only endpoint. Returns 404 if no SOP matches. No LLM fallback.POST /webhook: chat endpoint. It attempts SOP dispatch first; if no match, falls back to normal LLM flow.Path matching is exact against configured webhook trigger path.
Example:
path = "/sop/deploy"POST /sop/deployWhen pairing is enabled (default), provide:
Authorization: Bearer <token> (from POST /pair)X-Webhook-Secret: <secret> when webhook secret is configuredUse:
X-Idempotency-Key: <unique-key>
Defaults:
200 OK with "status": "duplicate"Idempotency keys are namespaced per endpoint (/webhook vs /sop/*).
curl -X POST http://127.0.0.1:42617/sop/deploy \
-H "Authorization: Bearer <token>" \
-H "X-Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"message":"deploy-service-a"}'
Typical response:
{
"status": "accepted",
"matched_sops": ["deploy-pipeline"],
"source": "sop_webhook",
"path": "/sop/deploy"
}
The scheduler evaluates cached cron triggers using a window-based check.
(last_check, now] are not missed.Trigger example:
[[triggers]]
type = "cron"
expression = "0 0 8 * * *"
Cron expressions support 5, 6, or 7 fields.
| Feature | Mechanism |
|---|---|
| MQTT transport | mqtts:// + use_tls = true for TLS transport |
| Webhook auth | Pairing bearer token (default required), optional shared secret header |
| Rate limiting | Per-client limits on webhook routes (webhook_rate_limit_per_minute, default 60) |
| Idempotency | Header-based dedup (X-Idempotency-Key, default TTL 300s) |
| Cron validation | Invalid cron expressions fail closed during parsing/cache build |
| Symptom | Likely Cause | Fix |
|---|---|---|
| MQTT connection errors | broker URL/TLS mismatch | Verify scheme + TLS flag pairing (mqtt:///false, mqtts:///true) |
Webhook 401 Unauthorized | missing bearer or invalid secret | re-pair token (POST /pair) and verify X-Webhook-Secret if configured |
/sop/* returns 404 | trigger path mismatch | ensure SOP.toml uses exact path (for example /sop/deploy) |
| SOP started but step not executed | headless trigger without active agent loop | run an agent loop for ExecuteStep, or design run to pause on approvals |
| Cron not firing | daemon not running or invalid expression | run zeroclaw daemon; check logs for cron parse warnings |