0054. Tote containers, stock per container and container-aware allocation
Status
Accepted (2026-11-20). Additive: no existing route, event, field or column
changes meaning. Builds on ADR 0045
and ADR 0046
(Container and LPN), ADR 0013
(facility events as a local read model), ADR 0025
(pick location on allocations) and ADR 0053.
Amends ADR 0050 for units held
in a container only. Records the inventory-storage row of the WCS design
(warehouse-docs docs/wcs/ecosystem-impact.md, seam decisions 1 and 2) and answers
its open question "Container id format and who prints labels".
Context
The WCS (material-flow-control, asrs-control, amr-fleet-control) moves containers:
it retrieves container C from the AS/RS to a station and stores it back. Seam
decision 1 makes this context the owner of the container: "its id, its contents and
its logical location. The WCS references the id only." Seam decision 2 makes each
AS/RS one logical location: "inventory-storage records that container C, with its
contents, is in that location. Rack positions stay inside asrs-control."
This context already has a Container (ADR 0045): a sealed case, one SKU, one
fixed quantity, linked 1:1 to a SEALED_CASE stock unit, never reused, keyed by
its LPN (the SSCC, or inbound-receiving's internal LPN-<site>-<id>). The AS/RS
stores totes: reusable bins, filled at a decant station with any SKUs, picked
from at a goods-to-person station and returned, many times.
Decision
- The container id is the LPN. One license-plate namespace: the existing rule
^[A-Za-z0-9._-]{1,64}$, unique across sealed cases and totes through alicense_platesregistry (primary keylpn,kindCASE or TOTE) claimed in the unit of work that registers either. AcontainerIdin any WCS message is such an LPN. - Labels. This service mints no LPN and prints nothing. A tote is labelled once
when commissioned (pre-printed by the supplier, or printed by the floor client
from the LPN as CODE128) and registered with
PUT /totes/{lpn}. A carton keeps its SSCC label or inbound-receiving's internal LPN label (ADR 0045). Toteis its own aggregate (internal/domain/container/tote.go):lpn,siteId(set at the first placement, then fixed),binId(its logical location),version(ADR 0019). It is not a kind ofContainer: the RESTContainerschema requiressku,gtin,unitsPerPack,qtyEaches,receiptId,lineNo, and making them optional is a breaking response change.- Stock per container. A
StockUnitcarries an optionalcontainerLpn. A tote's contents are LOOSE units in the tote's bin tagged with the tote. EverySEALED_CASEunit is tagged with its case's LPN (backfilled). A unit never changes container; eaches stay the ledger unit. - Commands.
RegisterTote—PUT /totes/{lpn}: 201 when created, 200 when the tote exists;409 license-plate-takenwhen the LPN is a sealed case. EventToteRegistered.FillTote—POST /totes/{lpn}/fills {sku, quantity, ownerRef?}: a stow into the tote (item scan + tote scan): the same placement checks, capacity check and events asPOST /stowages(ItemStowed,LocationRecorded,BinStockLevelChanged) plusToteFilled, at the tote's current bin. A tote in no bin:409 tote-not-placed.StowTote—POST /totes/{lpn}/stowages {bin}: moves the tote and every unit in it tobinin one unit of work (occupancy in eaches,BinStockLevelChangedfor both bins,LocationRecordedper unit,ToteStowed). Same bin: no-op. Another site:409 container-not-at-site. A tote holding reserved stock:409 tote-reserved(the allocation names the pick location, ADR 0025).- Reads:
GET /totes/{lpn}(tote with its contents),GET /bins/{binId}/totes.
- Allocations name their container.
AllocationgainsContainerLPN(reservation_allocations.container_lpn, RESTallocations[].containerId, omitted when empty) for every draw from a unit in a tote or a sealed case. - Container-aware draw (amends ADR 0050, units in a container only). After the forward pick faces, when they do not cover the request, the first unit in ADR 0050 order that is in a container and whose usable quantity covers the whole remainder is drawn next: one retrieval instead of several. A SKU with no container stock is ordered exactly as ADR 0050.
- No loose stock in an
AutomatedStoragebin. The facility cache keeps each slot'slocationTypefromLocationSlotRegistered(already published). A loose stow, a relocation into, a case break into and a transfer stow into a bin whose type isAutomatedStorage(facility-layout ADR 0048) is refused409 automated-storage-requires-container. An unknown type keeps today's behaviour (fail open, as ADR 0013). A sealed case (POST /containers/{lpn}/stowages) and a tote are containers and are accepted. - Events (CloudEvents 1.0, outbox,
warehouse.inventory.events, subject = key =lpn,datasnake_case,dataschema urn:warehouse:inventory-storage:events:<Event>:v1):
Type com.warehouse.wms.inventory-storage.tote.<Event> | data |
|---|---|
ToteRegistered | lpn, at |
ToteFilled | lpn, sku, qty_eaches, owner_ref?, site_id, bin, stock_unit_id, at |
ToteStowed | lpn, site_id, from_bin?, bin, contents[{sku, qty_eaches, owner_ref?}], at |
- Carton linking. A received carton whose LPN is already a tote is REJECTED
as
LPN_REGISTERED_AT_ANOTHER_RECEIPT_LINE(never merged), exactly like a duplicate SSCC (ADR 0046).
Amendment (2026-11-21): what the build settled
Recorded after the WCS plan 05a reviews; each point states behaviour the code on
develop has and names the test that pins it.
PUT /totes/{lpn}stays idempotent under concurrency. Two registrations of the same new LPN can both read "no tote" and race on thelicense_platesprimary key. The loser's claim waits for the winner's transaction, then finds the plate held by a TOTE and the tote row present: it re-reads and answers the winner's tote withcreated=false(200). Exactly oneToteRegisteredis raised.409 license-plate-taken(FINAL, ADR 0053) is answered only when the plate is held by a sealed case. Tests:TestConcurrentRegisterToteOfOneNewLPNAnswersTheExistingTote,TestRegisterToteLosingThePlateToASealedCaseIsLicensePlateTaken(use case) andTestConcurrentRegisterToteOverPostgresAnswersTheExistingTote(Postgres, one unit of work per racer).- Rejection reason reuse (decision 10). A carton whose LPN is a tote is rejected
with the existing reason
LPN_REGISTERED_AT_ANOTHER_RECEIPT_LINE. No new reason value is added, so no consumer of the rejection sees an unknown value. Read the reason as "this LPN already names another container"; the name dates from ADR 0046, when the only other holder was a receipt line. - One plate, one owner, in one transaction.
ToteRepo.AddandContainerRepo.Addclaim the plate inlicense_platesand insert their row in the same transaction: the use case's unit of work when one is active, otherwise a transaction of their own (claimAndInsert). A failed insert leaves no plate claimed. Tests:TestToteAddClaimRollsBackWithAFailedInsert,TestCaseAddClaimRollsBackWithAFailedInsert,TestLicensePlateClaimRollsBackWithTheUnitOfWork,TestOneLicensePlateNamespaceAcrossCasesAndTotes. The reads that come before the claim (RegisterTotelooking for a sealed case, the carton linker looking for a tote) are only checks: the claim decides. When a carton loses the claim to a tote registered between the linker's read and its insert, the pending link is dropped without the rejection of decision 10, as when a redelivered case loses (ADR 0046). No plate gets two owners; only the rejection record is missing. - Rollout window of migration 0042. The migration backfills a CASE plate for every
existing
containersrow. During a rolling deploy a pod still running pre-0042 code can register a sealed case after the backfill, and that case gets no plate. A laterPUT /totes/{lpn}of that LPN is still refused, becauseRegisterTotereadscontainersin the same unit of work. Only a tote registered at the same moment as such a case can take its LPN. There is no code defence: one morecontainersread insideToteRepo.Addwould be the same check-then-act read, because pre-0042 code takes no lock onlicense_plates. Once the last pre-0042 pod is gone, close the window by re-running the backfill (INSERT INTO license_plates (lpn, kind) SELECT lpn, 'CASE' FROM containers ON CONFLICT (lpn) DO NOTHING) and check thatSELECT lpn FROM containers JOIN totes USING (lpn)returns no row. StowToterefusal precedence. Every refusal is checked before the same-bin no-op and before any write, unit by unit:tote-reservedwhen the unit is reserved,unit-heldorunit-unlocated, then the placement rules of its SKU at the destination. So stowing a tote into the bin it is already in answers 409 when one of its units is reserved, held or unlocated, instead of the no-op of decision 5. A held unit going into a full destination answersunit-held, notbin-full. The route is new in this ADR, so no existing caller changes behaviour.
Not in this change
- Moving a container from
TaskCompleted. The WCS putaway ends with fulfillment-execution'sTaskCompleted(context map relationship 9); its payload carries no container today. Proposed for the fulfillment-execution ADR-0015 amendment (WCS plan 05b): an optional snake_casecontainer_idonTaskCompleted; with it andto_binthis context callsStowTote(putaway) or draws the relocation from that container's unit (replenishment). Until then the move is the REST command above. - MCP and A2A tools for totes (warehouse-ops-agent pins the MCP registry; they come with the read-only container-position views of the ecosystem-impact row).
- Lot and expiry on tote contents (a fill carries none; FEFO is out of scope as in ADR 0045).
Consequences
- The WCS can address any license plate this context knows; a sealed case stored in
an AS/RS that handles cartons works with the existing
POST /containers/{lpn}/stowages. - Two aggregates share one id space; the registry makes the uniqueness a database fact. A tote and its units are written in one unit of work.
- Allocation from automated storage prefers one container per request; ADR 0050's forward-first and tie-breaking rules are unchanged.
- An
AutomatedStoragebin can only be filled through a tote or a sealed case; inventory control must register the AS/RS bin (PUT /bins/{binId}) with a capacity in eaches large enough for the AS/RS. - Consumers of
warehouse.inventory.eventsdispatch on the full type; the three new types are ignored by each of them (proved in the PR description).
Alternatives considered
- A
kindonContainer. Rejected: invariants differ (one SKU and a fixed quantity vs any SKUs and a varying quantity) and the REST schema cannot carry a tote without a breaking change. - The WCS owns container ids. Rejected by seam decision 1 (the WCS must never know contents).
- Mint
TOTE-<ulid>here. Rejected: totes are labelled once for life, before they ever hold stock; an id issued here would still need a printed label, and ADR 0045 keeps this service out of identity minting. - Hold rack positions as bins. Rejected by seam decision 2: every reshuffle would be a stock transaction.