Karyo
Documentation/ What Karyo does in a warehouse

Work allocation

Karyo 2.1.1rendered at build time
On this page

The work inbox is the floor's single queue. Five modules publish into it, one service orders it, and one operator pulls from it. It is also the thinnest layer in the functional stack, and the place where two real defects are easiest to hit.

The shape

WorkProvider (services/work-service/karyo-work-api/.../spi/WorkProvider.kt, WorkProvider) is a five-method SPI: workTypes(), listOpen(filter), listClaimedBy(operatorId), claim(ref, operatorId) and release(ref, operatorId, asManager). Each provider is a thin adapter over its own module's service, never over its repository - claim and release write through the owning service so its guards cannot be bypassed.

Four providers cover eight work types:

Provider Types
PickWorkProvider (fulfillment) PICK
ReceivingWorkProvider (orders) RECEIVE
CountWorkProvider (stocktaking) COUNT
TransportWorkProvider (tasks) PUTAWAY, MOVE, REPLENISH, TRANSFER, CROSS_DOCK

WorkItem is a live read shape, never persisted (karyo-work-api/.../dto/WorkItem.kt, WorkItem). WorkRef is the cross-type identity, serialised as TYPE:id and parsed back on every claim (WorkRef).

Two WorkItem fields are populated by only some providers, and both KDocs say so rather than pretending otherwise:

  • primaryLocationId - null for PICK, because a pick order has no location of its own. That has a behavioural consequence spelled out at the same site: a null location means the item is excluded whenever ?workingAreaId= is applied, "deliberately: an operator scoped to a working area shouldn't be shown work with no known location" (WorkItem.primaryLocationId). So filtering the inbox by working area hides every pick. The one exception: while the Facility's dispatch orders work by position (see Proximity dispatch), PickWorkProvider fills it with the location of the pick order's first open pick in sequence, and the filter then keeps those picks (PickWorkProvider.firstPickLocations).
  • travelOrder - populated only by CountWorkProvider, and read only by TRAVEL_PATH dispatch (WorkItem.travelOrder).

Dispatch

WorkDispatchService.poolFor (.../service/WorkDispatchService.kt, WorkDispatchService.poolFor) resolves the operator's eligible types, asks every provider that overlaps them for its open items, narrows by working area, and hands the merged list to the active WorkDispatchStrategy to order.

getNext (WorkDispatchService.getNext) walks that ordered pool and claims the first item that does not throw WorkClaimConflictException, skipping anything it lost a race for. That is why every provider translates its own module's refusals - wrong state, paused, not found - into that one exception type: anything else would abort the dispatch loop rather than skip a candidate (.../tasks/messaging/TransportWorkProvider.kt, TransportWorkProvider.claimOrConflict).

Dispatch strategies

Selected by name, not by priority, for each Facility: karyo.work.dispatch-strategy, default STRICT_PRIORITY. It is a Facility setting of the runtime configuration store (group Work dispatch), so it resolves Facility, Business Unit, Company, then the installation's KARYO_WORK_DISPATCH_STRATEGY (.../service/WorkDispatchConfig.kt, WorkDispatchConfig), then the catalogue default. A Facility that never sets it keeps the installation's strategy (.../service/DispatchEnvironment.kt, RuntimeDispatchEnvironment).

  • STRICT_PRIORITY - priority DESC, createdAt ASC (.../service/StrictPriorityDispatchStrategy.kt, StrictPriorityDispatchStrategy).
  • TRAVEL_PATH - travelOrder NULLS LAST, priority DESC, createdAt ASC (.../service/TravelPathDispatchStrategy.kt, TravelPathDispatchStrategy). Opt-in. Items without a travel order sort after those that have one and then fall back to the strict ordering among themselves, "so a mixed pool ... degrades to StrictPriorityDispatchStrategy's behavior for the items this strategy has no spatial opinion about, rather than scattering them arbitrarily" (TravelPathDispatchStrategy).
  • PROXIMITY - the highest priority band, then the nearest walk from the operator, then createdAt (.../service/ProximityDispatchStrategy.kt, ProximityDispatchStrategy). Opt-in twice: see below.

Selection by name rather than by priority is deliberate, and it changes what deploying an extension does: priority-based resolution would let "ANY custom strategy under Int.MAX_VALUE silently win" (WorkDispatchService.strategy), so a lower-priority bean could take over the default just by being deployed. An unmatched name is a hard failure - error(), uncaught - rather than a silent fallback to some other registered strategy.

That failure is checked at boot for the installation's value, because it is deployment config fixed for the process lifetime (WorkDispatchService.validateOnStartup). A name a Facility stores is resolved at dispatch time, and the catalogue refuses any name but STRICT_PRIORITY, TRAVEL_PATH and PROXIMITY, in any letter case, so a custom strategy is selected by the environment value alone. Duplicate strategy names also fail boot, since two beans sharing a name would resolve in CDI discovery order.

Proximity dispatch

PROXIMITY interleaves work by where the operator stands (ADR 0063). It is used only when both hold for the Facility: its karyo.work.dispatch-strategy is PROXIMITY, and karyo.proximity.enabled is on (off by default). With proximity off, a Facility that selected PROXIMITY dispatches as STRICT_PRIORITY (WorkDispatchService.strategy). STRICT_PRIORITY and TRAVEL_PATH never read the operator's position or the proximity setting.

  • The pool is the operator's. Eligibility is unchanged: DefaultWorkEligibilityResolver and the ?type= and zone narrowing decide which types are in the pool, so the interleave spans exactly the types the operator's work groups allow and never offers an excluded one (a REPLENISH task is not offered to an operator whose groups exclude REPLENISH, however near it is).
  • Order. The strategy ranks by priority band, the set of items with one priority value. Inside the top band it ranks by walk metres from the operator, measured by the one distance service (ADR 0060), then by createdAt. A higher priority still wins over a nearer task. An item with no place on the floor follows the measured items of its band, oldest first.
  • The wait limit. An item that has waited longer than karyo.work.proximity.max-wait-minutes (Facility setting, group Proximity; default 30, minimum 1; environment KARYO_WORK_PROXIMITY_MAX_WAIT_MINUTES) 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. An item exactly at the limit has not waited longer.
  • Where the operator stands. work-core keeps one position per operator and Facility (operator_positions, OperatorPositionService). It is the location of their last confirmed task: the destination of a completed transport order (putaway, move, replenishment, transfer, cross-dock), the source of a confirmed pick, the counted location of a submitted count, the dock of a goods receipt they received a line on. The floor app's optional I am at scan (PUT /api/v1/work/position) writes the same row, so the later of the two stands. With no position, dispatch measures from the depot, the first Area's entry. A position is kept only while the Facility orders work by position, and it does not expire; it stays until the next confirmation or scan.
  • Picks. PickWorkProvider gives a pick order the location of its first open pick in sequence, so a pick is placed where its picker starts it (WorkFilter.withLocations, set only for a position-aware strategy).

GET /api/v1/work/positions returns every operator whose position was recorded in the last 12 hours, by name, for the floor view; it needs work.positions.read, which the Manager profile holds.

GET /api/v1/work/position returns active (true while the Facility dispatches by position), the location and name, its source (CONFIRMATION or SCAN) and when it was recorded. PUT takes {"locationId": ...}; a location outside the Facility is 422 invalid-reference. The flow projection builds the same context from its simulated operator (flow model).

Eligibility

DefaultWorkEligibilityResolver (.../service/DefaultWorkEligibilityResolver.kt, DefaultWorkEligibilityResolver):

  • a tenant with no work groups configured - the operator is eligible for all work types ("system open until configured");
  • otherwise - the union of work types across the operator's group memberships, and a non-member sees nothing.

Groups store their types as a comma-joined string and resolve calls WorkType.valueOf on each element. The REST layer validates the names on create (validateWorkTypes, .../api/v1/WorkInboxResource.kt, WorkInboxResource.validateWorkTypes), so this only bites if the column is written another way or an enum value is later removed - the same class of trap JournalRecordType's KDoc warns about for its own codes.

Claiming

Every route that claims is gated on the work.claim action and then on the work type's own write action in the Facility of the request.

POST /api/v1/work/{ref}/claim declares work.claim, then calls requireWriteAction(workRef.type) in the body to enforce the actual action for that type, and additionally refuses a type the operator is not eligible for.

POST /api/v1/work/next declares work.claim and narrows the pool to the types whose write action the caller holds in the Facility, intersected with the requested type. A caller holding no type's write action - the standard viewer profile, for example - gets 403. dispatch.getNext then claims the best available item of those types.

The per-type map gates claim, release and next, fail-closed:

private val WRITE_ACTION_BY_TYPE: Map<WorkType, String> = mapOf(
    WorkType.PICK to Actions.FULFILLMENT_WRITE,
    WorkType.RECEIVE to Actions.ORDERS_WRITE,
    WorkType.COUNT to Actions.INVENTORY_WRITE,
    WorkType.PUTAWAY to Actions.TASKS_WRITE,
    WorkType.MOVE to Actions.TASKS_WRITE,
    WorkType.REPLENISH to Actions.TASKS_WRITE,
    WorkType.TRANSFER to Actions.TASKS_WRITE,
    WorkType.CROSS_DOCK to Actions.TASKS_WRITE,
)

Every WorkType is in the map, so the getValue lookup cannot miss. TransportWorkProvider.workTypes() includes CROSS_DOCK, so a cross-dock transport order is claimable work and needs tasks.write.

Release

POST /api/v1/work/{ref}/release (WorkInboxResource.release) declares work.claim, applies the same per-type gate, then computes asManager as whether inventory.write holds in the Facility of the request (WorkInboxResource.release) and hands it to the provider. Each module's own release honours it - a non-owner needs manager authority, otherwise 409, never 403. Note the manager check is a different action from the per-type write action, so for a PICK the caller needs fulfillment.write to release at all and inventory.write to force-release someone else's.

A stale note

ReceivingWorkProvider's class KDoc still says the inbox gates claim/release uniformly at the inventory-read/inventory-write roles for every work type, and describes the resulting viewer-can-claim-a-receipt asymmetry as a pre-existing, inbox-wide design posture (.../orders/messaging/ReceivingWorkProvider.kt, ReceivingWorkProvider.workTypes, ReceivingWorkProvider.listOpen).

The per-type action map gates claim and release instead, and no provider role is authority (ADR 0048), so the KDoc describes behaviour the code does not have. It is still accurate about /next, though for a different reason than it gives.