ADR 0014: delivery-point profile (outcome detail, DeliveryPointProfile, DeliveryPointFlagged; roadmap C5)
Status
Accepted (2026-11-11).
Context
Wave 3 of the network evolution (roadmap item C5) wants the network to learn which drop-off points fail repeatedly, so that a planner and, later, the shopper can be told. The plan assumed more than this context can support, so the slice is reduced to what the code can honour (the Wave 3 design, section 2):
- The outcome vocabulary does not exist. An attempt is
DELIVEREDorFAILEDandfailureReasonis free text (1 to 200 characters, required exactly whenFAILED). The model defines no vocabulary. Parsing the text to guess a category is forbidden: it would invent a contract and would copy free text, which can hold personal data, into a new table. - There is no stop sequencer. The caller (the station planner) sends the stops;
route.Planonly validates them. A profile therefore cannot reorder a route and must not refuse one. - No entrance, parking or locker knowledge exists in any event or table; locker and pickup belong to a later item that needs its own model amendment.
- No address, name or free text may enter any new event, table or log line. The
stop is identified only by the opaque
stopKey(an HMAC derived by shipping-and-tracking at label time); the profile stores that key and counters.
The alternatives weighed: (a) add new outcome values (NOT_HOME, ...): rejected,
the wire outcome is consumed by shipping-and-tracking and by the analytics CHECK,
which would treat an unknown value as a failure or reject it; (b) build the profile
from our own DeliveryAttempted events through a second consumer group: rejected,
it is lagged, adds a consumer, and the data is already in hand inside
RecordAttempt; (c) a sweeper that decays strikes: rejected, this context has no
periodic job, so decay is evaluated lazily at the next observation.
Decision
- Outcome detail (additive, optional, dormant until a client sends it). The
attempt gains
outcomeDetail: forFAILEDone ofNOT_HOME,ACCESS_PROBLEM,OTHER; forDELIVEREDSAFE_PLACE_USED. Empty means "not reported" (a legacy client) and is NOT the same asOTHER.failureReasonstays required forFAILEDand forbidden forDELIVERED; a detail never replaces it. A mismatch of detail and outcome is422 validation-failed.outcomeDetailis on the REST request and response, the MCP and A2Aget_routeattempts, theDeliveryAttemptedevent (optional, omitted when empty, same type, dataschema:v1and topic) and inroute_attempts.outcome_detail(migration 0004). - Aggregate
DeliveryPointProfile(internal/domain/deliverypoint), root id = thestopKey, entity segmentdeliverypointprofile. Countersattempts,delivered,safePlaceUsed,failedNotHome,failedAccess,failedOther(saturating atshared.MaxInt32), a ring of at mostMaxStrikesstrikes{routeId, trackingNumber, category, at, notified},flaggedAt,lastAttemptAtand the version. Named constants:FlagAfterStrikes = 2,StrikeWindow = 60 days,MaxStrikes = 5; onlyNOT_HOMEandACCESS_PROBLEMare counted failures;OTHERand "not reported" are tallied, never counted.Restorevalidates: a stopKey that is valid and does not start withpkg:;attempts == delivered + failedNotHome + failedAccess + failedOther;safePlaceUsed <= delivered; at mostMaxStrikesstrikes, each a counted category, no two with onerouteId;flaggedAtis non-zero exactly when the strikes reachFlagAfterStrikes. - The one command
Observe(steps in order): (1)ref = max(at, lastAttemptAt), drop strikes older thanref - StrikeWindow, clear the flag when fewer thanFlagAfterStrikesremain; (2) tally the attempt (OTHERand empty both count asfailedOther); (3) a counted failure whoserouteIdhas no strike appends one (two parcels failing at one stop on one route are ONE strike, one visit) and the ring is trimmed oldest-first; (4) aDELIVEREDattempt ends the episode (clears strikes and flag) unless a strike of the samerouteIdexists; (5)lastAttemptAt = max(...), version up; (6) while at leastFlagAfterStrikesstrikes are open, the distinct tracking numbers of strikes not yet notified (and with no notified strike of their own number) are marked notified and raise ONEDeliveryPointFlaggedcarrying only those numbers andfailures = len(strikes);reasonisACCESS_PROBLEMwhen any open strike has it, elseNOT_HOME. A later parcel of another order failing at an already flagged point is therefore told too, once. - Event
DeliveryPointFlagged(integration, topicretailnetwork.last-mile-delivery.events): typecom.retailnetwork.logistics.last-mile-delivery.deliverypointprofile.DeliveryPointFlagged, source/retailnetwork/last-mile-delivery, dataschemaurn:retailnetwork:last-mile-delivery:events:DeliveryPointFlagged:v1, subject and Kafka key = thestopKey.data:stopKey,reason(NOT_HOMEorACCESS_PROBLEM),failures(integer, at least 2),trackingNumbers(1 to 5, the newly affected packages only),flaggedAt(RFC 3339 UTC, the attempt instant that triggered it). No optional fields. No event means "no new package was affected". There is no "cleared" event. - Persistence. Migration 0005 creates
delivery_point_profiles(stop key primary key with apkg:CHECK, the counters,strikes JSONB,flagged_at,last_attempt_at,version). Portports.DeliveryPointRepositorywithGet(ErrNotFound),GetMany(missing keys absent, never an error) andSaveunder the optimistic rule (create at version 1 expects absence; a unique violation isErrConcurrentUpdate). No retention job in this slice: a row is about 300 bytes per distinct address. - The use case.
RecordAttempt.executecallsupdateProfileafterupdateHistory, in the same unit of work: no lag, no second consumer group. The key comes fromstopInfo; a key starting withpkg:(a package with no label data) has no address key and gets no profile and no event. Counterlast_mile_delivery.delivery_point.flagged(attributereason). - Read-only exposure, no influence.
GET /delivery-points/{stopKey}(getDeliveryPoint): 200DeliveryPoint, 404not-found, 422validation-failedfor an invalid key.WaveStopgains an optionaldeliveryPoint{flagged, openStrikes, safePlaceUses}present only when a profile exists, loaded with oneGetManyper page. The MCPget_wave_stopsoutput gains the same object; the MCP charter stays read-only, no new tool, no A2A skill.PlanRouteis unchanged: no new error and no new status; the planner's invariants (ErrRouteOverCapacity,ErrStopKeyMismatch,ErrPackageAlreadyRouted, numbering) are untouched. A flagged point changes no ETA, no sequence and no promise. - Stop key source. The profile uses the
PackageStopViewkey; a package inducted before its label data arrived ispkg:<trackingNumber>and never gets a profile. RotatingSTOP_KEY_SECRETproduces new keys: the old profiles are orphaned and learning restarts.
Consequences
- C5 is dormant until the driver client sends
outcomeDetail: before that the profile tallies attempts as "other", never counts a strike and never publishes. Activation is a client change, not a deploy flag. - An invalid stop key on
Observecannot occur through the use case;Observereturnsshared.Invalidfor a malformed observation instead of guessing. - The profile holds only outcome-derived facts, never entrance, parking or locker
knowledge. No address, name, phone or free text is copied, and
failureReasonis not copied to the profile. - Two routes failing at one point concurrently conflict on the profile version;
transactretries once and the second run sees the first strike. - Strikes decay lazily: a point that is never visited again keeps its row and its open flag (a row with no consumer interest); the open decision on retention is for the product owner.
- No new env var, topic, consumer group, chart value or secret. Migrations 0004 and 0005 run at boot and are additive. Deploy order for the chain: customer-ordering, shipping-and-tracking, then this context, because a consumer commits past a type it has no handler for.
docs/adr/0004lists the new type in its catalogue; the projector acknowledges it and needs no fact from it.
Addendum 2026-11-13: current state
Item 7 of the Decision (read-only exposure) is not in the code. There is no GET /delivery-points/{stopKey} (getDeliveryPoint) in apis/openapi.yaml or internal/adapters/inbound/http, WaveStop has no deliveryPoint object (apis/openapi.yaml, schema WaveStop: stopKey, destinationPostalPrefix, trackingNumbers), and internal/adapters/inbound/mcp returns no such object from get_wave_stops. PR #57, which added this ADR, changed apis/openapi.yaml only for outcomeDetail.
The profile itself is built: internal/domain/deliverypoint (aggregate, Observe, DeliveryPointFlagged), internal/application/usecases/delivery_points.go (the RecordAttempt step) and internal/adapters/outbound/postgres/delivery_points.go. ports.DeliveryPointRepository.GetMany exists with Postgres and in-memory implementations, but no use case calls it.