Service-area delivery mode and declared carrier options
Status
Accepted (2026-11-13)
Context
The network's own last mile is not the only way to serve a postal prefix: in
sparse or remote areas the planner may hand packages to an external carrier at
a network node instead of routing them onto a station's delivery waves. No
repo of the fleet can compute whether own delivery pays — there is no density
model and no geography beyond declared constants — so the decision is made out
of band, by the planner, and lands in node-topology as a DECLARATION on the
service area. The per-package "chosen at the sort node by lowest cost" rule of
the model frame cannot be a free operator choice either: a promise quoted
against one carrier's transit must not be handed to another. Consumers of
ServiceAreaAssigned (the promise, the last mile) decode the event tolerantly
today, so the change must be additive on the same type.
Decision
ServiceAreagainsmode DeliveryMode—NETWORK_ROUTE(the zero value, and the behaviour of every existing area) |CARRIER_HANDOFF— andcarriers []CarrierOption— required non-empty (1..MaxCarriersPerArea= 4) whenCARRIER_HANDOFF, empty whenNETWORK_ROUTE.CarrierOptionis{CarrierID string, HandoffNodeID node.ID, CostPerPackageCents int64, TransitMinutes int}withCostPerPackageCents0..10,000,000 (the same integer-cent ceiling a lane's declared cost uses, ADR 0014) andTransitMinutes1..2147483647.assignenforces, besides the standing invariants:ErrHandoffNodeNotUsable(409): each option'sHandoffNodeIDloads and is ACTIVE with type DELIVERY_STATION or SORTATION_CENTER — the two carrier-collect points reachable from the sort network underallowedPairs; a node of any other type, or inactive, is refused.ErrCarrierOptionsInvalid(422): a duplicatecarrierIdwithin the area, an empty option list on CARRIER_HANDOFF, or a non-empty list on NETWORK_ROUTE.
- Omission semantics on the wire:
deliveryModeandcarriersareomitempty; their absence means NETWORK_ROUTE with no options, which is the current behaviour. The change is additive v1 on the SAME typecom.retailnetwork.logistics.node-topology.servicearea.ServiceAreaAssigned(same dataschemaurn:retailnetwork:node-topology:events:ServiceAreaAssigned:v1), because every consumer decodes tolerantly and defaults to the old meaning. - Storage (migration
0006_service_area_delivery_mode):service_areasgainsdelivery_mode TEXT NOT NULL DEFAULT 'NETWORK_ROUTE' CHECK (delivery_mode IN ('NETWORK_ROUTE','CARRIER_HANDOFF'))andcarrier_options JSONB NOT NULL DEFAULT '[]'; the down migration drops both. Rollback: additive columns stay; unassigning is a reassignment to NETWORK_ROUTE (version+1). - REST: the assign request/response gain
deliveryModeandcarriers[{carrierId, handoffNodeId, costPerPackageCents, transitMinutes}](additive, optional); 409 gainshandoff-node-not-usable; 422 gainscarrier-options-invalid; the resolve read returns them. MCP and A2A read tools surface the two fields additively. - The per-package carrier CHOICE is computed downstream from the declared options — sort by costPerPackageCents ascending, tie: the option with the LATER transit window, tie: lexicographically smallest carrierId — by the promise at quote time (into the witness) and by tracking at handoff time, both from the same area assignment version. The choice rule is not implemented in this repo and never chooses at the handoff desk.
- Lanes are untouched: the handoff lane's declared cost is the planner's input to the mode declaration, not a promise input.
Consequences
- Every area without a mode is NETWORK_ROUTE; nothing changes until a CARRIER_HANDOFF assignment exists (the C4 activation gate).
- Downstream repos (delivery-promise, last-mile-delivery) consume the mode from the same event; shipping-and-tracking does not consume it today.
- The planner owns the density decision; this context records it, it does not compute it.
- A reassignment can flip the mode either way under a strictly higher assignment version; consumers keep the highest version they have seen.