0052. Held stock and disposition
Status
Accepted
Context
ADR 0037 books only condition=Good lines of inbound-receiving's
ReceiptLineReceived. A Damaged line is claimed, logged and counted
(inventory.inbound_receipt_units{outcome=damaged_not_booked}) and then
vanishes from the inventory view: nobody owns the units and nothing says
whether they go back to the vendor, are scrapped, reworked or released. ADR
0037 and ADR 0045 both name "quarantine is a later ADR". Competing WMS treat
quarantine (hold) plus a disposition as table stakes. This is feature IF-6 of
the inbound-receiving evolution plan (Q8) and the foundation for the later
QC-pending hold (IF-7).
Decision
-
A new stock state
HELD(stock.StateHeld, next toStateUnlocatedandStateRemoved).- A held unit has
Usable() == 0andReserve*returnsErrUnitHeld, exactly like an unlocated unit. Every guard that rejectsStateUnlocated/StateRemoved(AddQuantity,MoveTo,RelocateOut,ReserveWhole,CanReserveWhole) rejectsStateHeldas well. - Held stock lives in its own aggregate and table. A hold has no bin
(the goods are in the receiving or quarantine area, not stowed), so it is
not a
stock_unitsrow. TheHeldUnitaggregate (internal/domain/stock) is persisted inheld_stock(migration 0041) and is invisible to everyStockRepoquery by construction. TheStateHeldguards onStockUnitand theHELDexclusion in the bin-level SQL are defence in depth: aHELDrow that ever reachedstock_unitsstill would not be promised or counted.
- A held unit has
-
A held unit carries a reason and its source. Reason is the closed set
DAMAGED,QC_PENDING,SUSPECT,OTHER. Source is the receipt id, the ASN number, the line number, the SKU and the quantity, plus the optionalowner_refandssccof the line (pack provenance, kept as for Good) and the carton LPNs recorded for the line (see 3). -
Booking.
BookInboundReceiptLinebooks aDamagedline as a held unit with reasonDAMAGEDinstead of dropping it. AGoodline is unchanged. The CloudEvents id claim, the held-unit save and the outbox write run in ONEUnitOfWork; a redelivered id is a no-op. Damaged carton contents.ReceiptCartonReceivednever books a quantity (ADR 0045: the line event is the sole quantity authority), so aDamagedcarton content does NOT open a second hold, which would count the same units twice. It records its provenance instead:LinkReceiptCartonwrites(receipt_id, line_no, lpn, sscc)intoheld_stock_carton_marks, idempotent on the CloudEvents id and independent of arrival order, and the list read joins the marks onto the held units of that line. -
Disposition, closed set, naming borrowed from returns-processing's
DispositionDecided(this service neither consumes nor calls returns-processing):Disposition Effect on the held unit Stock effect RELEASEleaves the hold (state REMOVED, disposition recorded)the quantity is received as a fresh staged receipt ( StockReceived): not usable until stowed, exactly like a Good lineRETURN_TO_VENDORREMOVED, disposition recordednone: the units leave the building SCRAPREMOVED, disposition recordednone REWORKstays HELD, reason updated (reasonin the request, defaultOTHER), rework count +1none Quantity is conserved: a disposition applies to the whole held quantity of the unit (no partial disposition in v1), so held plus disposed always equals the booked quantity. A
REMOVEDunit accepts no further disposition (ErrHeldUnitClosed, 409). The decision, the unit save and the events commit in oneUnitOfWork. -
Events on
warehouse.inventory.events, CloudEvents typecom.warehouse.wms.inventory-storage.stock.<Event>, key = subject = held unit id, additive (no existing payload changes):StockHeld{held_unit_id, sku, quantity, reason, receipt_id, asn_number, line_no, owner_ref?, sscc?, held_at}StockReleased{held_unit_id, sku, quantity, receipt_id, asn_number, line_no, released_at}StockDispositioned{held_unit_id, sku, quantity, disposition, reason, receipt_id, asn_number, line_no, decided_at}(raised for all four dispositions;StockReleasedis raised in addition onRELEASE).
All three also go to
warehouse.inventory.analyticswith the same type, like the sibling stock events (StockReceived,ItemStowed,ItemUnlocated); the projector ignores types it does not fold (a release shows in the report through theStockReceivedit raises), so no report changes. Inapis/asyncapi.yamleach message carriesx-no-consumer-reasonuntil a consumer exists. -
REST (fleet guideline, ADR 0049; RFC 9457 problems;
Idempotency-Keyon the POST):GET /held-stock(filtersreason,sku,olderThanHours, keyset paging) andGET /held-stock/{id};POST /held-stock/{id}/dispositions. -
MCP: one read tool
list_held_stockat authority L1. There is no write tool: the disposition stays REST only. The authority golden is updated. -
Metric
inventory.held_units{reason}: an up-down counter of units currently held, +quantity at hold, -quantity when the unit leaves the hold, and a move between reasons onREWORK. Thedamaged_not_bookedoutcome ofinventory.inbound_receipt_unitsis replaced byheld(a Damaged line is no longer dropped). -
Migration 0041, additive: new tables
held_stockandheld_stock_carton_marks. No existing row or table is altered.
Audit of every reader of usable quantity
A held unit must never be promised or counted as usable. Held units are not
stock_units rows, so each reader below that goes through StockRepo cannot
see them; the second column says what was checked and the verdict.
| Reader | Source of its numbers | Verdict |
|---|---|---|
StockUnit.Usable, Reserve, ReserveFor, ReserveWhole, CanReserveWhole, AddQuantity, MoveTo, RelocateOut | the aggregate | guarded: StateHeld returns 0 usable / ErrUnitHeld; unit tests |
ReserveStock (and ReserveFullCases) | StockRepo.FindBySKU / container units, sums Usable() | cannot see held units; a HELD unit would add 0 |
AllocateTransferStock (transfer allocation) | StockRepo.FindBySKUAtSite, sums Usable() | same |
allocation ordering (order.go) | Usable() of the loaded units | same |
GetUsable (GET /inventory/{sku}/usable, MCP get_usable, A2A check_availability) | StockRepo.FindBySKU | same: usable never includes held; held stock is read only through the new held-stock read |
RunCycleCount | StockRepo.FindByBin; skips UNLOCATED/REMOVED | extended to skip HELD; a held unit is not in a bin so a count never marks it unlocated |
RelocateStock / relocation domain | StockRepo.FindByBin, Usable() | cannot see held units; guarded by RelocateOut |
BreakCase, StowContainer, container unit exit | StockRepo.FindByID/FindByBin | present check extended to exclude HELD |
StowStock, StowTransferStock (bin capacity occupants) | StockRepo.FindByBin | held units occupy no bin capacity: they are not in stock_units |
ConfirmPick, reservation_expiry, RevokeReservation | StockRepo.FindByID by an allocation's unit id | held units are never allocated, so no allocation names one |
BinLevelLedger (memory + Postgres) → BinStockLevelChanged on_hand/reserved | stock_units where state not UNLOCATED/REMOVED | extended: HELD excluded in SQL and in memory, so a bin level never counts a held unit |
MCP get_bin_stock (mcp/tools.go, mapping.go), HTTP stock_handler | StockRepo.FindByBin/FindBySKU, Usable() | cannot see held units |
Analytics projector and report (internal/analytics) | the analytics topic, not stock units | folds StockReceived/ItemStowed/...; the new types are ignored; a release raises StockReceived, so flow stays right |
| Downstream: order-management ATP, network-inventory-planning NIP, replenishment | StockReserved, BinStockLevelChanged, TransferStockAllocated events | those events never include a held unit (rows above), so held stock is never promised |
Consequences
- Damaged units stay visible and owned: a list read, an age filter and a metric
replace the silent log line. ADR 0037's "Damaged is not booked" is superseded
for the
Damagedcondition;Goodis untouched. - Usable stock, reservations, transfer allocation, bin levels and cycle counts
behave exactly as before; the only new path into usable stock is
RELEASE, which goes through the same staged-receipt seam as a fresh receipt. - One extra table read when a
Damagedline arrives; none on the Good path. - Not in scope (v1): partial disposition, a configurable hold reason on the
wire (the producer's condition maps only to
DAMAGED;QC_PENDINGandSUSPECTare accepted for later producers such as IF-7), a held-stock analytics report, and the exception-management case per hold.