Skip to main content

ADR 0004: CloudEvents envelope and type catalogue

Status​

Accepted (2026-10-21).

Context​

Every Kafka message in the fleet is a CloudEvents 1.0 event in structured mode (fleet rule .claude/rules/fleet/cloudevents.md, warehouse-docs docs/strategic-design/event-standard-cloudevents.md). This ADR is the catalogue of every type exception-management publishes or consumes; TestEventCatalogueMatchesContract checks it against apis/asyncapi.yaml.

Decision​

Envelope​

  • specversion 1.0; id a UUID minted once per domain event and persisted with the outbox row (stable across relay retries; consumers dedupe on it); source /warehouse/exception-management; subject the case id (case-<uuid>), or the source type for the policy event; time the occurred-at instant in UTC; datacontenttype application/json; dataschema urn:warehouse:exception-management:<events|analytics>:<EventName>:v1.
  • Kafka value = the JSON event format; header content-type: application/cloudevents+json; charset=UTF-8; Kafka key = the subject, so all events of one case stay ordered on one partition.
  • data is snake_case; optional fields are omitted when unset; timestamps are RFC 3339 UTC.
  • Built and decoded only through internal/adapters/kafka/cloudevents.

Published​

<entity> is the raising aggregate, lowercase, no separators: exceptioncase or exceptionpolicy. The stream column says where the type goes: events is warehouse.exception-management.events (the integration contract), analytics is warehouse.exception-management.analytics (this service's own projector only, not an integration contract). The analytics mirror of every type below ships with the projector in a later build step of this service; it is declared here so the stream set does not change under the consumers later.

typestreamraised whendata
com.warehouse.wes.exception-management.exceptioncase.ExceptionOpenedevents + analyticsa source fact opens a case (first occurrence of the dedup key){case_id, source_type, source_subject, site_id (nullable), severity, queue, opened_at, sla_due_at, source_event_id, source_payload (object, frozen)}
com.warehouse.wes.exception-management.exceptioncase.ExceptionTriagedevents + analyticsseverity/queue set by an operator or system{case_id, severity, queue, actor, at}
com.warehouse.wes.exception-management.exceptioncase.ExceptionAssignedevents + analyticsan owner takes the case{case_id, assignee, actor, at}
com.warehouse.wes.exception-management.exceptioncase.ExceptionEscalatedevents + analyticsthe SLA sweeper sets the breach flag{case_id, sla_due_at, at}
com.warehouse.wes.exception-management.exceptioncase.ExceptionResolvedevents + analyticsan operator records resolution code + root cause (terminal){case_id, resolution_code, root_cause, note (nullable), actor, at}
com.warehouse.wes.exception-management.exceptioncase.ExceptionAutoResolvedevents + analyticsa policy auto-resolve rule fires on a correlated fact{case_id, rule_id, correlated_type, correlated_event_id, at}
com.warehouse.wes.exception-management.exceptionpolicy.ExceptionPolicyDeclaredevents + analyticsa policy version is declared{source_type, version, severity, queue, sla_minutes, auto_resolve (nullable)}

Payload rules:

  • ExceptionPolicyDeclared has subject and key = the source type (the full CloudEvents type string of the governed source fact); every other type has subject and key = the case id.
  • severity is LOW, MEDIUM, HIGH or CRITICAL.
  • ExceptionOpened.source_payload is the frozen copy of the consumed source fact's data: it never changes after open and is never re-fetched (ADR 0002).
  • ExceptionResolved.note is null when the operator recorded no remark.
  • ExceptionAutoResolved.correlated_type and correlated_event_id are the full CloudEvents type and id of the fact that satisfied the rule.
  • Analytics copies carry the same type and the same id per occurrence, with dataschema urn:warehouse:exception-management:analytics:<EventName>:v1.
  • A breaking payload change is a new .v2 type and dataschema, never a mutation of v1.

Consumed (ADR 0003)​

typetopicconsumer group envstatus
com.warehouse.wes.fulfillment-execution.task.TaskCPTMissedwarehouse.fulfillment.eventsFULFILLMENT_EXCEPTIONS_CONSUMER_GROUPv1 (verified on the producer's contract)
com.warehouse.wes.fulfillment-execution.package.PackageDivertedwarehouse.fulfillment.eventsFULFILLMENT_EXCEPTIONS_CONSUMER_GROUPpending the producer's promotion PR (analytics-only today)
com.warehouse.wes.fulfillment-execution.package.WeightDiscrepancyDetectedwarehouse.fulfillment.eventsFULFILLMENT_EXCEPTIONS_CONSUMER_GROUPpending the producer's promotion PR (analytics-only today)
com.warehouse.wes.work-planning.workpool.BacklogThresholdBreachedwarehouse.work-planning.eventsWORK_PLANNING_EXCEPTIONS_CONSUMER_GROUPv1 (verified)
com.warehouse.wes.network-fulfillment.networkorder.AcknowledgementDeadlineAtRiskwarehouse.network-fulfillment.eventsNETWORK_FULFILLMENT_EXCEPTIONS_CONSUMER_GROUPv1 (verified)
com.warehouse.wes.network-fulfillment.networkorder.OrphanedHoldCancelledwarehouse.network-fulfillment.eventsNETWORK_FULFILLMENT_EXCEPTIONS_CONSUMER_GROUPv1 (verified)
com.warehouse.wes.order-management.order.OrderRepromisedwarehouse.order-management.eventsORDER_CORRELATION_CONSUMER_GROUPv1 (verified; correlation only, never a case source)
com.warehouse.wms.returns-processing.returnreceipt.UnexpectedReturnReceivedwarehouse.returns-processing.eventsRETURNS_EXCEPTIONS_CONSUMER_GROUPpinned consumer-first (producer ships in wave 3)
com.warehouse.wms.inventory-storage.bin.DiscrepancyDetectedwarehouse.inventory.eventsINVENTORY_EXCEPTIONS_CONSUMER_GROUPpending the producer's promotion PR (analytics-only today)
com.warehouse.wms.inventory-storage.stock.ItemUnlocatedwarehouse.inventory.eventsINVENTORY_EXCEPTIONS_CONSUMER_GROUPpending the producer's promotion PR (analytics-only today)

Planned, not built (analytics-topic only today, no consumer yet): workforce-management PathUnderstaffed, network-inventory-planning TransferStuckDetected.

Every other type on those topics is ignored. A message that is not a valid CloudEvent is logged and skipped, never retried forever. Payloads are restated from the producers' own contracts in apis/asyncapi.yaml and never imported.

Consequences​

  • Consumers need nothing but this catalogue and apis/asyncapi.yaml; there is no shared Go code across repos.
  • The analytics stream is not an integration contract: the only consumer is this service's own projector (a later build step); other contexts keep reading warehouse.exception-management.events.
  • Until a pending promotion PR merges, its types simply never arrive; the contract above is pinned consumer-first and fixed here in a follow-up PR if a producer's final contract differs.

Addendum 2026-11-13: current state​

The analytics mirror is built, not "a later build step": the relay writes every published fact to warehouse.exception-management.analytics as well (internal/adapters/outbound/kafka/encoder.go:24-29,79), and cmd/exceptions-projector consumes it (internal/adapters/inbound/kafka/analytics_consumer.go; the seven *Analytics messages and receiveExceptionAnalytics in apis/asyncapi.yaml:129-130). The Consumed table above is the original set of ten types. apis/asyncapi.yaml declares 20 consumed types today, adding those of ADR 0006, 0010, 0011 and 0012; the "pending the producer's promotion PR" rows are on the producers' integration topics (fulfillment-execution apis/asyncapi.yaml:58,70-71; inventory-storage apis/asyncapi.yaml:170-172,205-206).