---
id: WF-COM-FUL-013
title: Fence and cancel shipment work for a cancellation
trigger: An Orders cancellation fences unshipped work.
product_area: commerce
module: fulfillment
revision: 1
status: draft
design_intent: proposed
implementation_evidence: observed
inference: []
source_sha:
  services-commerce: c8b66a98e2490617aec38ba5c8165dd9bd0a8f9b
implements:
  - CAP-COM-FUL-012
  - CAP-COM-FUL-014
  - CAP-COM-FUL-018
moves:
  - STATE-COM-FUL-005
  - STATE-COM-FUL-006
  - STATE-COM-FUL-009
crosses:
  - SVC-COM-FUL-shipping
  - SVC-COM-FUL-inventory
  - SVC-COM-FUL-fulfillment
idempotency: >-
  The cancellation tag identifies a retained fence. Releasing named fenced units
  can repeat safely, and cleanup skips labels already voided.
concurrency: >-
  The fence runs inside cancellation’s transaction and competes with handoff on
  shipment-line records. Label cleanup occurs through external calls afterward.
hops:
  - 'n': 1
    actor_or_service: Orders cancellation (in its transaction)
    action: >-
      Determine which requested units have already departed and which still
      permit cancellation.
    anchor: >-
      services-commerce:modules/shipping/services/fulfillment/cancellation-fence.ts:isLineShipped
    seam: sync
    on_failure: Refuse the owning cancellation request.
    left_inconsistent: No new cancellation fence is retained by refusal.
    observer: Cancellation plan result.
    provenance: observed
    source: >-
      services-commerce:modules/shipping/services/fulfillment/cancellation-fence.ts
  - 'n': 2
    actor_or_service: Orders cancellation (in its transaction)
    action: >-
      Conditionally fence unshipped shipment-line ranges inside the cancellation
      transaction.
    anchor: >-
      services-commerce:modules/shipping/services/fulfillment/cancellation-fence.ts:fenceOrderLineForCancellation
    seam: sync
    on_failure: Rollback the cancellation and its fence on conflict.
    left_inconsistent: Handoff that won earlier still stands.
    observer: Fence history.
    provenance: observed
    source: >-
      services-commerce:modules/shipping/services/persistence/shipments.ts:fenceLinesForCancellation
  - 'n': 3
    actor_or_service: Orders cancellation (after commit)
    action: >-
      Cancel fenced work, remove shipment assignments, void empty-content
      parcels and close shipments with no live lines.
    anchor: >-
      services-commerce:modules/shipping/services/fulfillment/cancellation-fence.ts:cancelFencedShipmentLines
    seam: sync
    on_failure: Retain cancelled lines when carrier void is refused or unknown.
    left_inconsistent: A carrier label can remain live or charged.
    observer: Label-void finding.
    provenance: observed
    source: >-
      services-commerce:modules/shipping/services/fulfillment/labels.ts:voidLabelsOfShipment
  - 'n': 4
    actor_or_service: Register worker (the merchandise application's cancel)
    action: >-
      Release the cancellation’s named fenced units and clear unrelated unit
      fences.
    anchor: >-
      services-commerce:modules/inventory/services/persistence/inventory-allocations.ts:releaseFencedUnitsOfLine
    seam: queue
    on_failure: Use cancellation delivery recovery for unfinished release.
    left_inconsistent: Units can remain fenced and promised until release runs.
    observer: Cancellation-obligation attempts.
    provenance: observed
    source: >-
      services-commerce:modules/inventory/services/persistence/inventory-allocations.ts
branches:
  - >-
    A staff shipment cancellation fences each live line under the shipment,
    cancels them and voids labels, but the units stay committed or picked on the
    order for a new shipment; the order is not cancelled.
waits:
  - The cancel obligation's delivery.
evidence:
  - >-
    services-commerce at c8b66a98:
    modules/shipping/services/fulfillment/cancellation-fence.ts,
    shipment-creation.ts:cancelShipment; services/persistence/shipments.ts;
    modules/inventory/services/persistence/inventory-allocations.ts;
    docs/migrations/shipping/README.md (D-P8S-11).
controls: [TC-IAM-006, TC-AZ-001, TC-AZ-002, TC-AZ-003, TC-AZ-004, TC-AZ-005, TC-AZ-006, TC-TEN-001, TC-TEN-002, TC-TEN-003, TC-CRY-001, TC-DAT-001, TC-DAT-002, TC-DAT-003, TC-DAT-004, TC-LOG-001, TC-LOG-002, TC-LOG-003, TC-LOG-004, TC-LOG-005, TC-AVL-004, TC-MON-001, TC-MON-002, TC-MON-004, TC-PI-001, TC-PI-002, TC-PI-003, TC-PI-004, TC-PI-005, TC-VEN-001, TC-VEN-002, TC-VEN-003, TC-PRV-001, TC-PRV-002]
---

# Fence and Cancel Shipment Work for a Cancellation

## What It Does

Cancellation first distinguishes units already shipped from those still recoverable. It conditionally fences shipment lines, cancels fenced work and removes shipment assignments. Labels for parcels with no retained contents are voided and allocations release through the cancellation instruction.

## The Flow

```mermaid
sequenceDiagram
  participant C as Orders cancellation
  participant F as Fence
  participant H as Handoff
  participant L as Labels
  participant R as Register worker
  C->>F: which units left?
  C->>F: fence unshipped lines (conditional)
  H--xF: handoff refused on a fenced line
  C->>F: after commit, cancel fenced lines
  F->>L: void labels, pull parcels
  R->>R: cancel obligation releases units
```

## When Something Fails

Fence and handoff compete on the same line rows. Carrier void can fail after cancellation work stands, leaving a live or charged label. Goods already handed over require a return rather than cancellation release.
