ADR 0006: carton-discrepancy consumer and routing
Status
Accepted (2026-10-24).
Context
inbound-receiving publishes CartonDiscrepancyRaised for every carton that
does not match its ASN or fails a receiving check (mastercase contract R5,
R12). exception-management turns each into a routed case. Constraints from
ADR 0003 (no live call to a sibling context; consumed contracts restated
locally) and ADR 0004 (CloudEvents 1.0 structured JSON, full type dispatch).
Decision
-
One consumer, one type.
warehouse.inbound-receiving.eventsis read under its own groupCARTON_DISCREPANCY_CONSUMER_GROUP(env, no default, boot error when unset; rendered by the Helm chart). Onlycom.warehouse.wms.inbound-receiving.receipt.CartonDiscrepancyRaisedis acted on; the other types on the topic are ignored. -
Payload (snake_case, as shipped):
receipt_id,sscc?,kind,expected?,actual?,at.kindis accepted as ANY string. -
Natural key. One case per
(receipt_id, sscc | "-", kind): the dedup key is(type, "<receipt_id>/<sscc|->/<kind>", ""). A re-raise under another CloudEvents id touches the open case; a replayed id is a no-op (processed-event claim in the same transaction as the effect). -
Routing is data. Two policy source types, seeded by migration 0003 (version 1, redeclarable through the policy API):
...CartonDiscrepancyRaised#problem-solve(HIGH, queueproblem-solve, 60 min) and...#receiving-lead(LOW, queuereceiving-lead, 480 min, informational, blocks nothing). The routing table lives inusecases.RouteForCartonKind:- problem-solve: UnexpectedCarton, MissingCarton, DuplicateSscc, UnknownGtin, CaseQtyMismatch, MixedCaseDeclaredAsCasePack, MixedCartonContentMismatch, and every unknown kind (never dropped, never silently demoted).
- receiving-lead: UnlabelledCarton, CartonOverLimit.
The case's
dedupKey.sourceTypestays the event type; only the policy lookup uses the route (Fact.PolicyType). -
Visibility is unchanged: the cases appear in the existing REST list (
sourceType,queuefilters), detail, triage/assign/resolve and the MCP tools; the two routes appear in the policy list. -
Shutdown budget. kafka-go group readers use
MaxWait: 500msso seven consumers stop inside the 40s graceful-stop budget.
Consequences
- A new inbound-receiving kind needs no code change to be tracked; moving it to receiving-lead is a one-line table change.
- Operators tune severity/queue/SLA per route, not per kind (per-kind policy would need a source type per kind; deferred until asked for).
- If a route policy is absent the message is skipped with a WARN and committed past (ADR 0002 policy rule).