9. Fragile and hazmat handling flags carried on Task and Package
Status
Accepted.
Context
inventory-storage introduced a ProductClassification concept upstream of
this service — it owns whether a SKU is, among other things, hazmat- or
fragile-relevant. This service does not call inventory-storage directly
(per the existing anti-corruption-layer rule at every context boundary — see
ADR-0004), so any of that
classification this service needs has to arrive already resolved, carried on
something this service already consumes.
The two classifications have different consequences here, discovered during a boundary check before implementation started:
- Hazmat is a station-eligibility concern: a hazmat task must be
claimed only by a station certified to handle it. This service already has
a mechanism for exactly that shape of rule —
shared.Capability/shared.CapabilitySet, an open string type (not a closed enum, matching theLocationType-style convention already used elsewhere in this codebase) compared by set containment inTask.ClaimviaCapabilitySet.HasAll, andRegisterStationalready accepts arbitrary capability strings for a station's certification set. A task requiring hazmat handling already works today by putting"hazmat"inrequiredCapabilities— no structural code exists to change. - Fragile is a packing concern, not a placement or capability-matching
concern: it affects how a station packs an order into a carton, not which
station or task can be claimed. Nothing in the existing model carried this
—
Taskhad no packing-hint field, andPackagehad no notion of care level at all.
The forces:
- Contexts must not share aggregates or call each other synchronously for
domain facts.
inventory-storage's classification must arrive already resolved into this context's vocabulary, riding on something this service already consumes — not via a new synchronous call. wes-work-planningalready does exactly this kind of translation. CPT andrequiredCapabilitiesalready ride in onWorkReleasedand get stamped onto theTaskat creation time via the existingCreateTaskuse case (see the repository'sINTEGRATION.mdand ADR-0004). A fragile hint is the same shape of fact — this service should not invent a second ingestion path for it.SealPackagealready loads the owningTaskto validate claim ownership before it builds thePackage(see Aggregates & invariants). Any fragile-derived state on thePackageis available at that exact moment for free, without a second lookup.- Adding a caller-supplied
fragileargument toSealPackage.Executewould let it drift from the Task's own answer. The station drivingseal-packageshould not be trusted (or asked) to restate a fact the system already knows from the Task it is fulfilling. - Kafka delivery already has one documented simplification (the
path_id-prefix convention) for a field the producer doesn't unambiguously carry yet. Backward compatibility with any already-documentedwes-work-planningproducer that predates a newdata.fragilefield is a real, immediate constraint, not hypothetical.
Decision
Task gains a fragile bool field with a Fragile() accessor, threaded
through New/Rehydrate and the CreateTask use case's Execute
parameters, exactly like CPT and requiredCapabilities already are.
Package gains a fragileHandling bool field with a FragileHandling()
accessor, set at construction (pack.New/Rehydrate) and derived — not
independently supplied — by SealPackage from task.Fragile() on the Task
it already loaded. Hazmat gets no code change: it is documented as a known,
named Capability value in the ubiquitous language. No new aggregate is
introduced for either.
Task.Fragile
func New(id shared.TaskId, taskType Type, cpt shared.CPT, orderRef shared.OrderRef,
required shared.CapabilitySet, fragile bool) *Task
fragile is opaque to this service: it does not gate Claim, does not
appear in requiredCapabilities, and has no effect on dispatch priority or
capability matching. It is read by exactly one caller, SealPackage.
The Kafka consumer (internal/adapters/inbound/kafka) reads an optional
data.fragile bool off the WorkReleased envelope, defaulting to false
when absent, and passes it straight to CreateTask.Execute — the same
mapping discipline path_id and cpt already get, and the same
"default-and-document" backward-compatibility approach the path_id-prefix
rule already established.
Package.FragileHandling — derived, not supplied
func New(id shared.PackageId, orderRef shared.OrderRef, fragileHandling bool) *Package
SealPackage.Execute is the only caller. It already does:
t, err := uc.Tasks.FindById(ctx, taskId)
...
p := pack.New(uc.NewId(), t.OrderRef(), t.Fragile())
There is deliberately no fragile field on sealPackageRequest — the HTTP
DTO the station sends. The station reports what it scanned; whether that
warrants fragile handling is a fact this service already knows from the
Task, not something to re-litigate per request.
Hazmat — documentation only
shared.Capability stays an open string type, not a closed enum — this
is a deliberate continuation of the existing convention, not a new choice
made for hazmat. "hazmat" is added to the ubiquitous language as a known,
named value alongside pick/pack/slam, in CLAUDE.md and
docs/docs/business-context/ubiquitous-language.md. No code in
Task.Claim, CapabilitySet.HasAll, or RegisterStation changes, because
none needs to: a task with requiredCapabilities: ["hazmat"] today is
already only claimable by a station whose registered capability set
contains "hazmat".
Domain events stay thin
Per the existing discipline (see
Domain events and
ADR-0004), neither
TaskCreated nor PackageSealed gained a fragile/fragileHandling
field. Both flags are already visible on their aggregate's HTTP response
(fragile on the task response, fragileHandling on the package response)
for anything that needs to read the current state; nothing consuming these
events in-process needs the value pushed onto the event payload today. If a
future external consumer needs it on the wire, the existing
repo-lookup-enrichment pattern (used for TaskCompleted's work_unit_id) is
the template — enrich in the adapter, not the domain event.
Consequences
Easier
- No new aggregate, no new consistency boundary. Both flags live on aggregates that already exist, set once at construction and never mutated — no new invariant to enforce, no new failing-path test class beyond simple round-tripping.
- Hazmat cost nothing to add. The entire mechanism — capability-set
matching in
Task.Claim, open acceptance inRegisterStation— already existed and needed zero lines of production code changed. This is the cheapest possible outcome for a cross-context requirement: the existing design already generalized to it. FragileHandlingcannot drift from its Task. BecauseSealPackagederives it rather than accepting it as an independent argument, there is no code path where a Package's fragile-handling flag disagrees with the Task that produced it.- Backward-compatible by construction.
data.fragile's absence on an olderWorkReleasedproducer defaults cleanly tofalse, matching the existingpath_id-prefix simplification's shape exactly — one more documented, bounded gap instead of a new kind of failure. - This positions a future WCS sortation ACL cheaply. A fragile package
can be routed to a non-tilt lane by a future outbound adapter that reads
Package.FragileHandling()— that adapter does not exist yet and is explicitly out of scope this round, but the flag it would need is already in place and already tested.
Harder
- Two more fields to keep in sync across every layer that touches Task or
Package.
New,Rehydrate, the Postgres schema (new migration0003_fragile_handling), the HTTP DTOs, and the Kafka mapping all needed a coordinated, mechanical change — the kind of ripple that is easy to half-do. Every call site was audited in this round; a future field addition should expect the same footprint. fragileonCreateTask.Executeis one more positional-ish parameter. The use case's signature grows again (type, cpt, orderRef, capabilities, fragile) — still explicit and named at call sites, but each addition make the signature longer. If this pattern repeats, a request-struct parameter object would be a reasonable follow-up refactor.- A caller with no better information must guess
fragile: false. The HTTPPOST /tasksendpoint acceptsfragilefrom any caller, not onlywes-work-planningvia Kafka — a human or script hitting the REST API directly can set it incorrectly (or leave itfalsewhen it should betrue) with no validation againstinventory-storage. This mirrors howrequiredCapabilitiesalready works today (accepted as freeform, not validated against a source of truth) and is an accepted, existing shape of risk rather than a new one. - No sortation ACL exists yet.
Package.FragileHandling()is currently read by nothing except the HTTP/GET-style responses — there is no consumer (WCS or otherwise) acting on it yet. It is data with a documented intended use, not a wired end-to-end capability, which is the same honest gap this repo already accepts forItemPicked(see Domain events).