0017. Read facility-layout's travel graph once, at shift-plan-commit time, to enrich PathPlan
Status
Superseded by ADR-0049.
Accepted — implemented in the same change that introduced this record.
Context
facility-layout's own ADR-0017 ("Geometry & Travel Graph") built a
pure-domain travel graph over aisle centrelines and cross-aisles, exposed
at GET /distance?from=&to=: the shortest travel distance, in metres,
between two coded locations, flagged estimated when any leg used a
zone's bay-pitch fallback rather than real geometry. That same ADR's
boundary statement is explicit and non-negotiable:
FL publishes distances and adjacency (facts). Travel TIME, congestion, route choice = wes-work-planning. Slotting optimization = NOT FL.
This service's own AGENTS.md had named the absence of a travel/adjacency
input as a known gap since before facility-layout's geometry work existed:
ShiftPlan/PathPlan commit a rate × heads × hours split for a process
path with no notion of where that path's stations physically sit relative
to the zones it draws work from. The question this ADR answers is not
whether to consume facility-layout's new fact — that follow-on was
already scoped in facility-layout's own plan as "Phase B3: wes-work-planning
new outbound port TravelDistanceLookup" — but how this service reads
it, since facility-layout's estimateTravelDistance/GET /distance
endpoint is a synchronous REST read, not a Kafka-published event (there is
no "distance changed" domain event — a travel distance between two static
locations changes only when the physical layout itself changes).
Precedent: this is the same shape as ADR-0009, one boundary over
This service already has exactly this integration shape for a different
sibling: ADR-0009
reads inventory-storage's product classification once, synchronously, at
ReleaseNextWork publish time, via ports.ProductClassificationLookup
with an HTTP Client and a PermissiveLookup no-op default selected by
PRODUCT_CLASSIFICATION_MODE=http|permissive. That ADR's own rationale —
"build against the sibling's real, current contract rather than a Kafka
consumer for an event that doesn't exist," "fail-open, always," "never
blocks the use case it enriches" — applies here verbatim, just against
facility-layout's /distance endpoint instead of inventory-storage's
/products/{sku}/classification.
Decision
We will read the travel distance between two caller-supplied
facility-layout LocationCodes once, synchronously, from
GET /distance?from=&to=, at the moment CommitShiftPlan commits a
PathPlan — and stamp two derived, OPTIONAL fields onto that PathPlan —
rather than build a Kafka projector for a fact that has no publish event.
- Mechanism: synchronous outbound HTTP, mirroring this service's own
productclassificationadapter pattern exactly, not a Kafka projector. A new outbound portports.TravelDistanceLookup(GetDistance(ctx, from, to) (traveldistanceview.TravelDistanceView, error)), a new packageinternal/adapters/outbound/traveldistance/with a plainnet/httpClientand aPermissiveLookupno-op default, selected viaTRAVEL_DISTANCE_MODE=http|permissive(defaultpermissive), requiringFACILITY_LAYOUT_BASE_URLinhttpmode. - A new, un-persisted read model, not a projection table.
internal/domain/traveldistanceview.TravelDistanceView{From, To, MetresM, Estimated, Known}is a plain value returned by the lookup call and discarded after use — noprocessed_eventsrow, no Postgres table, no idempotency concern, exactly likeproductclassificationview.ProductClassificationViewand for the same reason: nothing is being applied to persisted state that survives past the single request. PathPlancarries an optional travel-distance hint.CommitShiftPlanRequestgains optionalFromLocationCode/ToLocationCodefields (empty by default, so every existing caller keeps compiling), andPathPlangainsSetTravelDistance(metresM float64, estimated bool)plusTravelDistanceKnown()/TravelDistanceM()/TravelDistanceEstimated()accessors — a plain setter after construction, not aNewPathPlanparameter, so this stays additive rather than touching the aggregate's existingplannedHeads <= installedStationsinvariant. Both caller- supplied location codes must be present to attempt the lookup; either omitted skips it entirely — this is a caller opt-in enrichment, not a required field on every shift-plan commit.- The lookup and the stamp both live in the use case, not the
outbound Kafka adapter — unlike ADR-0009's
WorkReleasedenrichment (which lives ininternal/adapters/outbound/kafka/publisher.gobecause it enriches an outbound event payload), this enriches the returned aggregate itself (PathPlan), which the REST response DTO then reflects directly.CommitShiftPlan.enrichWithTravelDistanceruns right afterplan.NewPathPlansucceeds and beforeplan.NewShiftPlanwraps it. - REST surface:
travelDistanceM/travelDistanceEstimatedare OMITTED fromShiftPlanResponse— not defaulted to0/false— when no hint was recorded, so a consumer that already treats "absent" as "no hint" sees no difference from before this feature existed (same omit-when-unknown discipline asWorkReleased'srequired_capabilities/fragile, ADR-0009). - Fail-open, always — never blocks committing a shift plan. Missing
location codes, a
nilTravelDistanceLookup(mirrorsPermissiveLookup's ownKnown=false), an unknown location, a cross-zone pair (facility-layout refuses those rather than guessing — see its own ADR-0017), or a lookup error (timeout, 5xx, facility-layout down) are all treated identically: no hint, andCommitShiftPlan.Executestill succeeds and still publishesShiftPlanCommitted. This mirrors ADR-0009's own asymmetry with inventory-storage's fail-closedStowStockcheck: a travel-distance hint is an enrichment of a planning aggregate, not a placement safety invariant, so blocking a commit on a sibling service's uptime would be the wrong trade.
Consequences
Easier
- A
PathPlancan now say how far apart its two representative locations are, closing the gap this service's ownAGENTS.mdhad named since before facility-layout's geometry work existed, without this service ever computing travel time, congestion, or route choice itself — those remain squarely wes-work-planning's concern per facility-layout's own boundary statement, and this ADR only consumes the distance fact, never derives a time/rate from it. - No new idempotency mechanism. Because nothing is persisted beyond
the committed
PathPlanitself, there is noprocessed_eventsrow to write and nothing to double-apply on retry. - Matches what facility-layout actually shipped. Building against
GET /distance?from=&to=means this integration compiles and works against facility-layout's real, current, spec-first contract (apis/openapi.yaml'sTravelDistanceschema) rather than a speculative shape. - Symmetric with this service's own ADR-0009 adapter shape. A
developer who has read
productclassification.Client/PermissiveLookuprecognizestraveldistance.Client/PermissiveLookupimmediately;TRAVEL_DISTANCE_MODE=http|permissivemirrorsPRODUCT_CLASSIFICATION_MODEexactly, down to the env var shape.
Harder
- A travel-distance hint recorded at commit time is not retroactively
refreshed. If the underlying facility-layout geometry changes after a
shift plan is committed (a new cross-aisle registered, an aisle's
centreline corrected), the already-committed
PathPlan's hint does not pick up the change — a known and accepted gap, in the same spirit as ADR-0009's "classification drift after release is not retroactively applied." FromLocationCode/ToLocationCodeare caller-supplied, not derived from the process-path catalogue. This service has no notion today of "this path's representative pick location" or "this path's station location" — the caller (an operator, a console screen, or a future fulfillment-executionStation.locationCode, itself a separate Phase B3 follow-on) must know and supply the two LocationCodes explicitly. A future enhancement could derive these automatically once fulfillment-execution's optionalStation.locationCode(also facility-layout Phase B3) exists and can be looked up bypathId; that is out of scope here.- A synchronous cross-service call sits on the commit path. Unlike
every read this service previously performed inside
CommitShiftPlan, the use case now makes a real HTTP call (inhttpmode, and only when both location codes are supplied) to facility-layout before theShiftPlanis saved andShiftPlanCommittedis published. The fail-open design bounds the availability risk (a slow/unavailable lookup degrades to "no hint," not to a failed commit), but it does add real latency to a commit that supplies location codes whenTRAVEL_DISTANCE_MODE=httpis enabled — a cost this service's core planning path never paid before, mirroring ADR-0009's own documented trade-off exactly.