0040. Plan approved slot plans as sequenced RELOCATE work
Status
Accepted.
Implements this context's part of fleet decision E1 (slotting-optimization ADR 0010, "Approved slot plans are executed as WES relocation work", which supersedes slotting-optimization ADR 0007) and follows decision E5 (the process-path catalogue declares which demand sources may route work onto a path; process-path-management ADR 0034).
Context
slotting-optimization publishes SlotPlanApproved
(com.warehouse.wms.slotting-optimization.slotplan.SlotPlanApproved, dataschema
urn:warehouse:slotting-optimization:events:SlotPlanApproved:v1) on
warehouse.slotting-optimization.events, key and subject = the plan id. Its
data carries plan_id, site_id, approved_at, an optional
supersedes_plan_id, the full assignments map and the moves that change
the site's forward-slot picture. Each move is {sku, from_slot?, to_slot?, kind} where kind is Assign (no from_slot), Relocate (both) or
Vacate (no to_slot).
A move is physical floor work: an operator carries the SKU's stock from one
bin to another. The fleet already has one conductor for floor work. This
context plans and pools it, process-path-management routes it,
fulfillment-execution runs it with operators (its ADR 0047, task type
RELOCATE), and inventory-storage records the result on the ledger from
fulfillment-execution's TaskCompleted. Decision E1 makes approved slot
plans a second demand source next to orders, beside the network transfer
legs of ADR-0033.
ADR 0007's open questions are answered by decision E1; the parts this context owns are:
- Sequencing (answer 4). Inside one plan, a move INTO a slot that another move of the same plan vacates must wait until that vacating move's task has completed. Otherwise the operator finds the destination slot still full.
- Supersession (answer 3). When a newer plan for the site is approved, the superseded plan's work that has not been released yet is cancelled and the new plan's moves are planned. Released or in-progress work runs to completion.
- Quantity (answer 5). v1 moves the whole on-hand quantity of the SKU at
the source bin, counted and confirmed by the operator at execution, so the
plan carries no quantity and neither does the work unit. The open side of
an
Assign(source) or aVacate(destination) is chosen and scanned by the operator at execution.
Decision
-
A sixth consumed topic. The inbound
Consumeralso readswarehouse.slotting-optimization.events(cloudevents.TopicSlottingEvents) under the same consumer group, with its own<topic>.dlqwriter (RequiredAcks: RequireAll, like every DLQ writer). OnlySlotPlanApprovedis handled;SlotPlanGenerated,SlotPlanRejectedand any unknown type are ignored. -
ApplySlotPlanApproved, besideApplyWorkDemandReleased. One use case applies one plan, with the processed-event mark (the CloudEventsid) and every write in ONE atomic scope (ADR-0028). Nothing leaves except through the transactional outbox (ADR-0014). -
One RELOCATE work unit per move.
- id
<plan_id>-move-<move_seq>, wheremove_seqis the move's 0-based index inmoves(deterministic, so a replay under a new event id is a no-op); reference = plan_id, soGET /work-units?reference=<plan_id>lists every unit of a plan;- path
RELOCATE, validated against the process-path catalogue (ADR-0012). When the catalogue entry declares anintake(process-path-management ADR 0034) it must containSLOT_RELOCATION; an entry without an intake is accepted, because this route is chosen by explicit path id; work_kind = RELOCATE,site_id = site_id,sku = sku, plus the relocation value:plan_id,move_seq,kind,from_slot,to_slot;cpt = approved_at + RELOCATION_CPT_HORIZON(default24h): a slot plan has no customer cutoff, but every pooled unit needs a CPT, and fulfillment-execution's CPT-miss sweep must not flag a fresh move as already late.
- id
-
Sequencing: a blocked unit stays out of the pool. Move B waits on move A when
A.from_slot == B.to_slot(A is not B, same plan). B is createdPendingwithblocked_by = A's work unit idand is NOT admitted to the RELOCATE work pool, so no release (REST, MCP) can hand it out. When A's completion is recorded (TaskCompletedfrom fulfillment-execution, already consumed byApplyTaskCompleted, orPOST .../completions),RecordCompletionadmits everyPendingunit blocked by A into the pool in the SAME transaction and clears itsblocked_by. Two rules keep this total:- when several moves vacate the same slot (a valid plan has at most one),
B waits on the one with the lowest
move_seq; - a dependency cycle (a swap: X→Y and Y→X) is broken at its lowest
move_seq: that move is planned unblocked. The floor holds two SKUs in one bin for the duration of the swap, which the ledger allows.
- when several moves vacate the same slot (a valid plan has at most one),
B waits on the one with the lowest
-
Supersession is decided per site by approval time. A
slot_plansrow records every plan this context has applied (plan_id,site_id,approved_at,supersedes_plan_id,move_count). For an incoming plan P at site S:- P already recorded: no-op (the same plan under another event id);
- the latest recorded plan of S was approved AFTER P (ties: the greater
plan_idwins): P is stale. Plan ids are Kafka keys, so two plans of one site may arrive out of order. P is recorded and plans nothing; - otherwise P supersedes: every
PendingRELOCATE unit of S that belongs to another plan (blocked or pooled) is cancelled. The unit moves to the new terminal stateCancelledand its pool entry is withdrawn (WorkPool.Withdraw). Then P's units are planned.ReleasedandCompletedunits are never touched.supersedes_plan_idis recorded for audit only; the rule does not depend on it, so a missed intermediate plan cannot leave work behind.
-
Release goes through the existing flow. RELOCATE units are released by
ReleaseNextWorkon pathRELOCATE, exactly like every other pool. A pooled entry whose unit was cancelled is withdrawn on the way past, never released.WorkReleasedstays v1. For a RELOCATE unit itsdatagains ONE optional object, present only on RELOCATE units:"relocation": {"plan_id": "plan-3b0e8d2a","move_seq": 1,"kind": "Relocate","sku": "SKU-2","from_bin": "WH1-FWD-A02-03-01-A","to_bin": "WH1-FWD-A01-01-02-A"}from_binis omitted for anAssignandto_binfor aVacate(the operator scans the open side).kindkeeps the slotting spelling. This is the shape fulfillment-execution'sWorkReleasedconsumer turns into itsRelocationMove(ADR 0047 there); its completion reportsrelocation_ref = "<plan_id>:<move_seq>". The transfer fields of ADR-0033 (work_kind,transfer_ref,site_id,quantity) remain the transfer discriminator and are NOT emitted for RELOCATE units, so fulfillment-execution's transfer branch never sees a relocation. -
Fail loud on a broken contract. A
SlotPlanApprovedwith noplan_id,site_idorapproved_at, a move with nosku, an unknownkind, akindmissing the slot it requires, aRelocatewhose two slots are equal, an unknownRELOCATEpath or an intake that excludesSLOT_RELOCATIONis deterministic poison: the handler returns an error, the message is retried and then dead-lettered towarehouse.slotting-optimization.events.dlq. A message interrupted only by shutdown cancellation is never dead-lettered (the consumer's existingctx.Err()guard). -
No cancellation event in v1. A cancelled unit was never released, so no downstream service holds work for it. Its cancellation is visible on the work-unit read API (
state: Cancelled,cancelledAt). AWorkUnitCancelledevent can be added later if a consumer needs one.
Consequences
- RELOCATE work is staffed, capacity-planned and measured like every other path: labour plans, WIP limits, release telemetry and the analytics counters apply unchanged.
- The work-unit read side (
GET /work-units/{id},GET /work-units?reference=) showsCancelled,cancelledAt, therelocationvalue andblockedBy. TheWorkUnitStateenum gainsCancelled.Cancelledis terminal:ReleaseandCompleterefuse it. - Migration
0014is additive: relocation columns onwork_units(allNOT NULL DEFAULTexcept the nullablecancelled_at), two partial indexes, and theslot_planstable. - New env
RELOCATION_CPT_HORIZON(Go duration, default24h). - warehouse-infra: no change is required for this context. The consumer joins
the existing
KAFKA_CONSUMER_GROUP, and the topic is slotting-optimization's own publish topic, so its ensure-topics entry already exists wherever slotting-optimization runs. TheRELOCATEpath must be in the process-path catalogue (process-path-management's seed) before plans arrive, or they are dead-lettered until it is (replay from the DLQ; see the runbook).
Alternatives considered
- A blocked flag inside the pool entry (a
heldentry state) — rejected: every pool reader (backlog depth, WIP, remaining capacity) would need to learn a state that means "not really backlog". Keeping blocked units out of the pool keeps the pool's meaning "releasable work". - Sequencing in fulfillment-execution — rejected: release order is this context's job; fulfillment-execution would have to hold tasks it was told to run.
- Supersession driven only by
supersedes_plan_id— rejected: one lost or out-of-order event would leave a superseded plan's work in the pool forever. Approval time per site is total and order-independent. - A separate relocation aggregate — rejected for the ADR-0033 reason: a move is the same releasable unit of work with extra descriptive context.