ADR 0035: Warehouse setup identifies an aisle by zone and aisle-role text
Status: Accepted.
Context
Warehouse setup lets a goods owner create locations by typing a label range (A-01-1-1 to
A-20-1-1) or pasting a list, then Create writes every new label in one transaction. A create can
be submitted more than once under different idempotency keys: the same aisle can be extended
later, re-typed in full, or re-typed with a different face count. Two invariants must survive all
of that: an existing row is never rewritten, and no two different bay-and-within-bay-position
pairs ever share a (zone, run, along) triple, because run (yPos) is the physical aisle line
put-away distance reads and along (xPos) is that pair's place along it, one step per bay and
per within-bay position exactly as the label reader computes it. Only the levels of the same
bay and within-bay position legitimately share one (run, along) pair; along identifies a bay
and a within-bay position, not a level.
The first seeding attempt offset every new location's planned run by a zone-wide amount. That
broke as soon as a second create only re-submitted the new bays of an aisle that already existed
(A-11..A-20 alone, after A-01..A-10 was already stored): with nothing in the new plan
overlapping a stored label, the aisle looked brand new and was stored as a second, overlapping
aisle at a different run.
Decision
- An aisle is identified by
(zone, rack), whererackis the aisle-role text the label reader already extracts (e.g."A"). Two submissions that name the same zone and the same aisle text are the same aisle, whether or not their labels overlap. - A planned run that already holds a stored label keeps that stored run. Found by checking,
per
(zone, plannedRun)group in the new plan, whether any member's name is already stored; when it is, the group's run becomes that label's actual stored run, not the plan's own numbering. - A planned run with no stored label, but whose aisle already has an unclaimed stored run, extends that run. When more than one unclaimed stored run exists for the aisle, the planned run is matched to the stored run whose bays share its absolute bay parity (odd bays to odd, even to even), read from one stored row's bay text per run; only when no stored run shares that parity, or the bay text carries no usable digits, does it fall back to the lowest-numbered unclaimed run. A run already claimed by the rule above is not offered a second time in the same create, so retyping a single-face aisle with both faces gives at most one of the two new face-groups the old run; the other gets a fresh one.
- New bays of an extended run continue its along numbering past the stored maximum. Their shift is the stored maximum minus the smallest planned along among the run's new members, applied uniformly, so every new bay and within-bay position continues the stored numbering with the same per-bay, per-position steps the reader already computes, instead of each new bay restarting the count. Only the levels of the same new bay and within-bay position share the resulting along value. Every other new location keeps the plan's own along numbering (a full resubmission's own along-counter is already continuous, and a brand-new run has no stored maximum to continue).
- A planned run whose aisle has no stored data, or that finds no unclaimed stored run, gets a run above the zone's current maximum, in ascending planned order.
- A location that already exists never has its stored run or position touched. Its own
stored
(run, along)pair is read directly, by name, and used verbatim in the response; the extension/fresh-run rules above only ever apply to a location that is about to be inserted. - The same lookup drives the create response and the idempotency-key replay response. Replay treats every planned location as already stored, so it always resolves through the by-name direct lookup, never through the extension or fresh-run rules; one key therefore always returns the same preview.
Consequences
- Extending an aisle in a separate submission, re-typing it in full, and adding a genuinely new
aisle to a zone that already has one, all leave exactly one row per label and no two different
bay-and-within-bay-position pairs sharing a
(zone, run, along)triple. - Per zone this costs one query for the zone's stored maximum run and one query per distinct rack touched by the plan (not per location), in addition to the existing by-name lookup for already-stored labels.
- Retyping a single-face aisle with both faces cannot always tell which of the two new face-groups is "the same" physical face as the one already stored; the rule above is a deterministic tie-break (first claimed wins the old run), not a claim that the geometry is labelled the way a human would necessarily choose. Neither invariant above depends on getting that particular choice "right".
Alternatives considered
- Offset every new location's planned run by the zone's maximum run. Rejected: this was the first implementation and is exactly the bug this record fixes - it does not look at whether an aisle already has stored data, only at whether the specific label already exists.
- Identify an aisle by parity-based face index instead of
(zone, rack). Rejected:expand's face index is(bay - firstBay) % 2, relative to each submission's own first bay, so it is not stable across two separate submissions of the same aisle.
Evidence
services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/service/WarehouseSetupService.ktseedRuns- the run/position mapping this record describescreate- both call sites (first create and idempotency-key replay) share the one mapping
services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/repository/WarehouseSetupRepository.ktactualPositions- by-name stored(run, along)lookupaislePositions- per-(zone, rack)stored runs, their maximum along, and one stored bay's text per run for parity matching
services/karyo-app/src/test/kotlin/com/karyo/layout/service/WarehouseSetupCreateTest.kt- the extension, retype, both-faces and brand-new-aisle cases
Related
- ADR 0007 - the same "look up the real row, do not recompute it" discipline applied within one module's own table