0036. WorkUnit stores line_no; WorkReleased carries it
Status
Accepted (2026-10-07). Amends nothing: it is additive on top of
ADR-0031 (the deterministic
<order>-line-<n> ids), ADR-0010
and ADR-0033 (the other optional
WorkReleased fields) and ADR-0011 (the
analytics stream).
This is hops 3 and 4 of fleet decision 18 (per-line confirm-pick), recorded in
the architect's 2026-10-05 audit decision log. The other hops live in
order-management (sends lineNo when it reserves), inventory-storage
(Reservation.line_no, and the per-line confirm in its TaskCompleted
consumer — its ADR 0035 is the fallback this keeps) and fulfillment-execution
(Task.source_line_no, TaskCompleted.line_no).
Context
OrderAllocated / OrderPartiallyAllocated carry a line_no per allocated
line, and ApplyOrderAllocated already receives it as
OrderAllocatedLine.LineNo. It uses it for one thing: building the work unit
id "<order>-line-<n>". After that the number exists only inside an id
string — the WorkUnit has no line_no, and WorkReleased has no
line_no (it carries ref, which is the order id, not the line).
Downstream, that loses the information the confirm-pick flow needs: a
TaskCompleted for an order can name the order but not which line was picked,
so inventory-storage has to count picks and confirm everything on the last
one (its ADR 0035), which leaves a "one pick early" edge and a window in which
a reservation is confirmed before its line is picked. The fix is to carry the
line explicitly end to end. Parsing it back out of the id string is rejected:
the id format is this service's private business (REST callers supply
arbitrary ids, transfer units use demand ids), and an explicit, validated
field is something a consumer can rely on.
Decision
We store the line number on the WorkUnit and publish it on WorkReleased,
as an optional, additive field everywhere. Nothing becomes required, no
event version changes, and no existing id changes.
- Aggregate.
WorkUnitgains an optionallineNo(LineNo()/SetLineNo(), the same additive-setter style asSKU,GiftWrapand the transfer fields).0means unknown. It plays no part in any invariant. - Enqueue.
EnqueueWorkUnitRequestgains an optionalLineNo. A negative value is rejected withworkunit.ErrInvalidLineNo;0is unknown.ApplyOrderAllocatedpassesline.LineNofor each line; a non-positive value from upstream is treated as unknown (the id is still built exactly as before), so a malformed line is never newly dead-lettered by this change.WorkUnitIdis untouched. - Persistence. Migration
0013addswork_units.line_no INTEGER, nullable, no default. An unknown line is written asNULL, never0;NULLrehydrates as unknown. Every row created before this ADR is thereforeNULLand every existingINSERTkeeps working. The in-memory repo mirrors it. - REST.
POST /paths/{pathId}/work-unitsaccepts an optionallineNo(integer ≥ 1;null≡ omitted). An explicit0or negative value is400with the new problem typeinvalid-line-no— it is rejected, not silently coerced to "unknown". The work-unit response echoeslineNo, omitted when unknown. TheIdempotency-Keybehaviour (ADR-0022) is unchanged: the body hash simply covers the new field. WorkReleasedv1data, integration topic (warehouse.work-planning.events): gains an optional integerline_no, read off theWorkUnitat encode time exactly likeref/cpt(inside the release transaction, so the outbox sees the just-saved row), and omitted when unknown. Sametype, samedataschema(…:events:WorkReleased:v1).WorkReleasedv1data, analytics topic (warehouse.wes.analytics): gains the same optionalline_nounder the same rule. The analytics publisher used to be repo-free; it now takes an optional work-unit repo (AnalyticsPublisher.WithWorkUnits), wired incmd/wesandcmd/mcpwith the same repository the integration publisher reads. Without a repo (or on a failed read) the field is simply omitted — fail-open, like the classification hints (ADR-0009): a publishing hiccup never blocks a release.- Transfer units (ADR-0033) never carry a line. A unit created before
this ADR publishes no
line_no. In both cases a consumer sees exactly the payload it saw before. - Contract rule for consumers. Absent
line_nomeans line unknown and every consumer must keep working without it. This is what lets the four repos of decision 18 ship in any order.
Consequences
- Easier: fulfillment-execution can stamp the line on its
TaskfromWorkReleased.line_noand echo it onTaskCompleted, which lets inventory-storage confirm exactly one line's reservation instead of counting picks. No consumer parses an id. - Backward compatible by construction. Optional field, same v1 identity,
omitwhen unknown, nullable column. The pre-existing publisher goldens are byte-identical (a legacy unit has no line); new goldens pin the with-line shape on both topics. Verified against the fleet'sorigin/develop: fulfillment-execution'sWorkReleasedconsumer decodes into a plain struct (noDisallowUnknownFieldsanywhere in that repo), and this repo's own analytics consumer and projector read onlypath_id/work_unit_id; no other repo consumes the payload. - Harder: the analytics publisher is no longer repo-free, so its
Encodenow performs one indexed read perWorkReleased(the integration publisher already did). Under the outbox this happens inside the release transaction. - Not retroactive: units already in the pool when this ships have no
line_no, so theirWorkReleasedcarries none and downstream keeps using the last-pick fallback for them until they drain. There is deliberately no backfill that parses<order>-line-<n>out of existing ids. - Hard to reverse: once a consumer relies on
line_no, removing it would reintroduce the premature-confirm window. The column itself is additive and can stay. - Open edge: the nullable column is
INTEGERwithout aCHECK (line_no >= 1). The aggregate's callers validate (REST rejects< 1; the order consumer maps non-positive to unknown); a constraint was left out to keep the migration trivially safe on a populated table.