Repository navigation
ADR 0009 Command And Event Envelopes
Accepted (2026-10-08)
Services exchange mower commands, telemetry and domain events over NATS JetStream (ADR 0007). The plan requires that a command delivered twice is executed once, that a stale command (for example a "start" queued during an outage) is never executed, that an emergency stop always wins, and that contracts only evolve in a backward compatible way. ADR 0007 left the message format, the subject scheme and the enforcement of message ids and expiry to our contracts.
All bus messages are wrapped in envelopes defined in mowdeck-contracts (mowdeck_contracts.v1):
-
CommandEnvelope:
command_id(UUID),mower_id,account_id,issued_by(principal reference),issued_at,expires_at,priority(normaloremergency),correlation_idandcommand, a discriminated union onkind(start_mow,pause_mow,resume_mow,return_to_dock,emergency_stop,set_blade_height,set_speed,manual_drive).-
expires_atmust be afterissued_at. Consumers checkis_expired()before execution and answer with aCommandResultof statusexpired; publishers refuse to send expired commands. -
priorityisemergencyif and only if the command isemergency_stop, and is derived when omitted. The priority is also sent as theMowdeck-Priorityheader so the Device-Gateway can fast-path it without decoding. -
manual_drivecarries its own dead-man timeoutttl_ms(100 to 2000 ms, default 1000).
-
-
CommandResult:
command_id,mower_id,status(accepted,rejected,executed,expired,failed),reason,at. -
EventEnvelope[Payload]:
id(UUID),type(<domain>.<name>, e.g.mower.registered),version(integer, starting at 1),occurred_at,account_id,correlation_id,causation_id,producerand the typedpayload. - All timestamps are timezone-aware UTC. Models ignore unknown fields (tolerant reader).
De-duplication uses JetStream: the envelope id (command_id or event id) is sent as the Nats-Msg-Id header. JetStream drops a repeated id within the stream's duplicate window (120 s for commands and events, 30 s for telemetry). Consumers stay idempotent for redeliveries after a missing ack.
Subject naming (refines ADR 0007; events get an event. prefix so one stream captures all of them):
| Subject | Stream | Payload |
|---|---|---|
command.mower.<mower_id> |
COMMANDS (command.>) |
CommandEnvelope |
command.result.mower.<mower_id> |
COMMANDS |
CommandResult |
telemetry.mower.<mower_id> |
TELEMETRY (telemetry.>) |
MowerState |
event.<domain>.<name> |
EVENTS (event.>) |
EventEnvelope |
Other subjects (for example svc.<service>.<operation> for request/reply) use core NATS and are not persisted. Stream limits are defined as data in mowdeck_contracts.v1.subjects and applied by mowdeck-service-kit on connect.
Versioning: within v1 only backward compatible changes (new optional fields). An event is never reinterpreted; a changed meaning gets a new event version. An incompatible envelope change creates a new namespace mowdeck_contracts.v2. JSON Schemas are exported to libs/mowdeck-contracts/schemas/v1/ and a test fails when they are out of date.
Options considered: CloudEvents as the envelope (rejected for now: more fields than needed and no typed command union; the envelope maps onto CloudEvents attributes if an external integration needs it), and de-duplication in each consumer with a database table (rejected: JetStream already provides it within a window, consumers only need idempotency for redeliveries).
- Duplicate publishes within the window are harmless; stale and duplicated commands cannot move a mower.
- Emergency stops are recognisable from the header alone and cannot be downgraded by a client.
- Every producer and consumer depends on
mowdeck-contracts; changing a model requires regenerating and committing the schemas. - De-duplication only covers the duplicate window. Longer-lived idempotency (for example for scheduled commands) must be handled by the producer, which issues a new
command_idper execution. - Telemetry and command results are bounded by stream limits; history lives in the Telemetry service and the audit log.
Mirrored from docs/adr/0009-command-and-event-envelopes.md at commit 690a4b82f5ebf7597d0952b648aa5798d083620e. Edit the file in the repository, not this wiki page.
Mirrored from the docs/ directory at commit 690a4b82f5ebf7597d0952b648aa5798d083620e. Edit the files in the repository, not this wiki.
MowDeck documentation
- Home
- Phases
- Architecture
-
Decisions (ADR)
- Architecture decisions
- ADR 0001: OpenFGA instead of self-built authorization
- ADR 0002: Self-built Identity service in FastAPI instead of Keycloak or Zitadel
- ADR 0003: SvelteKit for the web app
- ADR 0004: Monorepo with a uv workspace
- ADR 0005: AGPL-3.0 for services and apps, Apache-2.0 for libraries
- ADR 0006: PostgreSQL for all persistence, no SQLite
- ADR 0007: NATS JetStream as event bus
- ADR 0008: Traefik as gateway
- ADR 0009: Command and event envelopes, subject naming and de-duplication
- ADR 0010: Python 3.13 for all services and libraries
- ADR 0011: Separate GPL-3.0 package for the PyMammotion adapter
- ADR 0012: Mower control interface and safety rules
- ADR 0013: Device-Gateway registry, sharding and per-mower concurrency
- ADR 0014: Authorization model, tuple ownership and the mowdeck-authz client
- ADR 0015: Tokens, sessions and key rotation
- ADR 0016: Fleet commands and authorization per command kind
- ADR 0017: Telemetry storage and retention
- ADR 0018: Realtime WebSocket protocol
- ADR 0019: Mammotion adapter transports, manual drive and secrets
- ADR 0020: Web app architecture
- ADR 0021: Browser authentication flow
- ADR 0022: Notifications: rules, recipients and delivery
- ADR 0023: Map rendering and projection
- ADR 0024: Scheduler: recurrence, rain pause and command issuing
- ADR 0025: Home Assistant integration as a pure API client
- ADR 0026: Manual drive channel over the Realtime WebSocket
- ADR 0027: Health history and theft alarm
- ADR 0028: Entitlements: plans as data and enforcement
- ADR 0029: Helm chart and release pipeline
- ADR 0030: Mowing patterns as plug-ins and the Planner
- ADR 0031: Billing with a Stripe adapter
- ADR 0032: Live camera over Agora, joined directly by the browser
- ADR 0033: Vision-assisted recovery with human approval
- ADR 0034: Linked cloud accounts and device discovery
- ADR 0035: Server-side camera frames and automatic AI analysis on errors
- ADR 0036: Native app shells with Capacitor, loading the web app from the server
- ADR 0037: Camera panorama calibration in the browser, with the AI supplying points only
- ADR 0038: Dual link per mower and firmware updates
- ADR 0039: Spot mowing by MowDeck-driven paths
- ADR 0040: Link heartbeat for online status
- ADR 0041: Spot runs from the dock: undock, transit and return
- ADR 0042: Drive calibration
- ADR 0043: Turn styles
- ADR 0044: Drive view with camera
- ADR 0045: Camera relay
- Development
- Operations
- Spikes
- Guides
- Original plan (German)