ADR 0063: Task interleaving is a dispatch strategy, selected per Facility, gated by the proximity setting
Status: Accepted
Context
The owner chose one Facility setting for proximity, off by default, with each function opting in independently (ADR 0061, ADR 0062). Putaway and the pick route follow that rule. Task interleaving is the next function: when an operator finishes a task, "Get next task" can offer the work nearest to where they stand, across the work types their work groups allow.
The owner approved this shape for interleaving: dispatch the nearest eligible task to where the operator is, across every type their work groups allow, inside the highest priority band and with a wait limit. The operator's position comes from the last confirmed task, with an optional floor-app scan. Bundling a putaway with a nearby retrieval as one dual-cycle trip was not chosen and is not built.
Before this change the work service had one active dispatch strategy for the whole installation,
chosen by name from karyo.work.dispatch-strategy (environment KARYO_WORK_DISPATCH_STRATEGY) and
checked at boot. A strategy saw only the list of items. It knew nothing of the operator.
Decision
A strategy named PROXIMITY. It orders the pool by priority band first, then the walk in metres
from the operator's position, then createdAt. A priority band is the set of items with one
priority value; a higher value is a higher band. The pool is the one the dispatch service already
builds: exactly the work types the operator's groups allow, narrowed by zone and working area.
Eligibility is not the strategy's business, so an excluded type is never offered.
A wait limit. An item that has waited longer than karyo.work.proximity.max-wait-minutes
(default 30, minimum 1) moves up one band. It then competes with the band above on the walk, and an
old item of the top band moves above all of it. So far work is not starved by a stream of nearer
work. An item exactly at the limit has not waited longer than it.
Work with no place. An item whose location cannot be measured, or that has none, follows the measured items of its band, oldest first.
The Facility chooses the strategy. karyo.work.dispatch-strategy becomes a catalogue setting
(group Work dispatch) read for the Facility through the runtime configuration ladder. The
installation's environment value is the ladder's configuration step, so a Facility that never sets
the key keeps today's strategy. The catalogue accepts STRICT_PRIORITY, TRAVEL_PATH and
PROXIMITY; a custom strategy bean is still selected by the environment value alone.
The proximity gate. PROXIMITY is used only while the Facility also has karyo.proximity.enabled
on. With it off, a Facility that selected PROXIMITY gets STRICT_PRIORITY, so choosing the
strategy changes nothing until proximity is enabled. STRICT_PRIORITY and TRAVEL_PATH ignore the
operator's position and proximity entirely, and their results are unchanged.
Operator position. work-core keeps one row per operator and Facility in operator_positions: the
location, where it came from (CONFIRMATION or SCAN) and when. Each module that confirms work
at a place fires OperatorLocatedEvent from karyo-work-api: tasks-core at the destination of a
completed transport order, fulfillment-core at the source of a confirmed pick (read before the
stock moves), stocktaking-core at the counted location when a count is submitted or confirmed
empty, and orders-core at the dock of a goods receipt when a line is received on it (the dock is where
dispatch measures a receiving task, and the floor app confirms receiving only by line). At every
site the person who confirms the work is the one whose position moves, whoever holds the work, and nobody
else moves: OperatorLocatedEvent.confirmedAt takes the caller's username and principal id. Work nobody
holds moves the caller too. work-core records it after the confirming transaction commits, in a transaction of its own,
and only while the Facility orders work by position. A failure to record never fails the
confirmation. The floor app's "I am at" scan writes the same row through PUT /api/v1/work/position,
so whichever came later stands. With no row, dispatch measures from the depot, the first Area's
entry, as the pick route and the simulator do.
Pick work items carry a location. PickWorkProvider fills WorkItem.primaryLocationId with the
location of a pick order's first open pick in sequence (ADR 0062),
and only when the dispatch service asks with WorkFilter.withLocations, which it does only for a
position-aware strategy. Every other dispatch reads exactly what it read before.
One seam for the position. WorkDispatchStrategy gains usesPosition and
order(items, DispatchContext); the default of both keeps every existing strategy unchanged. The
context holds the operator's location, the time, the wait limit and a walk measure. Live dispatch
measures through LocationDistanceLookup.walkMetres, which reads only the operator's location and
the locations of the pool. The flow projection builds the same context from the simulated operator:
a person's position is the place of the unit they finished last, and a walking picker returns to the
depot. QueueProjection and the day simulator order a position-aware strategy per free person.
Consequences
An existing Facility dispatches as before. Turning interleaving on takes two settings of the
Facility: proximity enabled, and the dispatch strategy set to PROXIMITY. Until the operator
confirms a task or scans a location, dispatch measures from the depot. A position never expires;
it stays until the next confirmation or scan.
Pick orders are placed by their first open pick only. A pick order with several locations is
dispatched by where it starts. While a Facility uses PROXIMITY, picks have a location, so a
?workingAreaId= filter no longer hides them.
A custom dispatch strategy cannot be stored as a Facility row, because the catalogue refuses names
it does not know. It is selected by KARYO_WORK_DISPATCH_STRATEGY for the installation. An
unregistered name still fails loudly at dispatch time; the boot check covers only the installation's
value.
The nearest task is not a globally shortest tour: each choice looks one task ahead. The flow simulator's policy P runs this strategy with the other proximity rules, and the walk-distance evidence records it against policies R and O; no default changes on that evidence alone.
Alternatives considered
- A switch per Area. Rejected by the owner: proximity is one Facility setting, and each function reads it independently.
- Bundling a putaway with a nearby retrieval as one trip (a dual cycle). Not chosen by the owner. It would need a new kind of task; this change needs none.
- Aging as a weight. A weighted score of priority, walk and age would hide why a task was offered. Bands with a wait limit keep the order explainable.
- Reading the position from the last claim. A claim says where the work is, not where the operator ended up. Confirmation says where they stand.
Evidence
services/work-service/karyo-work-api/src/main/kotlin/com/karyo/work/dto/DispatchContext.ktservices/work-service/karyo-work-api/src/main/kotlin/com/karyo/work/spi/WorkDispatchStrategy.ktservices/work-service/karyo-work-api/src/main/kotlin/com/karyo/work/event/OperatorLocatedEvent.ktservices/work-service/karyo-work-core/src/main/kotlin/com/karyo/work/service/ProximityDispatchStrategy.ktservices/work-service/karyo-work-core/src/main/kotlin/com/karyo/work/service/WorkDispatchService.ktservices/work-service/karyo-work-core/src/main/kotlin/com/karyo/work/service/DispatchEnvironment.ktservices/work-service/karyo-work-core/src/main/kotlin/com/karyo/work/service/OperatorPositionService.ktservices/work-service/karyo-work-core/src/main/kotlin/com/karyo/work/messaging/OperatorLocatedObserver.ktservices/work-service/karyo-work-core/src/main/kotlin/com/karyo/work/api/v1/WorkInboxResource.ktservices/karyo-app/src/main/resources/db/migration/work/V1616__operator_positions.sqlservices/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/service/FloorPlanService.ktservices/fulfillment-service/karyo-fulfillment-core/src/main/kotlin/com/karyo/fulfillment/messaging/PickWorkProvider.ktservices/fulfillment-service/karyo-fulfillment-core/src/main/kotlin/com/karyo/fulfillment/service/PickPositionAnnouncer.ktservices/task-service/karyo-tasks-core/src/main/kotlin/com/karyo/tasks/service/TransportOrderEmitter.ktservices/order-service/karyo-orders-core/src/main/kotlin/com/karyo/orders/service/GoodsReceiptService.ktservices/stocktaking-service/karyo-stocktaking-core/src/main/kotlin/com/karyo/stocktaking/service/StocktakingService.ktservices/flow-service/karyo-flow-core/src/main/kotlin/com/karyo/flow/engine/QueueProjection.ktservices/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/config/SystemPropertyCatalog.ktfrontend/mobile/src/components/hmi/position-card.tsxservices/karyo-app/src/test/kotlin/com/karyo/work/ProximityDispatchTest.ktservices/karyo-app/src/test/kotlin/com/karyo/flow/FlowProximityDispatchTest.ktservices/karyo-app/src/test/kotlin/com/karyo/app/ProximityDispatchFlowTest.kt