0042. Plan pick-face replenishment requests as REPLENISH work
Status
Accepted. Amended by ADR-0044: REPLENISHMENT_MODE defaults to kafka and permissive/off are boot errors; the consumer is always on.
Mirrors the RELOCATE chain of ADR-0040 for the second floor-work demand source of the pick-face replenishment design (fleet plan, decision 5, change P3b). The consuming side is fulfillment-execution's ADR 0050 (REPLENISH task).
Context
pick-face-replenishment keeps forward pick faces stocked from reserve bins. For
each pick face under its min/max policy it raises a ReplenishmentRequested
(com.warehouse.wms.pick-face-replenishment.replenishment.ReplenishmentRequested,
dataschema
urn:warehouse:pick-face-replenishment:events:ReplenishmentRequested:v1) on
warehouse.pick-face-replenishment.events, key and subject = the request id.
Its data carries request_id, site_id, sku, forward_bin (the pick face
to fill), source_bin (the reserve bin), quantity, priority
(NORMAL | URGENT: URGENT when the pick face had nothing available at
detection), policy_min, policy_max and requested_at. It also raises
ReplenishmentCancelled (reason: OPERATOR, ASSIGNMENT_CHANGED,
POLICY_REMOVED) and ReplenishmentCompleted on the same topic.
The physical move is the same kind of floor work as a slot-plan move: an
operator carries stock from one bin to another. This context plans and pools
it, process-path-management routes it, fulfillment-execution runs it with
operators, and inventory-storage records the result from fulfillment-execution's
TaskCompleted. pick-face-replenishment closes its request from
inventory-storage's StockRelocated.
Decision
-
A seventh consumed topic, with its own consumer.
internal/adapters/inbound/kafka/replenishment_consumer.goreadswarehouse.pick-face-replenishment.events(cloudevents.TopicPickFaceReplenishmentEvents). It is opt-in:REPLENISHMENT_MODE=permissive(the default) consumes nothing, so a deployment that has not opted in plans no REPLENISH work;REPLENISHMENT_MODE=kafkaruns it under the STABLE groupREPLENISHMENT_CONSUMER_GROUP, shared by every replica.kafkawithout the group, withoutKAFKA_BROKERSor withoutDATABASE_URL(Postgres: the planned work is shared state, so the in-memory repositories are never an option for this consumer), and any other mode value, is a boot error. The consumer follows the fleet pattern: dispatch on the FULL CloudEvents type;ReplenishmentRequestedandReplenishmentCancelledare handled;ReplenishmentCompletedand every unknown type are committed past; a message that is not a valid CloudEvent (bad JSON, the retired flat envelope) is WARN-logged and skipped;FetchMessage+CommitMessagesafter success; the use case claims the CloudEventsidand writes its effect in ONE atomic scope (ADR-0028); a payload that can never be applied is dead-lettered at once, any other failure is retried with jittered backoff (3 attempts) and then the raw message goes towarehouse.pick-face-replenishment.events.dlq; a message that only shutdown interrupted is never dead-lettered. -
ApplyReplenishmentRequested, besideApplySlotPlanApproved. Nothing leaves except through the transactional outbox (ADR-0014):WorkUnitCreatedis published in the same transaction as the processed-event mark, the pool entry and the unit. -
ONE REPLENISH work unit per request id.
- id
replenish-<request_id>(deterministic). A redelivery of the same CloudEventsidis caught by the processed-event mark; a DIFFERENT event for an already-planned request id finds the unit and is a no-op, never a second unit; reference = request_id, soGET /work-units?reference=<request_id>finds it;- path
REPLENISH, validated against the process-path catalogue (ADR-0012). The catalogue declares no replenishment intake value (it definesCUSTOMER_ORDER,STOCK_TRANSFER,SLOT_RELOCATION,INVENTORY_CONTROL), so no intake is evaluated: like every path reached by explicit id,REPLENISHis accepted whatever it declares. The path must exist in the catalogue before requests arrive, or they are dead-lettered until it does (replay from the DLQ); work_kind = REPLENISH,site_id,sku,quantity, plus the replenishment value:request_id,from_bin(the event'ssource_bin),to_bin(the event'sforward_bin),priority.
- id
-
Invariants of the value (
workunit.ReplenishmentMove):request_id,skuand both bins are present,quantity > 0, the bins differ,priorityisNORMALorURGENT.site_idandrequested_atare required by the use case. A violation is deterministic poison and goes to the DLQ without retries. -
Priority mapping: URGENT sits in the front band through the CPT. The WorkUnit has no priority field; pools release earliest CPT first, and fulfillment-execution's
claimNextdoes the same. So the priority is expressed in the CPT:cpt = requested_at + horizon(priority), withREPLENISHMENT_CPT_HORIZON(default8h) for NORMAL andREPLENISHMENT_URGENT_CPT_HORIZON(default1h) for URGENT. An urgent horizon above the normal one is capped at it, so URGENT can never sort behind NORMAL. Malformed or non-positive values fall back to the default and never fail the boot. The priority itself travels on the released event. -
Release goes through the existing flow.
ReleaseNextWorkon pathREPLENISH.WorkReleasedstays v1. For a REPLENISH unit itsdatagains ONE optional object, present only on REPLENISH units:"replenishment": {"request_id": "repl-9c2f6b1e-5d3a-4e8b-a7f0-1b2c3d4e5f60","sku": "SKU-2","from_bin": "WH1-RSV-A07-03-02-B","to_bin": "WH1-FWD-A01-01-02-A","quantity": 6,"priority": "URGENT"}This is exactly the shape fulfillment-execution's
WorkReleasedconsumer decodes (itsWorkReleasedReplenishment, ADR 0050); a golden exact-JSON test pins the bytes and a consumer-compatibility test decodes them through a field-for-field copy of that decoder. REPLENISH work never carriesrelocation, and the transfer fields (work_kind,transfer_ref,site_id,sku,quantity) are NOT emitted for it. Every RELOCATE, transfer and orderWorkReleasedpayload is byte-identical to before. -
Cancellation: the same as a superseded RELOCATE move, and no more.
ReplenishmentCancelledfor a unit that is stillPendingcancels it (Pending → Cancelled, the ADR-0040 state) and withdraws its pool entry, in one atomic scope. Released or completed work runs to completion (it was already handed to fulfillment-execution), and a cancellation for a request this context never planned is a no-op. No event is published: a Pending unit was never released, so no downstream service holds work for it. -
Persistence. Migration
0015is additive: fourNOT NULL DEFAULT ''columns onwork_units(replenishment_request_id,replenishment_from_bin,replenishment_to_bin,replenishment_priority); the sku and the quantity are the unit's existing columns. The memory adapter holds the same value; the Postgres integration test pins the round trip.
Configuration
| Variable | Default | Meaning |
|---|---|---|
REPLENISHMENT_MODE | permissive | kafka runs the consumer; permissive (or unset) consumes nothing; anything else is a boot error |
REPLENISHMENT_CONSUMER_GROUP | (unset) | STABLE consumer group shared by every replica; required (boot error if unset or blank) when the mode is kafka; also requires KAFKA_BROKERS and DATABASE_URL |
REPLENISHMENT_CPT_HORIZON | 8h | CPT of a NORMAL request = requested_at + this Go duration |
REPLENISHMENT_URGENT_CPT_HORIZON | 1h | CPT of an URGENT request = requested_at + this Go duration; capped at the normal horizon |
Text for the orchestrator to roll into .claude/rules/integration-events.md
(this change could not edit .claude/**):
Separately, with
REPLENISHMENT_MODE=kafka(ADR-0042),internal/adapters/inbound/kafka/replenishment_consumer.goreadswarehouse.pick-face-replenishment.eventsunder its own STABLE groupREPLENISHMENT_CONSUMER_GROUP(unset = boot error; so is a missingKAFKA_BROKERSor a missingDATABASE_URL), acts only oncom.warehouse.wms.pick-face-replenishment.replenishment.ReplenishmentRequested(ApplyReplenishmentRequested: ONEREPLENISHwork unit per request id, idreplenish-<request_id>) and...ReplenishmentCancelled(ApplyReplenishmentCancelled: cancels the unit only while Pending), and ignoresReplenishmentCompletedand every other type. CloudEventsidclaim
- effect in one UnitOfWork; invalid CloudEvents are WARN-skipped; poison goes to
warehouse.pick-face-replenishment.events.dlq; the offset is committed after success. DefaultREPLENISHMENT_MODE=permissiveconsumes nothing.REPLENISHMENT_CPT_HORIZON(8h) /REPLENISHMENT_URGENT_CPT_HORIZON(1h) set the CPT of NORMAL / URGENT work.
Consequences
- REPLENISH work is staffed, capacity-planned and measured like every other
path: labour plans, WIP limits, release telemetry and analytics counters apply
unchanged once the
REPLENISHpath exists in the catalogue. - The work-unit read side shows a REPLENISH unit with
pathId: REPLENISH,reference = request_idandstate; the OpenAPIWorkUnitdoes not enumerate work kinds or paths, so it is unchanged. - New envs above; no chart value is added in this change because the mode
defaults to
permissive. - warehouse-infra: the
REPLENISHpath must be in process-path-management's catalogue (infra config, outside this change), the ensure-topics entry forwarehouse.pick-face-replenishment.eventsis pick-face-replenishment's own, and a deployment opts in by settingREPLENISHMENT_MODE=kafkaandREPLENISHMENT_CONSUMER_GROUP.
Not done / limitations
- A cancellation that finds no unit is lost.
ReplenishmentCancelledfor a request id this context has not planned is a no-op and is not remembered. The topic is keyed by request id, so within one partition a cancellation cannot overtake its request; across a consumer-group reset or a replay with the processed-event marks pruned (ADR-0032) the request could be planned again. - Released work cannot be recalled. As in ADR-0040, there is no
WorkUnitCancelledevent and no recall of a unit already released to fulfillment-execution; it runs to completion. - Completion is not consumed here.
ReplenishmentCompletedis ignored: the unit completes through fulfillment-execution'sTaskCompleted, as for every other kind. policy_minandpolicy_maxare not read; the REST work-unit read model does not expose the replenishment value (unlikerelocation).
Alternatives considered
- A separate replenishment aggregate — rejected for the ADR-0033 reason: a replenishment is the same releasable unit of work with extra descriptive context.
- A priority field on the WorkUnit — rejected: every pool reader and the release ordering would have to learn it. The CPT already orders every queue, and the shorter URGENT horizon puts those requests in front without a new concept.
- Sharing
KAFKA_CONSUMER_GROUP— rejected: the consumer is opt-in and its effect is shared state in Postgres, so, like the ProductClassified consumer, it has its own stable group and its own mode.