Strategies and policies
Karyo has two strategy tables an administrator edits: order_strategies and
storage_strategies. Between them they carry most of the behavioural policy a deployment
tunes - how stock is chosen, whether an order parks in PACKING, where a pallet is put away,
whether waves release themselves. Both are reachable from Strategies in the operational
shell (frontend/web/src/pages/strategies/).
What each flag does to the algorithms belongs to allocation and reservation, picking and putaway and location finding. This document is about the configuration surface: what is a column and what is loose JSON, how a strategy gets bound to work, and what an administrator cannot do. The decision behind the strategy pattern is ADR 0018.
The two tables do not agree on tenancy
OrderStrategy extends BaseEntity and carries no business_unit_id. Its KDoc gives the reason:
"System-level order configuration (no clientId - silo tenancy makes the company implicit)"
(services/order-service/karyo-orders-core/src/main/kotlin/com/karyo/orders/domain/model/OrderStrategy.kt, OrderStrategy).
StorageStrategy extends FacilityEntity and is per Facility
(services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/domain/model/StorageStrategy.kt, StorageStrategy).
Both readings of silo tenancy are defensible on their own; together they mean a 3PL can give
Facility A a different putaway policy from Facility B, but cannot give goods owners different
order-handling policies. The ordering resolver makes the asymmetry visible:
OrderStrategyContext carries the order's Facility, which the built-in resolver never reads
(services/order-service/karyo-orders-api/src/main/kotlin/com/karyo/orders/spi/OrderStrategyResolver.kt, OrderStrategyResolver;
services/order-service/karyo-orders-core/src/main/kotlin/com/karyo/orders/service/DefaultOrderStrategyResolver.kt, DefaultOrderStrategyResolver).
The seam for per-Facility order strategy exists and is unused. Why the two tables differ is not
recorded, and the code does not settle it.
Pick source order
The order strategy's Pick source order (pickSourceOrder) defaults to FIFO for existing and
new strategies. Same-day nearest (SAME_DAY_NEAREST) orders eligible sources within the same
rotation day by their shortest walk from the depot or the order's earlier picks. Older days
always win. It applies only when the Facility enables karyo.proximity.enabled, which stays off
by default; otherwise selection keeps exact FIFO. Matching preference and complete handling retain
their precedence. This option is independent of the pick route below.
See Stock selection for day boundaries, anchors and fallbacks.
Proximity pick routes
The order strategy's Proximity pick route option (proximityRoute) defaults to off. It affects
new pick orders only when the Facility also enables karyo.proximity.enabled. Karyo walks those
picks nearest neighbour from the first Area's entry, using lift metres to break walk ties. Unplaced
locations follow in their configured walking order. A cross-order wave batch uses the route only
when every contributing order requests it; otherwise its old order stays unchanged.
See Picking for the saved sequence and later additions.
Work dispatch strategy
Dispatch is a third strategy a Facility chooses, though it is a runtime setting and not a table. The
setting karyo.work.dispatch-strategy (group Work dispatch) names the WorkDispatchStrategy that orders
the work Get next task offers: STRICT_PRIORITY (the default), TRAVEL_PATH or PROXIMITY. A Facility
that never sets it uses the installation's KARYO_WORK_DISPATCH_STRATEGY. PROXIMITY ranks by priority
band, then the walk from the operator, then age, and a wait limit
(karyo.work.proximity.max-wait-minutes, default 30) moves old work up one band. It is used only while the
Facility also enables karyo.proximity.enabled; otherwise the Facility dispatches as STRICT_PRIORITY.
See Work allocation and
ADR 0063.
How each strategy is bound
The two use different mechanisms, and the difference matters at commissioning time.
An order strategy is bound to an order, by id, resolved through a priority chain of
OrderStrategyResolver beans where the first non-null name wins and the built-in registers
last (OrderStrategyResolver). The built-in returns the order's own
orderStrategyId, or the seeded DEFAULT when the order names none
(DefaultOrderStrategyResolver). Every installation has a DEFAULT row: it is
seeded by migration, idempotently
(services/karyo-app/src/main/resources/db/migration/orders/V405__seed_default_order_strategy.sql).
So order strategy always resolves to something, and an administrator who configures nothing
still gets coherent behaviour.
A storage strategy is bound to a product, with a Facility default. The finder takes the
request's explicit storageStrategyId if there is one, and otherwise the incoming stock's
product-level ItemData.defaultStorageStrategyId, read from the product's policy in the Facility
being searched
(services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/service/LocationFinderService.kt, resolveStrategy).
When neither rung produces one, it takes the Facility default strategy: the one row of the
Facility with facility_default, seeded by migration for every active Facility
(services/karyo-app/src/main/resources/db/migration/layout/V1608__facility_default_storage_strategy.sql)
and created for a later Facility by Warehouse setup or its first putaway search
(services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/service/StorageStrategyService.kt, StorageStrategyService.facilityDefault).
It is named Facility default, its only sort key is TRAVEL_DISTANCE, and every other field has
its default (ADR 0061).
So storage strategy, like order strategy, always resolves to something in an active Facility.
A product still binds its own policy, so a policy that differs from the Facility default is
configured product by product. An administrator who wants one policy for the whole Facility
edits the Facility default instead of stamping defaultStorageStrategyId onto every product. The
console marks the Facility default with a Default badge on Strategies, and its form says
when putaway uses it. A product's Facility zone also steers putaway, as the second rung of the zone
order, but only while the Facility's karyo.proximity.enabled setting is on
(the zone).
A mistyped strategy id is refused
Writing a product checks the three ids it carries into other modules. ProductService.createProduct
and ProductService.updateProduct refuse an unknown defaultUnitLoadTypeId, and
ProductFacilityPolicyService.apply refuses a defaultStorageStrategyId or zoneId that the
Facility does not have, all with 422 invalid-configuration
(services/product-service/karyo-product-core/src/main/kotlin/com/karyo/product/service/ProductFacilityPolicyService.kt, ProductFacilityPolicyService.apply).
The check asks the owning module through ProductPlacementLookup and ProductUnitLoadTypeLookup. A
value the product already holds is not asked again, so saving an old product with a stale id does
not fail until that field changes.
Downstream, resolveStrategyById still returns null for a missing row and for a strategy of another
Facility, and logs nothing in either case (StorageStrategyRepository.findInFacility). Both cases
are described as "fail-closed", which is the right instinct for a putaway that must not use
another Facility's policy. A strategy that existed when it was stored and was removed later still
leaves a putaway on the Facility default, but a typo no longer reaches it.
What is a column, and what is loose JSON
OrderStrategy has fifteen typed columns and one JSONB column called extension_properties,
described as "the relief valve for extension config instead of new columns"
(OrderStrategy). The relief valve carries shipped product behaviour.
Fourteen product-owned keys remain in the map. Karyo validates them on create and update; the configuration reference lists their accepted values. Runtime readers retain the following defaults for old stored rows:
| Key | Read at | Default |
|---|---|---|
releaseMode |
messaging/StreamingConfigParser.kt, StreamingConfigParser |
MANUAL |
streamBatchSize |
StreamingConfigParser |
50, clamped 1..1000 |
streamMaxWaitSeconds |
StreamingConfigParser |
30 |
streamAbandonSeconds |
StreamingConfigParser |
1800, floored at max-wait |
streamTimingStrategy |
StreamingConfigParser |
time-size |
waveAutoRelease |
messaging/DefaultOrderReleasePort.kt, DefaultOrderReleasePort.parseConfig |
false |
waveMaxOrders |
DefaultOrderReleasePort.parseConfig |
200 |
wavePickMode |
DefaultOrderReleasePort.parseConfig |
HYBRID |
waveShortageAction |
DefaultOrderReleasePort.parseConfig |
SKIP |
waveSelectionStrategy |
DefaultOrderReleasePort.parseConfig |
due-date-priority |
waveDueWithinDays |
DefaultOrderReleasePort.parseConfig |
none |
waveMinPrio |
DefaultOrderReleasePort.parseConfig |
none |
waveIncludeUndated |
DefaultOrderReleasePort.parseConfig |
true |
waveSelectionRuleId |
DefaultOrderReleasePort.parseConfig |
none |
Defaults are declared on WaveStrategyConfig and StreamingStrategyConfig
(services/order-service/karyo-orders-api/src/main/kotlin/com/karyo/orders/spi/OrderReleasePort.kt, OrderReleasePort).
The keys are parsed in the orders module, but what they tune - wave release and order
streaming - is done by the wave and streaming engines, which are part of the distribution and act
on every installation
(engine capabilities).
OrderStrategyService checks the map before a create, or an update that sends extensionProperties, takes effect.
A misspelled waveAutorelease is refused with 422 order-strategy-invalid-extension, not stored
and ignored. Custom keys must start with ext.; their extension owns value validation. Existing
stored strategies are unchanged and keep their runtime behaviour until a request sends their map.
An update that omits extensionProperties leaves the stored map unchecked and unchanged.
The admin UI reflects the split honestly rather than hiding it. Five of the fourteen keys -
releaseMode and the four streaming knobs - have typed controls, and the form comments that
those five "own their keys and always win over anything left in the free-form JSON textarea"
(frontend/web/src/pages/strategies/order-strategy-form.tsx, OrderStrategyForm). The remaining nine wave
keys use the JSON textarea. A refused save shows the server's message in a toast, named after the
action, from the API client; the form does not route it to a field. The API shape
stays the same; the fourteen keys do not become typed columns or system properties.
One behaviour worth knowing before promising anything: the form writes the four streaming keys
whenever releaseMode is STREAM. When it is another mode, the form still writes a key the strategy
already carries, and a key whose value was changed from its default
(order-strategy-form.tsx, OrderStrategyForm). An administrator who tunes streaming, switches a
strategy to MANUAL for a week and saves, keeps the tuning. A strategy that never had a streaming key
saves none under another mode, and the parser reads the documented defaults for a missing key. Earlier
releases dropped the four keys from the saved map under any mode but STREAM.
Storage strategy flags
StorageStrategy carries eight behavioural fields (StorageStrategy). Two of them,
useAreaStrategyDate and useItemDataArea, once carried the comment "Column only in this task;
finder behavior lands in Task 3". The comment is gone, because both flags are live. Both are read by the finder, threaded into AreaOccupancyReader for
cross-area FIFO hiding and full-area hiding, and used by CandidateOrdering to prepend area
order and to suppress a redundant STORAGEAREA sort key
(LocationFinderService.applyAreaConstraints, service/AreaOccupancyReader.kt, AreaOccupancyReader.resolve,
service/CandidateOrdering.kt, CandidateOrdering.apply). There are dedicated tests for each
(services/karyo-app/src/test/kotlin/com/karyo/layout/service/LocationFinderAreaTest.kt, LocationFinderAreaTest.suffix).
manualSearch short-circuits the finder to no location found before any candidate query,
so putaway falls back to manual placement (StorageStrategy).
The inert onlyClientLocation flag is removed; every candidate belongs to the named Facility.
sorts is a free-text comparator chain parsed by StorageStrategySortParser, and it is the one
free-text strategy field that is validated: an unknown token is refused with
LayoutException.InvalidSortTokens -> 400
(service/StorageStrategySortParser.kt, mapped at exception/LayoutExceptionMapper.kt, LayoutExceptionMapper).
The JSONB knobs above now also validate on write. The tokens
are the names of StorageStrategySortType, in any case. TRAVEL_DISTANCE (code 9) ranks by the
walk from where the unit load stands, and the console offers it first as Travel distance
(nearest first). What it measures, and the Facility setting that turns proximity on, is in
putaway and location finding.
Neither strategy can be deleted
OrderStrategyResource exposes list, get, create and update
(api/v1/OrderStrategyResource.kt, OrderStrategyResource). StorageStrategyResource exposes list, get, create,
update, and get/set of the ordered area list (api/v1/StorageStrategyResource.kt, StorageStrategyResource).
Neither service has a delete method.
The built-in order resolver nevertheless guards against a deleted strategy: "The id is
validated at write time ..., so a miss here means a since-deleted strategy: deliberately fall
back to DEFAULT rather than fail a pick" (DefaultOrderStrategyResolver). The
reasoning is sound and the fallback is the right one - but no route in the product can produce
the condition it defends against. Either the guard anticipates a delete route that does not
exist, or the route was removed and the guard stayed; nothing in the code or its documents says
which.
The practical effect for an administrator is the same either way: a strategy created by mistake during commissioning is permanent.
Related
- Warehouse layout configuration - the layout a storage strategy searches
- Reference data - the product fields that bind a storage strategy
- Strategies and runtime configuration - strategy seams an extension can fill
- ADR 0018 - strategy-driven configuration