Use Cases
Built on develop (merged 2026-11-08) in IQVO/yard-management, released at v0.1.4 (first release v0.1.0 on 2026-11-09; applied to the k3s cluster on 2026-11-10 at v0.1.2 in a reduced footprint, and the image pinned to the v0.1.4 commit 44d605e in warehouse-infra since 2026-11-18, checked 2026-12-02): yard-management switches on its API and relay (at the check the relay was 1/1 and the API 0/1 Pending on the NotReady agent node k3s-agent2); dock-scheduling runs its API only (it relays inline). The MCP server (25 tools on develop 3bcfc22, 21 in v0.1.4) is registered in warehouse-infra but switched off until the cluster has room; the A2A agent (two skills) is built on develop (2026-12-02), not released and not deployed (the chart carries it off by default and warehouse-infra has no a2a block); the analytics projectors, report services and sweeps are registered but switched off, so the KPI reports of ADR 0011 are released, not yet served. The page still derives from yard/model/model.yaml; where the as-built service differs, the model and this page say so (see the as-built notes).
One section per command in contexts[yard-management].aggregates[*].commands
(24 commands, ExpireLease among them) plus DwellSweep, an inbound message that is on no aggregate's command
list. Package (as built): internal/application/usecases. The runtime
sequence of the significant ones is on
Sequence Diagrams. Reads
(ListVisits, GetVisit, ListTrailers, GetTrailer, ListMoves, GetYardBoard,
GetYardPolicy) are not use cases: the HTTP adapter reads the repositories and the
read models directly.
Conventions for every use case
-
One transaction. The aggregate changes, their outbox rows and (for a Kafka-driven use case) the inbox row commit together. A use case that touches two aggregates (
ClaimNextMove: move and trailer;CompleteMove: move and trailer;CheckInVisit: visit, trailers and first move) does so in one unit of work, as the model'sTrailer.notesstates forStartMovingandArriveAt. -
Errors are
application/problem+json. The model assigns an HTTP status only to four generic errors:Error HTTP Problem typeslugErrNotFound404 not-foundErrIllegalTransition409 illegal-transitionErrConcurrentUpdate409 concurrent-updateErrValidation422 validation-failed -
Domain errors (
ErrLocationOccupied,ErrAppointmentRequired, ...) have a name in the model and, at first, no status. As built (decision D-10, service ADR 0002): a conflict with current state (occupancy, ownership, release, an open check) is 409; a value-object or reference rule (ErrInvalidCarrier,ErrUnknownLocation,ErrUnexplainedDestination) is 422; a malformed request is 400. The problemtypeslug is the kebab case of the name withoutErr(ErrLocationOccupiedbecomeslocation-occupied). Errors added as built:ErrNoFreeSpot(409),ErrTrailerNotOnHold(409),ErrLeaseNotExpired. -
Idempotency. Every state-changing
POSTandPUTtakes anIdempotency-Keyheader; a replay with the same key returns the first response (idempotency_keys); sweeps are naturally idempotent. Mutable aggregates carry aversion; aGETof one aggregate returns a weak ETag of it,PUT /sites/{siteId}/yard-policyhonoursIf-Match, and a stale write isErrConcurrentUpdate. Every Kafka consumer is idempotent on the CloudEventsid(inbox). -
Kafka-driven errors have no HTTP status. A policy refusal is logged and counted, the event is marked processed, and nothing is retried; an infrastructure failure rolls back and the message is redelivered.
-
Where the model was silent the flow first said proposed or this pack's reading and named the gap. The decisions that closed the gaps (Y-1 to Y-14, X1 to X7; see the Model Gap Register) are now stated in the flows; what remains marked this pack's reading is a detail the service does not state.
YardVisit
CheckInVisit
- Actor / trigger: gate clerk or kiosk (a camera or ANPR adapter issues the same command).
- Inbound adapter: REST
POST /visits. Body (OpenAPIcheckInVisit):siteId,carrier,carrierScac?,tractorPlate,driverRef?,purpose,appointmentId?,trailers(the trailers in). - Preconditions: none. A site with no declared
YardPolicyanswers the defaults (require_appointmentfalse,seal_mismatch_actionFLAG,lease_seconds300). - Main flow:
- Read the site's
YardPolicy(require_appointment,holding_spot_codes,parking_zone_ids,seal_mismatch_action). - Validate the carrier; refuse a second
CHECKED_INvisit for the plate. - If the site requires appointments, the named appointment must be
BOOKEDfor this site inAppointmentView. - Create
YardVisitinCHECKED_IN. - For each trailer brought in,
RecordArrival(below). SealCheckAtGate: compare a recorded seal with the appointment'sexpected_seal_number; a mismatch raisesSealExceptionRaised, and underREJECTthe visit is recordedREJECTEDinstead, withVisitRejected(SEAL_MISMATCH)and aSealExceptionRaisedthat has no trailer (decision Y-5).DirectOnCheckInandVisitingDriverMove: for each trailer in, create the first move,CLAIMED, performerVISITING_DRIVER, no lease. Destination: a door when the appointment's door is free, not closed and flow-compatible (reasonTO_DOOR); the holding spot when it is a walk-in or the arrival is earlier than the tolerance (TO_HOLDING); otherwise the first free spot of the parking zones by location code.- Save and write
VisitCheckedInto the outbox, one transaction.
- Read the site's
| Error | HTTP | Problem type slug |
|---|---|---|
ErrInvalidCarrier | 422 | invalid-carrier |
ErrVisitAlreadyOpen | 409 | visit-already-open |
ErrAppointmentRequired | 409 | appointment-required |
ErrTrailerAlreadyOnSite (from RecordArrival) | 409 | trailer-already-on-site |
ErrDestinationReserved (first move) | 409 | destination-reserved |
ErrValidation | 422 | validation-failed |
- Events emitted:
VisitCheckedIn;SealExceptionRaisedwhen the seal mismatches;VisitRejectedunderREJECT; analytics move events for the first move. - Idempotency:
Idempotency-Key;ErrVisitAlreadyOpenis the natural second guard. - Settled gaps: the arrival tolerance comes from the appointment copy (X1); a move to a plain spot has the
reason
TO_SPOT(Y-4); with no free spot the check-in fails withErrNoFreeSpot(Y-12); the first move has no origin, it comes from the gate (Y-1). A walk-in or an arrival earlier than the tolerance goes to the first free holding spot of the policy, or to the first free spot when none is declared (assumption A17).
RejectAtGate
- Actor / trigger: gate clerk or kiosk, when a visit must not enter.
- Inbound adapter: REST
POST /visit-rejections. Body (OpenAPIrejectAtGate):siteId,carrier,carrierScac?,tractorPlate,appointmentId?,reason(aRejectionReason). - Preconditions: none (the rejected visit never became
CHECKED_IN). - Main flow:
- Validate the carrier and the reason.
- Create
YardVisitinREJECTED; no trailer is recorded on site. - Save and write
VisitRejectedto the outbox, one transaction.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrInvalidCarrier | 422 | invalid-carrier |
ErrValidation (unknown reason) | 422 | validation-failed |
- Events emitted:
VisitRejected(consumed bydock-scheduling, which cancels the appointment withTURNED_AWAY, and byexception-management). - Idempotency:
Idempotency-Key. - Settled gap: a refused
CheckInVisitcreates nothing,RejectAtGateis the one command that records a rejection, and theREJECTseal outcome uses it (decision Y-5).
CheckOutVisit
- Actor / trigger: gate clerk or kiosk.
- Inbound adapter: REST
POST /visits/{visitId}/check-outs. Body (OpenAPIcheckOutVisit):trailersOut, naming only the trailer ids (decision Y-9). - Preconditions: the visit is
CHECKED_IN. - Main flow:
- Load the visit and the trailers it takes out.
- Every trailer is on site and released: no open move, and either
PARKEDorDOCKEDwith door workDONE(a live visit leaves from its door; decision Y-2). - Every
LOADEDtrailer taken out of aLIVE_LOADorPICKUPvisit carries a seal (ErrSealRequired). Departfor each trailer taken out (decision Y-6).- Transition
CHECKED_IN → CHECKED_OUT, computeon_site_minutes. - Save and write
VisitCheckedOut(analytics) and, per trailer,TrailerDeparted(integration and analytics since ADR 0010) andTrailerUndocked(when it left a door), one transaction.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrTrailerNotReleased | 409 | trailer-not-released |
ErrSealRequired | 409 | seal-required |
ErrDoorWorkOpen (from Depart) | 409 | door-work-open |
ErrIllegalTransition | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted:
VisitCheckedOut(analytics only),TrailerDeparted(integration, read byoutbound-shipping),TrailerUndocked. - Idempotency:
Idempotency-Key; a visit alreadyCHECKED_OUTis returned unchanged (this pack's reading).
Trailer
RecordArrival
- Actor / trigger:
CheckInVisit, once per trailer in. No route of its own. - Inbound adapter: internal (called by the visit use case).
- Preconditions: the natural key
(scac, number)is not already on site. - Main flow:
- Create
TrailerwithUnitNumber,TrailerKind,LoadState,Contents(asn_numbersfrom the appointment andAsnContentView, oroutbound_ref),SealandArrivedAt(the dwell clock start). - The trailer is created
IN_MOVEtogether with its first move, createdCLAIMED(decision Y-1);appointment_idis set from the visit. - Save.
- Create
| Error | HTTP | Problem type slug |
|---|---|---|
ErrTrailerAlreadyOnSite | 409 | trailer-already-on-site |
ErrValidation | 422 | validation-failed |
- Events emitted: none of its own (
VisitCheckedIncarries the trailers). - Idempotency: the natural key; the visit's
Idempotency-Key.
StartMoving
- Actor / trigger: the
ClaimNextMoveuse case (and, for a visiting driver's move, its creation), in the same unit of work. Not an inbound message. - Preconditions: the trailer is
PARKEDorDOCKED. - Main flow:
- Transition to
IN_MOVE; the place (spot or door) is released (decision Y-8). - When it left a door: raise
TrailerUndocked(decision Y-6).
- Transition to
| Error | HTTP | Problem type slug |
|---|---|---|
ErrIllegalTransition | 409 | illegal-transition |
- Events emitted:
TrailerUndockedwhen leaving a door (reading). - Idempotency: none of its own; the claim's.
ArriveAt
- Actor / trigger: the
CompleteMoveuse case, in the same unit of work. - Preconditions: the trailer is
IN_MOVE. - Main flow:
- The location is a known, active slot of the trailer's site (
LocationView). - For a door: not under a closure (
DoorClosureView), flow allows the trailer's direction (LocationView.dockFlow), the trailer is not on hold. Occupancy.CheckFreeon the location under a per-location advisory lock (a partial unique index is the backstop).- Transition to
PARKED(spot) orDOCKED(door); at a door,DoorWorkstartsWAITING. - Raise
TrailerParkedorTrailerDocked.
- The location is a known, active slot of the trailer's site (
| Error | HTTP | Problem type slug |
|---|---|---|
ErrUnknownLocation | 422 | unknown-location |
ErrDoorClosed | 409 | door-closed |
ErrDoorFlowMismatch | 409 | door-flow-mismatch |
ErrTrailerOnHold | 409 | trailer-on-hold |
ErrLocationOccupied | 409 | location-occupied |
ErrIllegalTransition | 409 | illegal-transition |
- Events emitted:
TrailerParked(analytics) orTrailerDocked(integration). - Idempotency: the completion's.
- Settled gaps: the destination is also validated when the move is requested, and an occupied location
at arrival is refused with the move staying
CLAIMED(decision Y-8); anEMPTYtrailer is unconstrained by door flow unless the visit purpose isLIVE_LOADorPICKUP(decision Y-9).
StartDoorWork
- Actor / trigger: dock operator (floor client).
- Inbound adapter: REST
POST /trailers/{trailerId}/door-work-starts. - Preconditions: the trailer is
DOCKEDand its door work isWAITING. - Main flow:
- Load the trailer.
- Set
DoorWorktoIN_PROGRESS. - Save and write
DoorWorkStarted(started_at) to the outbox. The driver wait KPI is arrival to this instant.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrIllegalTransition (not DOCKED) | 409 | illegal-transition |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted:
DoorWorkStarted(analytics only). - Idempotency:
Idempotency-Key; door work alreadyIN_PROGRESSis returned unchanged (this pack's reading). A held trailer's door work does not start (ErrTrailerOnHold).
CompleteDoorWork
- Actor / trigger: dock operator; policy
AutoCompleteUnloadonReceiptClosed. - Inbound adapter: REST
POST /trailers/{trailerId}/door-work-completions(body: the resultingloadState, optional); Kafka consumer ofwarehouse.inbound-receiving.eventsfor the policy. - Preconditions: the trailer is
DOCKED. - Main flow:
- Load the trailer with its
version. - Set
DoorWorktoDONEand record theload_state(EMPTYfor the policy). - Save and write
DoorWorkCompletedto the outbox. ClearDoorAfterWork: aDROPtrailer gets aHOSTLERmoveFROM_DOORto a free spot (RequestMove); aLIVEtrailer stays until its visit checks out. How the trailer knows it is a drop is the visit's purpose.
- Load the trailer with its
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrIllegalTransition (not DOCKED) | 409 | illegal-transition |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted:
DoorWorkCompleted(integration since 2026-11-09, read byoutbound-shipping). - Idempotency:
Idempotency-Key, inbox for the policy; completingDONEwork is a no-op. - Settled gap:
AutoCompleteUnloadjoins throughreceipt_idfromReceiptOpenedand completes door work (fromWAITINGorIN_PROGRESS) once every ASN on the trailer has a closed receipt (decision Y-7).
RecordSeal
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /trailers/{trailerId}/seals(body: seal number). - Preconditions: the trailer is on site.
- Main flow:
- Set
Seal{number, INTACT}. - If the trailer's appointment has an
expected_seal_numberthat differs, raiseSealExceptionRaised(SealCheckAtGate; the comparison happens when the seal arrives, decision Y-13). - Save with the version check.
- Set
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrValidation | 422 | validation-failed |
ErrIllegalTransition (DEPARTED) | 409 | illegal-transition |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted:
SealExceptionRaised(consumed byexception-management) on mismatch; none otherwise. - Idempotency:
Idempotency-Key.
BreakSeal
- Actor / trigger:
RecordSealwith stateBROKEN(POST /trailers/{trailerId}/seals); no route of its own. - Inbound adapter: the seal route (body:
state,sealNumber?). - Preconditions: the trailer is on site.
- Main flow: set
Seal.statetoBROKEN, place aSEAL_BROKENhold and save (decision Y-6, assumption A10). - Errors:
ErrNotFound,ErrIllegalTransition. - Events emitted:
TrailerHeld(analytics only). - Idempotency: a seal already
BROKENis unchanged.
PlaceHold
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /trailers/{trailerId}/holds(body:reason, aHoldReason). - Preconditions: the trailer is on site and not already held.
- Main flow:
- Set
Hold{reason}. - Save and write
TrailerHeldto the outbox. A held trailer cannot be docked (ErrTrailerOnHold); a hold on an alreadyDOCKEDtrailer is allowed and door work then waits for the release (decision Y-13).
- Set
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrValidation (unknown reason) | 422 | validation-failed |
ErrIllegalTransition (DEPARTED) | 409 | illegal-transition |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted:
TrailerHeld(analytics only). - Idempotency:
Idempotency-Key.
ReleaseHold
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /trailers/{trailerId}/hold-releases. - Preconditions: the trailer is on hold.
- Main flow: clear the hold; save; write
TrailerHoldReleased.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotFound | 404 | not-found |
ErrIllegalTransition (not held) | 409 | illegal-transition |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted:
TrailerHoldReleased(analytics only). - Idempotency:
Idempotency-Key; a trailer not held is returned unchanged (this pack's reading).
RecordLoadState
- Actor / trigger:
DoorWorkCompletedcarries aload_state, andAutoCompleteUnloadsetsEMPTY. - Inbound adapter: none of its own; the door-work completion body takes an optional
loadState. - Main flow: set
LoadState(EMPTY,LOADEDorPARTIAL); save. It is a step ofCompleteDoorWork. - Errors:
ErrNotFound,ErrValidation. - Events emitted: none of its own.
- Idempotency: setting the same value is a no-op.
Depart
- Actor / trigger:
CheckOutVisitcalls it for each trailer taken out. - Inbound adapter: none of its own (no route).
- Preconditions: the trailer is
PARKEDorDOCKED; ifDOCKED, its door work isDONE. - Main flow:
- Transition to
DEPARTED; computedwell_minutesfromArrivedAt. - Save; write
TrailerDepartedand, when it left a door,TrailerUndocked.
- Transition to
| Error | HTTP | Problem type slug |
|---|---|---|
ErrDoorWorkOpen | 409 | door-work-open |
ErrIllegalTransition (IN_MOVE or already DEPARTED) | 409 | illegal-transition |
- Events emitted:
TrailerDeparted(analytics),TrailerUndocked(integration, for a trailer leaving a door; reading). - Idempotency: the visit's.
DwellSweep
- Actor / trigger: scheduler (cron), policy
DwellSweep. - Inbound adapter: REST
POST /dwell-sweeps. - Preconditions: none.
- Main flow:
- For each trailer on site, compare its dwell (now minus
ArrivedAt) with thedwell_threshold_minutesof itsTrailerKindin the site'sYardPolicy. - For each trailer that crossed its threshold and has not been reported for it, write
TrailerDwellExceeded(dwell_minutes,threshold_minutes,location_code). - Return the count raised.
- For each trailer on site, compare its dwell (now minus
| Error | HTTP | Problem type slug |
|---|---|---|
a missing threshold for a kind (no Err...) | — | skipped, logged |
- Events emitted:
TrailerDwellExceeded(consumed byexception-management). - Idempotency: once per trailer and threshold crossing, so a rerun raises nothing new;
the marker is
dwell_alerted_aton the trailer (decision Y-13). A kind without a threshold is never alerted.
YardMove
RequestMove
- Actor / trigger: yard supervisor; policies
DirectOnCheckIn,CallToDoor,ClearDoorAfterWork. - Inbound adapter: REST
POST /moves(body, OpenAPIrequestMove:trailerId,to,reason?,priorityBand?,dueBy?); the policies call the use case in-process. - Preconditions: the trailer is on site and not
IN_MOVEwith another move. - Main flow:
- Load the trailer;
from_locationis its current place. - Refuse if the trailer has another
REQUESTEDorCLAIMEDmove. - Under the destination's advisory lock: the destination is free
(
Occupancy.CheckFree) and no other open move names it; reserve it. - Create
YardMoveinREQUESTED, performerHOSTLER. - Save and write
YardMoveRequestedto the outbox.
- Load the trailer;
| Error | HTTP | Problem type slug |
|---|---|---|
ErrTrailerHasOpenMove | 409 | trailer-has-open-move |
ErrDestinationReserved | 409 | destination-reserved |
ErrNotFound (trailer) | 404 | not-found |
ErrValidation | 422 | validation-failed |
- Events emitted:
YardMoveRequested(analytics only). - Idempotency:
Idempotency-Key; the open-move invariant is the guard. - Settled gap: the destination (known slot, closure, flow, hold) is validated at request and again at arrival
(decision Y-8). A missing
reasonis derived:TO_DOORfor a door,FROM_DOORfor a spot when the trailer isDOCKED,RELOCATEotherwise (assumption A6).
ClaimNextMove
- Actor / trigger: hostler (floor client).
- Inbound adapter: REST
POST /moves/claims(body, OpenAPIclaimNextMove:siteId,hostlerRef). - Preconditions: the hostler holds no
CLAIMEDmove. - Main flow:
- Refuse if the hostler already holds a
CLAIMEDmove. - Pick the next
REQUESTEDHOSTLERmove of the site: lowest priority band, then earliestdue_by(none last), then request time (decision Y-11), skipping rows locked by another claim. - Transition
REQUESTED → CLAIMEDwithLease{hostler_ref, expires_at}, whereexpires_at= now plus the site'slease_seconds. Trailer.StartMovingin the same unit of work.- Save and write
YardMoveClaimed.
- Refuse if the hostler already holds a
| Error | HTTP | Problem type slug |
|---|---|---|
ErrHostlerBusy | 409 | hostler-busy |
ErrConcurrentUpdate (another hostler won) | 409 | concurrent-update |
| no move available | 404 | no-claimable-move |
ErrValidation | 422 | validation-failed |
- Events emitted:
YardMoveClaimed(analytics only). - Idempotency:
Idempotency-Key; a replay returns the same claim.
CompleteMove
- Actor / trigger: the lease-holding hostler; for a
VISITING_DRIVERmove the dock operator or gate clerk (same route; decision Y-3). - Inbound adapter: REST
POST /moves/{moveId}/completions(body, OpenAPIcompleteMove:hostlerRef?,actualLocation?,deviationNote?). - Preconditions: the move is
CLAIMED. - Main flow:
- Load the move with its
version. - Only the lease holder completes it. A
VISITING_DRIVERmove has no lease. - A location other than the destination needs a reason.
Trailer.ArriveAt(actual_location), with its checks andOccupancy.CheckFree, in the same unit of work.- Transition
CLAIMED → COMPLETED; computeduration_seconds. - Save and write
YardMoveCompletedand the trailer'sTrailerParkedorTrailerDocked.
- Load the move with its
| Error | HTTP | Problem type slug |
|---|---|---|
ErrNotLeaseHolder | 409 | not-lease-holder |
ErrUnexplainedDestination | 422 | unexplained-destination |
ErrLocationOccupied, ErrDoorClosed, ErrDoorFlowMismatch, ErrTrailerOnHold, ErrUnknownLocation (from ArriveAt) | 409 / 422 | see ArriveAt |
ErrIllegalTransition (not CLAIMED, for example after lease expiry) | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted:
YardMoveCompleted(analytics),TrailerParkedorTrailerDocked. - Idempotency:
Idempotency-Key; aCOMPLETEDmove is returned unchanged.
CancelMove
- Actor / trigger: yard supervisor; policy
NoShowFreesHoldingonDockAppointmentNoShoworDockAppointmentCancelled. - Inbound adapter: REST
POST /moves/{moveId}/cancellations(body:reason); Kafka consumer ofwarehouse.dock-scheduling.eventsfor the policy. - Preconditions: the move is
REQUESTEDorCLAIMED. - Main flow:
- Load the move.
- Transition to
CANCELLED; release the destination reservation. - Save and write
YardMoveCancelled.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrIllegalTransition (COMPLETED or already CANCELLED) | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted:
YardMoveCancelled(analytics only). - Idempotency:
Idempotency-Key, inbox for the policy; aCANCELLEDmove is returned unchanged. - Settled gaps: cancelling a
CLAIMEDhostler move runsReturnToOriginin the same unit of work, so the trailer goes back where it was (decision Y-1); the policy finds the move through theappointment_idthe move carries (decision X3).
ExpireLease
- Actor / trigger: scheduler (cron), policy
LeaseExpirySweep. - Inbound adapter: REST
POST /move-lease-sweeps. - Preconditions: none.
- Main flow:
- Select
CLAIMEDmoves whoseLease.expires_atis in the past. - For each, transition
CLAIMED → REQUESTEDand clear the lease; its destination stays reserved. - Return the count.
- Select
| Error | HTTP | Problem type slug |
|---|---|---|
a move that changed since selection (no Err...) | — | skipped, next sweep |
- Events emitted:
YardMoveLeaseExpired(analytics only, decision Y-10). - Idempotency: rerunning returns the same moves to
REQUESTEDonly once. - Settled gap: the trailer goes back where
StartMovingfound it (ReturnToOrigin, decision Y-1); when that origin has since been taken it staysIN_MOVEand the moveREQUESTED(assumption A16).
YardCheck
OpenYardCheck
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /yard-checks. - Main flow: refuse if the site has an
OPENcheck; createYardCheckinOPEN; save.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrYardCheckOpen | 409 | yard-check-open |
ErrValidation | 422 | validation-failed |
- Events emitted: none (the model lists only
YardCheckClosed). - Idempotency:
Idempotency-Key;ErrYardCheckOpenis the natural guard.
RecordObservation
- Actor / trigger: yard supervisor, walking the yard.
- Inbound adapter: REST
POST /yard-checks/{yardCheckId}/observations(body:location_code,unit_number?). - Preconditions: the check is
OPEN. - Main flow: refuse a location already observed in this check; append the
Observation; save.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrLocationAlreadyObserved | 409 | location-already-observed |
ErrIllegalTransition (CLOSED) | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrValidation | 422 | validation-failed |
- Events emitted: none.
- Idempotency:
Idempotency-Key; the same observation replayed is refused by the invariant.
CloseYardCheck
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
POST /yard-checks/{yardCheckId}/closures. - Preconditions: the check is
OPEN. - Main flow:
- Compare the observations with the trailers the model places at those locations.
- Build the
Discrepancylist:MISSING,UNEXPECTEDorWRONG_LOCATION. The rules are: every observed location is compared with the trailer the model records there; a location not observed isMISSINGwhen the model records a trailer there; an observed unit that differs makes the expected trailerMISSINGand the observed unitWRONG_LOCATION(known elsewhere on site) orUNEXPECTED(unknown). Closing only reports (decision Y-11, assumption A13). - Transition
OPEN → CLOSED. - Save and write
YardCheckClosedwith the discrepancies.
| Error | HTTP | Problem type slug |
|---|---|---|
ErrIllegalTransition (CLOSED) | 409 | illegal-transition |
ErrNotFound | 404 | not-found |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted:
YardCheckClosed(consumed byexception-management, one case per discrepancy). - Idempotency:
Idempotency-Key; aCLOSEDcheck is returned unchanged.
YardPolicy
DeclareYardPolicy
- Actor / trigger: yard supervisor.
- Inbound adapter: REST
PUT /sites/{siteId}/yard-policy(If-Match for a change). - Main flow:
- Validate: holding spots are known Yard slots of the site (
LocationView); thresholds and lease are positive. - Replace the policy of the site:
require_appointment,holding_spot_codes,parking_zone_ids,dwell_threshold_minutesper kind,lease_seconds,seal_mismatch_action, optionalfree_time_minutes. - Save.
- Validate: holding spots are known Yard slots of the site (
| Error | HTTP | Problem type slug |
|---|---|---|
ErrUnknownLocation | 422 | unknown-location |
ErrValidation | 422 | validation-failed |
ErrConcurrentUpdate | 409 | concurrent-update |
- Events emitted: none (
YardPolicy.events: []). - Idempotency:
PUTreplaces; the same body is a no-op;Idempotency-Key.
Event-driven reactions that are not commands
These policies react to a Kafka event and call the use cases above; the projectors update the read models in their own transaction.
| Trigger event | Reaction | Use case called |
|---|---|---|
TrailerUndocked (own) | CallToDoor | RequestMove (HOSTLER, TO_DOOR) |
DoorWorkCompleted (own) | ClearDoorAfterWork | RequestMove (FROM_DOOR) for a DROP trailer |
ReceiptClosed (inbound-receiving) | AutoCompleteUnload | CompleteDoorWork |
DockAppointmentNoShow, DockAppointmentCancelled | NoShowFreesHolding | CancelMove |
DockAppointmentBooked, Rescheduled, Cancelled, NoShow | projector | AppointmentView |
DoorClosureScheduled, DoorClosureLifted | projector | DoorClosureView |
LocationSlotRegistered, LocationSlotDecommissioned, ZoneRegistered | projector | LocationView |
ASNRegistered, ASNCancelled | projector | AsnContentView |
ReceiptOpened, ReceiptClosed | projector | ReceiptAtDoorView |
Agent surfaces: which use cases the MCP tools and the A2A skills call
As built on develop 3bcfc22 (read 2026-12-02; internal/adapters/inbound/mcp/tools*.go
and internal/adapters/inbound/a2a/server.go, service ADRs 0007, 0013, 0015, 0020 and
0021). REST and the two agent adapters call the same use cases. The MCP server has 25
tools (11 L1, 3 L2, 11 L3; 21 in v0.1.4) and the A2A agent two skills; the gate
check-in and check-out, the visit rejection, the move claim and completion, the door
work, the observations and the closing of a yard check, the policy and the sweeps are on
neither. An L2 tool returns a recommendation and changes nothing (it raises no event, so
it takes no idempotencyKey and no attribution); an L3 tool or skill is a write: the
human approval is held by the caller, every write takes an idempotencyKey, and the
facts it raises carry initiated_by (via mcp or a2a, proposal_id, approved_by,
agent_id). The use cases the model has no command for are marked; they are described
in the service's ADRs named here.
| Surface | Tool or skill | Level | Use case called | REST twin |
|---|---|---|---|---|
| MCP | request_move | L3 | RequestMove | POST /moves |
| MCP | cancel_move | L3 | CancelMove | POST /moves/{moveId}/cancellations |
| MCP | place_hold, release_hold | L3 | PlaceHold, ReleaseHold | POST /trailers/{trailerId}/holds, POST /trailers/{trailerId}/hold-releases |
| MCP | record_seal | L3 | RecordSeal | POST /trailers/{trailerId}/seals |
| MCP | secure_trailer, release_securing | L3 | SecureTrailer, ReleaseTrailerSecuring (no model command, ADR 0013) | POST /trailers/{trailerId}/securings, POST /trailers/{trailerId}/securing-releases |
| MCP | open_yard_check | L3 | OpenYardCheck | POST /yard-checks |
| MCP | open_inspection, record_inspection_item, complete_inspection | L3 | OpenInspection, RecordInspectionItem, CompleteInspection (no model command, ADR 0015) | POST /trailers/{trailerId}/inspections, PUT /inspections/{inspectionId}/items/{itemCode}, POST /inspections/{inspectionId}/completions |
| MCP | recommend_next_door | L2 | RecommendNextDoor (no model command, ADR 0021): the waiting trailers ranked for the next free door | none |
| MCP | propose_pickup_plan | L2 | ProposePickupPlan (no model command, ADR 0021): the steps that prepare a pickup, timed backward from it | none |
| MCP | list_gate_record_gaps | L2 | ListGateRecordGaps (no model command, ADR 0021): visits with a missing check-out and units a yard check saw that the board lacks | none |
| MCP | check_time_on_site | L1 | CheckTimeOnSite (no model command, ADR 0021) | none |
| MCP | get_yard_board, list_trailers, get_trailer, list_moves, list_visits, get_visit, get_yard_policy, get_yard_dwell_report, get_inspection, list_trailer_inspections | L1 | GetYardBoard, ListTrailers, GetTrailer, ListMoves, ListVisits, GetVisit, GetYardPolicy, Reports.YardDwell, GetInspection, ListTrailerInspections | the GET routes |
| A2A | yard_status | L1 | GetTrailer, ListTrailers, GetYardBoard | the MCP twins get_trailer, list_trailers, get_yard_board |
| A2A | request_yard_move | L3 | RequestMove | the MCP twin request_move; REST POST /moves |