Skip to main content

Tasks

The Task aggregate: units of Pick, Pack, or SLAM work. Covers the pool (create), PULL dispatch (claim-next), lease lifecycle (renew, expire), completion, and read models: the pending queue-depth projection and the by-order-reference lookup used by downstream consoles.

๐Ÿ“„๏ธCreate a task and place it in the pool

Puts a new unit of Pick, Pack, or SLAM work into the pending pool. The task is not assigned to any station at creation time โ€” PULL dispatch (`POST /stations/{stationId}/task-claims`) is the only way a task becomes claimed, consistent with this service's rule that work is never pushed to a named station in advance. `cpt` (Critical Pull Time) drives dispatch priority: `claimNext` always selects the earliest-CPT pending task a station is equipped for.

๐Ÿ“„๏ธLook up every task recorded for an order reference

Read-only query tracing an order-management order back to the Pick/Pack/SLAM tasks this service created for it โ€” the endpoint that backs a cross-service console screen answering 'what tasks has fulfillment-execution created/completed for order X'. Returns every task whose `orderRef` matches, normally one PICK/PACK/SLAM leg each; a leg may appear more than once if it was retried (e.g. a new task created after a prior one's lease expired without completion), so treat the response as the full set of tasks for the order, not a single result per process path. An unrecognized `orderRef` is not an error โ€” it returns an empty page, the same convention `GET /queues/{taskType}/depth` uses for an unknown `taskType`.

๐Ÿ“„๏ธPULL-dispatch the best-fit pending task to this station

Implements this service's core dispatch rule: **pull, not push**. The station calls claimNext; the system โ€” never the caller โ€” selects which task to hand it. Among Pending tasks of `taskType` that this station's registered capabilities satisfy, the **earliest-CPT** task is selected and leased to `stationId` for a fixed duration (5 minutes by default). Assignment is **at-most-once**: a task with an active, unexpired lease cannot be claimed by anyone else, and this endpoint will simply skip it and try the next-best candidate. If the lease is not renewed or the task completed before it expires, the task automatically returns to the pool (see `POST /task-lease-expirations`) rather than being lost. This call is not idempotent in the way a PUT would be โ€” every successful call claims a *different* task (or the same task again only after its prior lease was released); that's intended PULL semantics, not a bug.

๐Ÿ“„๏ธForm this station's pick walk (ADR 0063)

Pick batching behind the `PICK_BATCH_MODE` rollout gate. The anchor is exactly the task `POST /stations/{stationId}/task-claims` with `taskType: PICK` would return (the same claimer selects it), so batching never changes who goes first; companions are the station's interleaving-hint candidates inside the anchor's CPT band, in hint rank order, kept only when the station can do them and the cart segregation matrix allows sharing, up to the configured maximum (default 4). A batch of one is valid; nothing waits for a batch to fill. With the mode not `on` (the fleet default is `off`) the surface answers 503 batch-mode-off and `task-claims` is the only dispatch path, exactly as before.

๐Ÿ“„๏ธComplete a task on behalf of the station that claimed it

Finishes the task's lifecycle (Claimed -> Completed) and publishes `TaskCompleted`. Only the owning station's claim may complete it, and a completed task can never be completed again โ€” this endpoint enforces the no-double-complete invariant, returning `409` on a repeat call rather than silently succeeding twice. A `RELOCATE` task (a slot-plan move, ADR-0047) completes only with the operator's confirmation: `quantity` (counted, at least 1) and the bins the move left open โ€” `fromBin` for an Assign, `toBin` for a Vacate (see the task's `relocation`). A scan of a side the plan fixed must equal the planned bin. The confirmed move is published on `TaskCompleted` (`sku`, `from_bin`, `to_bin`, `quantity`, `relocation_ref`). A `REPLENISH` task (a pick-face replenishment, ADR-0050) completes only with `quantity` (counted, at least 1); `fromBin` and `toBin` are optional scans that must equal the task's planned `replenishment` bins. The confirmed move is published on `TaskCompleted` (`sku`, `from_bin`, `to_bin`, `quantity`, `request_ref`). Any other task type takes none of these fields.

๐Ÿ“„๏ธConfirm one scan of an each or case GTIN against a PICK task

The station holding the claim on a PICK task scans a GTIN (ADR 0054). The GTIN is resolved against the local copy of product-master's pack levels (no synchronous call): it must identify the task's SKU and, for a task planned in eaches, an EACH level; for a task planned in cases, a CASE level. `count` packs are added (default 1) and the answer reports the eaches confirmed so far. Quantities are always in eaches; `POST /tasks/{id}/completions` and `TaskCompleted` are unchanged. A rejected scan changes nothing.

๐Ÿ“„๏ธComplete a BREAK_CASE task by breaking the sealed case in inventory-storage

A BREAK_CASE task (ADR 0054) is created when an each pick finds only a sealed case at its source. Completing it asks inventory-storage to break the container (`POST /containers/{lpn}/case-breaks`) into the loose bin, with an Idempotency-Key stable per task, and only then completes the task and publishes `TaskCompleted`. If inventory-storage cannot be reached the task stays claimed (503); a retry does not break twice.

๐Ÿ“„๏ธScan contents and seal a Package for a Pack task's order

The Pack-path counterpart to `complete`: the station holding the active claim on a Pack task scans the order's contents and seals them into a brand-new Package resource (created by this call, not pre-existing โ€” see the `Location` header). The task itself is left claimed; a separate `POST /tasks/{id}/completions` call finishes the Pack task once the package is sealed. Requires at least one scanned item โ€” an empty `contents` array is a domain invariant violation (`422`), not a malformed request (`400`), since the array is present and well-formed, just semantically insufficient to seal.

๐Ÿ“„๏ธSweep every Claimed task whose lease has expired back to Pending

The Clock-driven side of the at-most-once lease design: scans every Claimed task and, for each whose lease expiry has passed without a renewal or completion, frees it back to Pending (publishing `LeaseExpired`) so the work is never silently lost. A collection- level action on the `tasks` resource โ€” not scoped to a single task id โ€” analogous to how `/tasks/{id}/completions` is a single-resource action; deliberately not placed under an unscoped `/admin` path. Idempotent: a second call simply frees nothing new if nothing else has expired since the last sweep. Takes no request body.

๐Ÿ“„๏ธSweep every still-open task whose CPT has passed and report it as missed

The Clock-driven half of the promise feedback loop with order-management (ADR 0014 ยง5, this service's own ADR-0025): scans every task still open (Pending or Claimed โ€” i.e. not Completed) and, for each whose CPT is at or before now, publishes `TaskCPTMissed`. Unlike `/task-lease-expirations`, this never mutates the task's own lifecycle state โ€” a CPT miss is a fact reported upstream, not a state transition. A collection-level action on the `tasks` resource, mirroring `/task-lease-expirations`'s own convention exactly. **Not idempotent in the usual sense by design**: a task still open past its CPT is reported again on every sweep pass for as long as it remains open โ€” order-management's `RepromiseOrder` consumer is explicitly designed (ADR 0014 ยง5) to be idempotent on `(orderId, sourceEventId)` because of this. Takes no request body.