openapi: 3.0.3 info: title: Workforce Management API version: "1.0.0" contact: name: claudioed email: claudioed.oliveira@gmail.com description: | Workforce Management is a Supporting bounded context that owns "who is on shift, on which process path, at what rate; direct vs indirect hours." It covers two things: 1. **The shift-start planning horizon** — a human proposes and then commits a split of headcount across process paths (`ShiftPlan`, made of `PathPlan` lines: path, planned heads, planned rate, planned hours), one plan per site per shift (the plan key is the canonical `siteCode`; `buildingId` is its deprecated alias, ADR 0035). 2. **Intra-shift assignment tracking** — moving associates between paths as backlogs deviate from plan (`LaborAssignment`). The move itself is always a human call; this context makes the staffing gap legible (`GetStaffingGap` / `PathUnderstaffed`), it never decides or performs a rebalance on its own. Three aggregates back the API: `AssociateShift` (roster entry — certifications, break state, logged hours), `ShiftPlan` (committed headcount split across paths), and `LaborAssignment` (one associate, one path, an interval — exactly one ACTIVE assignment per associate at a time, and an assignment is rejected if the associate lacks the path's required certification). **Where this context's boundary stops:** it never links an associate to a specific task, and it never dispatches work — that is Fulfillment Execution's job, against a completely different cadence (shifts/hours here vs. seconds there for task claiming). Keeping the seam at "this associate is on this path" lets task-dispatch policy change without touching workforce planning, and vice versa. All error responses use RFC 7807 (`application/problem+json`); see the shared `Problem` schema. servers: - url: http://localhost:8080 description: Local development tags: - name: Associates description: >- The AssociateShift aggregate: starting/ending a roster entry for a shift, certifications, and break state. - name: Shift Plans description: >- The ShiftPlan aggregate: proposing and committing the headcount split across process paths for one site's shift (keyed by the canonical `siteCode`; `buildingId` is the deprecated alias, ADR 0035). - name: Assignments description: >- The LaborAssignment aggregate: putting an associate on a path for an interval, enforcing the certification gate and the one-active- assignment-per-associate invariant. - name: Staffing description: >- Read model surfacing the gap between a path's committed plannedHeads and its currently active assignments. - name: System description: Operational endpoints not scoped to a domain aggregate. paths: /healthz: get: operationId: healthz summary: Liveness check description: >- Returns 200 with a static status body if the process is up and serving. Does not check downstream dependencies (e.g. Postgres connectivity) — it is a liveness probe, not a readiness probe. tags: [System] responses: "200": description: Service is up. content: application/json: schema: $ref: "#/components/schemas/HealthzResponse" example: status: ok /readyz: get: operationId: readyz summary: Readiness check description: >- Reports whether this instance should receive traffic. Returns 200 `{"status":"ready"}` only while serving AND Postgres answers a ping AND a Kafka broker answers a metadata request (ADR-0038; topics are never required and the verdict is cached for 3 s). Returns 503 `{"status":"not_ready"}` once graceful shutdown has begun (ADR-0022): readiness is flipped first so a Kubernetes readinessProbe stops routing new requests during the drain window, while the liveness probe (`/healthz`) stays green. Returns 503 problem+json (`dependency-unavailable`) naming `postgres` and/or `kafka` while a dependency is unreachable. tags: [System] responses: "200": description: Instance is ready to receive traffic. content: application/json: schema: $ref: "#/components/schemas/ReadyzResponse" example: status: ready "503": description: >- Instance is draining for shutdown (`not_ready`) or a runtime dependency (Postgres, Kafka) is unavailable (`dependency-unavailable`); it must not receive new traffic. content: application/json: schema: $ref: "#/components/schemas/ReadyzResponse" example: status: not_ready application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/dependency-unavailable title: A runtime dependency is unavailable status: 503 detail: "not ready: kafka" instance: /readyz /associates/{id}/shift-starts: post: operationId: startAssociateShift summary: Start an associate's shift description: >- Creates a new AssociateShift roster entry for this shift, with an initial set of certifications, raising AssociateShiftStarted. The associate id is client-supplied and this endpoint is naturally idempotent by that id: calling it twice for the same associate upserts the roster entry rather than erroring (each call still re-raises AssociateShiftStarted and returns 201). The optional siteCode records the canonical site the associate works at (ADR 0034) so the staffing gap can be scoped to a site. tags: [Associates] parameters: - $ref: "#/components/parameters/IdempotencyKey" - $ref: "#/components/parameters/AssociateId" requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/StartShiftRequest" example: certifications: ["pack"] siteCode: WH1 responses: "201": description: >- Shift started. Location points at the associate resource (this service has no GET route for an individual associate yet; the URI identifies the resource per RFC 7231 §7.1.2 regardless). headers: Idempotency-Replayed: $ref: "#/components/headers/IdempotencyReplayed" Location: description: URI of the started associate's shift resource. schema: type: string example: /associates/assoc-1 content: application/json: schema: $ref: "#/components/schemas/StartShiftResponse" example: associateId: assoc-1 "400": $ref: "#/components/responses/BadRequest" "409": description: >- Conflict — this associate's roster entry was concurrently modified by another request between when it was read and when this write was attempted (concurrent-modification, ADR 0021). Only possible on a restart (the associate already has a roster entry) racing another concurrent write for the same associate; reload and retry. Also returned (idempotency-key-reused) when the Idempotency-Key was already used with a different request (method, path or body). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/concurrent-modification title: The resource was modified by another request; reload and retry status: 409 detail: aggregate was concurrently modified; reload and retry instance: /associates/assoc-1/shift-starts "500": $ref: "#/components/responses/InternalError" /associates/{id}/certifications: post: operationId: certifyAssociate summary: Add a certification to an associate description: >- Adds a named qualification (e.g. "pack", "hazmat", "pick") to an already-started AssociateShift, raising AssociateCertified. An associate untrained on a path cannot be assigned to it (see POST /associates/{id}/assignments). Adding a certification the associate already holds is a no-op on state (set semantics) but still re-raises the event and returns 204 — certifications are not independently addressable sub-resources, so this returns 204 rather than 201. tags: [Associates] parameters: - $ref: "#/components/parameters/IdempotencyKey" - $ref: "#/components/parameters/AssociateId" requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CertifyRequest" example: certification: hazmat responses: "204": headers: Idempotency-Replayed: $ref: "#/components/headers/IdempotencyReplayed" description: Certification added. No response body. "400": $ref: "#/components/responses/BadRequest" "404": $ref: "#/components/responses/NotFound" "409": description: >- Conflict — the associate's shift has already ended (associate-shift-ended), or this associate's roster entry was concurrently modified by another request between when it was read and when this write was attempted (concurrent-modification, ADR 0021); reload and retry. Also returned (idempotency-key-reused) when the Idempotency-Key was already used with a different request (method, path or body). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/associate-shift-ended title: Associate shift has already ended status: 409 detail: associate shift has already ended instance: /associates/assoc-1/certifications "500": $ref: "#/components/responses/InternalError" /paths/{pathId}/plan-proposals: post: operationId: proposePathPlan summary: Propose planned heads for a path (pure computation, not committed) description: >- Two forms (ADR 0043). FROM THE LABOUR PLAN: omit `charge` and name `shiftId` (with `siteCode`): `proposedHeads` is the `planned_heads` warehouse-planning published for (siteCode, shiftId, pathId) in LabourPlanCommitted (this service keeps a local copy), `resolvedRate` its `rate_units_per_hour`, `rateSource` is `labour-plan` and NO idle-share trim applies; nothing published is 404 labour-plan-not-found, never zero heads. CHARGE-BASED (DEPRECATED, unchanged; removed only by a later ADR once no caller sends a charge): a request with `charge`, even one that also names `shiftId`, works as described below. Neither `charge` nor `shiftId` is 400 missing-charge. Both forms raise ShiftPlanProposed. Computes `heads = ceil(charge / plannedRate)` for one path and raises ShiftPlanProposed for visibility — it persists nothing and commits nothing. A human must still call POST /shift-plans to commit an actual ShiftPlan. This is why the response is 200, not 201: no resource is created. When a high observed idle share (idleness-as-staffing-signal, fed back from labor-performance via `LABOR_PERFORMANCE_MODE=kafka-cache`) is available for this path's task type and exceeds `IDLE_SHARE_TRIM_THRESHOLD` (default 0.30), the computed heads are further trimmed (floored at 1 head minimum) and `trimReason` explains why — fail-open: no idle-share signal available applies no trim. tags: [Shift Plans] parameters: - $ref: "#/components/parameters/IdempotencyKey" - $ref: "#/components/parameters/PathId" requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ProposePathPlanRequest" examples: fromLabourPlan: summary: Heads from warehouse-planning's published labour plan (ADR 0043) value: siteCode: WH1 shiftId: 2026-11-18-day chargeBased: summary: DEPRECATED charge-based proposal (unchanged) value: siteCode: WH1 charge: 100 plannedRate: 30 responses: "200": headers: Idempotency-Replayed: $ref: "#/components/headers/IdempotencyReplayed" description: Proposed heads for this path, not committed. content: application/json: schema: $ref: "#/components/schemas/ProposePathPlanResponse" example: pathId: pack proposedHeads: 4 resolvedRate: 30 rateSource: caller "400": $ref: "#/components/responses/BadRequest" "404": description: >- No charge was sent and warehouse-planning has published no labour plan for (siteCode, shiftId, pathId) (labour-plan-not-found, ADR 0043). Never answered as zero heads. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/labour-plan-not-found title: No labour plan has been published for this site, shift and path status: 404 detail: 'site "WH1" shift "2026-11-18-day" path "pack": no labour plan has been published for this site, shift and path' instance: /paths/pack/plan-proposals "409": $ref: "#/components/responses/IdempotencyKeyReused" "422": $ref: "#/components/responses/ConflictingSiteAndBuilding" "500": $ref: "#/components/responses/InternalError" /shift-plans: post: operationId: commitShiftPlan summary: Commit a shift's headcount split across paths description: >- Commits a human-decided ShiftPlan: one or more PathPlan lines (path, plannedHeads, plannedRate, plannedHours), raising ShiftPlanCommitted. Validates, per line, that plannedHeads does not exceed the caller-supplied installedStations for that path (this context enforces the invariant independently — it has no dependency on Work Planning, which owns installed-station counts — the request carries the number it needs), that plannedHeads does not exceed the LIVE installed capacity fulfillment-execution reports for that path's capability (a SEPARATE, independent check — see ADR-0014; fetched fresh on every commit, and this service fails the entire commit loud, without any fallback, if fulfillment-execution cannot be reached). The capability is resolved through the process-path catalogue, never taken from pathId: a path's live ceiling is the number of stations registered with each of its declared requiredCapabilities (the smallest count when it declares several), so pathId PICK (or pick-zone-a) is checked against stations holding capability pick. A pathId the catalogue does not declare is rejected with 400 unknown-path-id. It also validates that plannedHours does not exceed plannedHeads * the configured max hours per shift. Naturally idempotent by the client-supplied (siteCode, shiftId) key (siteCode is the canonical name of the plan key, buildingId its deprecated alias with the same value and the same stored column; ADR 0035): the underlying repository upserts on that key. A blind retry would nevertheless re-publish ShiftPlanCommitted, so this route is also protected by the Idempotency-Key header (ADR-0027, ADR-0044): a retried request with the same key and body replays the first response without committing or publishing again — unless the first answer was RETRYABLE (e.g. exceeds-installed-capacity, concurrent-modification), which is not stored: the key is released and the retry executes again. tags: [Shift Plans] parameters: - $ref: "#/components/parameters/IdempotencyKey" requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CommitShiftPlanRequest" example: siteCode: WH1 shiftId: shift-1 lines: - pathId: pack plannedHeads: 3 plannedRate: 30 plannedHours: 24 installedStations: 10 - pathId: pick plannedHeads: 2 plannedRate: 25 plannedHours: 16 installedStations: 10 responses: "201": description: Shift plan committed. headers: Idempotency-Replayed: $ref: "#/components/headers/IdempotencyReplayed" Location: description: URI of the committed shift plan. schema: type: string example: /shift-plans/WH1/shift-1 content: application/json: schema: $ref: "#/components/schemas/ShiftPlanResponse" example: siteCode: WH1 buildingId: WH1 shiftId: shift-1 lines: - pathId: pack plannedHeads: 3 plannedRate: 30 plannedHours: 24 "400": description: >- Malformed body, an empty required field (siteCode or its deprecated alias buildingId, shiftId, or a line's pathId), no path plan lines supplied (shift-plan-no-path-plans), a line references a path with no installedStations entry (shift-plan-missing-installed-stations), a line's pathId is not declared by the process-path catalogue (unknown-path-id), or the Idempotency-Key header is missing on a deployment with Postgres (idempotency-key-required, ADR-0027). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/shift-plan-no-path-plans title: Shift plan must have at least one path plan line status: 400 detail: shift plan must have at least one path plan line instance: /shift-plans "409": description: >- Conflict — a line's plannedHeads exceeds installedStations (planned-heads-exceed-installed), a line's plannedHeads exceeds the LIVE installed capacity fulfillment-execution reports for that path's capability, resolved from the process-path catalogue's requiredCapabilities (exceeds-installed-capacity — see ADR-0014; this is a SEPARATE, independent check from installedStations), or plannedHours exceeds what plannedHeads can work within the shift's max hours (planned-hours-exceed-capacity). Also returned (idempotency-key-reused) when the Idempotency-Key was already used with a different request (method, path or body). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/planned-heads-exceed-installed title: Planned heads exceed installed stations for path status: 409 detail: planned heads exceed installed stations for path instance: /shift-plans "422": description: >- Unprocessable — siteCode and its deprecated alias buildingId were both sent with DIFFERENT values (conflicting-site-and-building, ADR 0035). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/conflicting-site-and-building title: siteCode and its deprecated alias buildingId have different values status: 422 detail: siteCode and buildingId (a deprecated alias of siteCode) are both present with different values instance: /shift-plans "500": $ref: "#/components/responses/InternalError" "503": description: >- Service unavailable — fulfillment-execution could not be reached to verify installed capacity for one or more path lines (installed-capacity-unavailable). This service fails the ENTIRE commit loud in this case rather than falling back to any assumed capacity, since a shift-plan commit mutates real state — see ADR-0014. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/installed-capacity-unavailable title: Could not verify installed capacity against fulfillment-execution status: 503 detail: installed capacity unavailable instance: /shift-plans /associates/{id}/assignments: post: operationId: assignLabor summary: Assign an associate to a path description: >- Puts an associate on pathId for a new interval, raising LaborAssigned (first assignment) or LaborReassigned (an assignment was already active). The "exactly one ACTIVE assignment per associate" invariant is enforced by construction, not by rejecting a second call: if the associate already has an active assignment, it is closed first (its hours are logged against the associate's shift) and the new one starts — this matches how rebalancing actually happens on the floor, a supervisor moves someone without first "unassigning" them. The assignment requires the associate hold the path's required certification (by convention, the Certification with the same name as the PathId — e.g. path "pack" requires certification "pack"), and is rejected if the associate is currently on a logged break or their shift has ended. Because each call closes the prior interval and raises an event, a blind retry would double-apply it, so this route is protected by the Idempotency-Key header (ADR-0027, ADR-0044): a retried request with the same key and body replays the first response — unless the first answer was RETRYABLE (e.g. certification-required, associate-on-break, concurrent-modification), which is not stored: the key is released and the retry executes again once the state allows it. tags: [Assignments] parameters: - $ref: "#/components/parameters/AssociateId" - $ref: "#/components/parameters/IdempotencyKey" requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AssignLaborRequest" example: pathId: pack responses: "201": description: >- Associate assigned. Location points at this associate's assignment resource (at most one active assignment exists per associate, so the collection URI identifies it). headers: Idempotency-Replayed: $ref: "#/components/headers/IdempotencyReplayed" Location: description: URI of the associate's assignment resource. schema: type: string example: /associates/assoc-1/assignments content: application/json: schema: $ref: "#/components/schemas/AssignmentResponse" example: associateId: assoc-1 activePathId: pack active: true "400": $ref: "#/components/responses/BadRequest" "404": $ref: "#/components/responses/NotFound" "409": description: >- Conflict — the associate lacks the required certification for this path (certification-required), is currently on a logged break (associate-on-break), their shift has ended (associate-shift-ended), closing the prior active assignment would push logged hours over the configured max per shift (max-hours-exceeded), or this associate's roster entry or active assignment was concurrently modified by another request between when it was read and when this write was attempted (concurrent-modification, ADR 0021); reload and retry. Also returned (idempotency-key-reused) when the Idempotency-Key was already used with a different request (method, path or body). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/certification-required title: Associate lacks the certification required for this path status: 409 detail: associate lacks the certification required for this path instance: /associates/assoc-1/assignments "500": $ref: "#/components/responses/InternalError" /associates/{id}/break-starts: post: operationId: startAssociateBreak summary: Start a logged break for an associate description: >- Begins a logged break for the associate, raising AssociateBreakStarted. While on break, the associate cannot receive a new labor assignment (see POST /associates/{id}/assignments). Not idempotent: calling this while already on break is rejected as a conflict rather than treated as a no-op, since it represents a discrete state transition, not an upsert. tags: [Associates] parameters: - $ref: "#/components/parameters/IdempotencyKey" - $ref: "#/components/parameters/AssociateId" responses: "204": headers: Idempotency-Replayed: $ref: "#/components/headers/IdempotencyReplayed" description: Break started. No response body. "400": $ref: "#/components/responses/BadRequest" "404": $ref: "#/components/responses/NotFound" "409": description: >- Conflict — the associate is already on break (associate-already-on-break), their shift has already ended (associate-shift-ended), or this associate's roster entry was concurrently modified by another request between when it was read and when this write was attempted (concurrent-modification, ADR 0021); reload and retry. Also returned (idempotency-key-reused) when the Idempotency-Key was already used with a different request (method, path or body). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/associate-already-on-break title: Associate is already on break status: 409 detail: associate is already on break instance: /associates/assoc-1/break-starts "500": $ref: "#/components/responses/InternalError" /associates/{id}/break-ends: post: operationId: endAssociateBreak summary: End a logged break for an associate description: >- Ends the associate's current logged break, raising AssociateBreakEnded. Not idempotent: calling this while not on break is rejected as a conflict rather than treated as a no-op. tags: [Associates] parameters: - $ref: "#/components/parameters/IdempotencyKey" - $ref: "#/components/parameters/AssociateId" responses: "204": headers: Idempotency-Replayed: $ref: "#/components/headers/IdempotencyReplayed" description: Break ended. No response body. "400": $ref: "#/components/responses/BadRequest" "404": $ref: "#/components/responses/NotFound" "409": description: >- Conflict — the associate is not currently on break (associate-not-on-break), their shift has already ended (associate-shift-ended), or this associate's roster entry was concurrently modified by another request between when it was read and when this write was attempted (concurrent-modification, ADR 0021); reload and retry. Also returned (idempotency-key-reused) when the Idempotency-Key was already used with a different request (method, path or body). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/associate-not-on-break title: Associate is not on break status: 409 detail: associate is not on break instance: /associates/assoc-1/break-ends "500": $ref: "#/components/responses/InternalError" /paths/{pathId}/staffing-gap: get: operationId: getStaffingGap summary: Get the staffing gap for a path within a committed shift plan description: >- Read-model projection: plannedHeads (from the committed ShiftPlan for siteCode+shiftId) vs. currently active LaborAssignment count for pathId. Raises PathUnderstaffed when active assignments fall short of plannedHeads. This surfaces the gap only — it never decides or performs a rebalance; that stays a human call recorded via POST /associates/{id}/assignments. ShiftPlan is keyed by site+shift, so both are needed as query parameters alongside the path in the URL — a path's planned heads only make sense within one committed plan. `siteCode` is the canonical name (ADR 0035): it is the plan lookup key AND the associate scope (activeHeads counts only associates with an active shift at that site, ADR 0034). `buildingId` is the DEPRECATED alias for the plan lookup ONLY: a call that gives just buildingId is NOT scoped by site and counts fleet-wide, exactly as before. One of the two is required (neither is 400 missing-building-id). When both are given, buildingId is the plan key and siteCode the scope, as ADR 0034 defined. tags: [Staffing] parameters: - $ref: "#/components/parameters/PathId" - name: siteCode in: query required: false description: >- The canonical Site code (the facility-layout Site code, e.g. WH1): plan lookup key AND associate scope. Required unless the deprecated buildingId is given. Accepted as given, never validated against facility-layout, so an unknown code simply counts 0. schema: type: string example: WH1 - name: buildingId in: query required: false deprecated: true description: >- DEPRECATED -- use siteCode. The legacy name of the plan key: alias for the plan lookup ONLY (same stored value). A call that gives only buildingId is not scoped by site. Required unless siteCode is given. schema: type: string example: bldg-1 - name: shiftId in: query required: true description: The shift (within the site) whose committed plan to read. schema: type: string example: shift-1 responses: "200": description: Staffing gap for this path within the committed plan. content: application/json: schema: $ref: "#/components/schemas/StaffingGapResponse" example: pathId: pack plannedHeads: 3 activeHeads: 1 understaffed: true observedIdleShare: 0.42 observedIdlePct: 0.42 siteCode: WH1 "400": $ref: "#/components/responses/BadRequest" "404": description: >- No committed ShiftPlan exists for siteCode (or buildingId) + shiftId (resource-not-found). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/resource-not-found title: Resource not found status: 404 detail: not found instance: /paths/pack/staffing-gap "500": $ref: "#/components/responses/InternalError" /sites/{siteCode}/shifts/{shiftId}/staffing-gap: get: operationId: listStaffingGapsForSiteShift summary: >- List the staffing gap for every path planned within one committed shift plan of a site (canonical route) description: >- The canonical route of the all-paths staffing-gap list (ADR 0035; supersedes GET /buildings/{buildingId}/shifts/{shiftId}/staffing-gap, which stays as a deprecated alias). Same handler core and response shape. The path siteCode is both the plan lookup key and the associate scope: every path's activeHeads counts only associates with an active shift at that site (ADR 0034). Reuses the exact same per-path computation as GET /paths/{pathId}/staffing-gap and raises PathUnderstaffed for every understaffed path in the plan. This surfaces the gaps only — it never decides or performs a rebalance; that stays a human call recorded via POST /associates/{id}/assignments. tags: [Staffing] parameters: - $ref: "#/components/parameters/SiteCodePath" - $ref: "#/components/parameters/ShiftId" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" responses: "200": description: >- Staffing gap for every path planned in this site's committed shift, one entry per path, scoped to the site. content: application/json: schema: $ref: "#/components/schemas/StaffingGapPage" example: items: - pathId: pack plannedHeads: 3 activeHeads: 1 understaffed: true observedIdleShare: 0.42 observedIdlePct: 0.42 siteCode: WH1 - pathId: pick plannedHeads: 1 activeHeads: 1 understaffed: false siteCode: WH1 "400": $ref: '#/components/responses/BadRequest' "404": description: >- No committed ShiftPlan exists for siteCode+shiftId (resource-not-found). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/resource-not-found title: Resource not found status: 404 detail: not found instance: /sites/WH1/shifts/shift-1/staffing-gap "500": $ref: "#/components/responses/InternalError" /buildings/{buildingId}/shifts/{shiftId}/staffing-gap: get: operationId: listStaffingGapsForShift deprecated: true summary: >- DEPRECATED -- use GET /sites/{siteCode}/shifts/{shiftId}/staffing-gap. List the staffing gap for every path planned within one committed shift plan (fleet-wide, all-paths view) description: >- DEPRECATED alias of GET /sites/{siteCode}/shifts/{shiftId}/staffing-gap (ADR 0035): buildingId is the legacy name of the plan key. Every response carries the header `Deprecation: true`. It keeps working, unchanged, until a later breaking ADR removes it; a call that gives only the buildingId path segment is NOT scoped by site. ADR-0011's deferred fast-follow: a fleet-wide "all paths, one building/shift" list endpoint, for contexts that need every path's staffing gap for a building+shift in one call rather than one request per path. Reuses the exact same per-path computation as GET /paths/{pathId}/staffing-gap — the two can never disagree for a given path — and raises PathUnderstaffed for every understaffed path in the plan. This surfaces the gaps only — it never decides or performs a rebalance; that stays a human call recorded via POST /associates/{id}/assignments. The optional siteCode query parameter scopes every path's activeHeads to one canonical site (ADR 0034); without it the list is fleet-wide, as before. tags: [Staffing] parameters: - $ref: "#/components/parameters/BuildingId" - $ref: "#/components/parameters/ShiftId" - $ref: "#/components/parameters/SiteCodeQuery" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" responses: "200": description: >- Staffing gap for every path planned in this building's committed shift, one entry per path. headers: Deprecation: description: >- `true` -- this route is deprecated in favour of /sites/{siteCode}/shifts/{shiftId}/staffing-gap (ADR 0035). Present on every response of this route, errors included. schema: type: string example: "true" content: application/json: schema: $ref: "#/components/schemas/StaffingGapPage" example: items: - pathId: pack plannedHeads: 3 activeHeads: 1 understaffed: true observedIdleShare: 0.42 observedIdlePct: 0.42 - pathId: pick plannedHeads: 1 activeHeads: 1 understaffed: false "400": $ref: '#/components/responses/BadRequest' "404": description: >- No committed ShiftPlan exists for buildingId+shiftId (resource-not-found). Also carries `Deprecation: true`. headers: Deprecation: description: "`true` -- this route is deprecated (ADR 0035)." schema: type: string example: "true" content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/resource-not-found title: Resource not found status: 404 detail: not found instance: /buildings/bldg-1/shifts/shift-1/staffing-gap "500": $ref: "#/components/responses/InternalError" /associates/{id}/shift-ends: post: operationId: endAssociateShift summary: End an associate's shift description: >- Closes the associate's shift, raising AssociateShiftEnded. Any currently active LaborAssignment is closed first (its hours logged against the shift). Idempotent: ending an already-ended shift is a no-op — no error, no event, still 204. tags: [Associates] parameters: - $ref: "#/components/parameters/IdempotencyKey" - $ref: "#/components/parameters/AssociateId" responses: "204": headers: Idempotency-Replayed: $ref: "#/components/headers/IdempotencyReplayed" description: Shift ended (or was already ended). No response body. "400": $ref: "#/components/responses/BadRequest" "404": $ref: "#/components/responses/NotFound" "409": description: >- Conflict — closing the active assignment's hours would exceed the configured max hours per shift (max-hours-exceeded), or this associate's roster entry or active assignment was concurrently modified by another request between when it was read and when this write was attempted (concurrent-modification, ADR 0021); reload and retry. Also returned (idempotency-key-reused) when the Idempotency-Key was already used with a different request (method, path or body). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/max-hours-exceeded title: Max hours per shift exceeded status: 409 detail: logging these hours would exceed the max hours per shift instance: /associates/assoc-1/shift-ends "500": $ref: "#/components/responses/InternalError" components: parameters: Limit: name: limit in: query required: false description: Page size, 1-500 (default 100). Empty or repeated is 400 invalid-limit. schema: type: integer minimum: 1 maximum: 500 default: 100 Cursor: name: cursor in: query required: false description: >- Opaque page token from the previous page's nextCursor; repeat the same filters. Undecodable or repeated is 400 invalid-cursor. Any other undeclared query parameter is 400 unknown-query-parameter. schema: type: string AssociateId: name: id in: path required: true description: The associate's identity (AssociateId). schema: type: string minLength: 1 example: assoc-1 PathId: name: pathId in: path required: true description: >- The process path's identity (e.g. "pack", "pick", "stow"). By convention, the Certification required to be assigned to a path has the same name as the PathId. schema: type: string minLength: 1 example: pack BuildingId: name: buildingId in: path required: true deprecated: true description: >- DEPRECATED -- the legacy name of the plan key; use the /sites/{siteCode}/... route (ADR 0035). The building whose committed shift plan to read. NOT auto-scoped by site. schema: type: string minLength: 1 example: bldg-1 SiteCodePath: name: siteCode in: path required: true description: >- The canonical Site code (the facility-layout Site code, e.g. WH1). It is both the plan lookup key AND the associate scope: activeHeads counts only assignments whose associate has an active (not-ended) shift at that site (ADR 0034, ADR 0035). The key is the resource identity and is used exactly as given (never trimmed); it is not required to be a canonical facility-layout code, because plans written under a legacy buildingId are read here too (ADR 0035). It is never validated against facility-layout: a key with no plan is 404. schema: type: string minLength: 1 example: WH1 ShiftId: name: shiftId in: path required: true description: The shift (within the site) whose committed plan to read. schema: type: string minLength: 1 example: shift-1 SiteCodeQuery: name: siteCode in: query required: false description: >- ADDITIVE and optional (ADR 0034). The canonical Site code (the facility-layout Site code, e.g. WH1). When given, activeHeads counts only assignments whose associate has an active (not-ended) shift at that site; associates started without a site (including every row that predates this parameter) never match a site. Absent or blank keeps the original behaviour exactly: a fleet-wide count across every site. The code is accepted as given, never validated against facility-layout, so an unknown code simply counts 0. schema: type: string example: WH1 IdempotencyKey: name: Idempotency-Key in: header required: true description: >- Caller-generated key (e.g. a UUID v4) that makes a retried request safe (ADR-0027). Required on every POST: the service runs on Postgres in every deployment (ADR-0038) and rejects a request without it with 400 idempotency-key-required. Reuse the SAME key for retries of one logical request (same body) — the first response is stored and replayed byte-for-byte for the key's TTL (24h by default) when it is final for that request: a 2xx, a request-shape 400/422, or a FINAL conflict whose every operand the request itself carries (planned-heads-exceed-installed, planned-hours-exceed-capacity) — and a NEW key for each new logical request. A RETRYABLE refusal (404 resource-not-found or labour-plan-not-found, 400 unknown-path-id, the associate-state 409s, exceeds-installed-capacity, concurrent-modification) is NOT stored (ADR-0044): the key is released, so the same key and body executes again once the state allows it — and a different body under that key is a new request, not a 409. A 5xx answer is never stored: the request's writes and the key roll back, so a retry with the same key runs again. Reusing a key with a different request (method, path or body) is rejected with 409 idempotency-key-reused. A key that is not 1-128 printable ASCII characters that start and end with a visible character is a 400 idempotency-key-invalid. The pattern describes the header as sent on the wire (ADR-0042): the key itself (1-128 characters, visible first and last character), optionally followed by spaces or tabs. That trailing whitespace is HTTP optional whitespace (RFC 9112 field-line grammar): the HTTP stack drops it before the service reads the value (RFC 9110 section 5.5), so it is never part of the key. Leading whitespace is not in the pattern because HTTP clients do not send it. Every POST of this service takes the key; the key is global (looked up by key alone), so one key must never be reused across routes. schema: type: string minLength: 1 pattern: '^[!-~]([ -~]{0,126}[!-~])?[ \t]*$' example: 3f1d6a4e-9c0b-4a39-8f0f-5b2d1c7e9a10 headers: IdempotencyReplayed: description: >- "true" when this answer is the stored replay of an earlier request with the same Idempotency-Key and fingerprint; absent on the first execution. schema: type: string enum: ["true"] responses: BadRequest: description: >- Malformed JSON body, or a required field was missing/empty (empty-associate-id, empty-path-id, empty-certification, missing-building-id -- neither siteCode nor its deprecated alias buildingId was sent --, missing-shift-id, missing-charge, unknown-path-id -- a pathId the process-path catalogue does not declare --, or malformed-request-body). The two staffing-gap list routes also answer 400 for a bad paging query: invalid-limit (not an integer 1-500, empty or repeated), invalid-cursor (undecodable or repeated) and unknown-query-parameter (any query parameter other than limit, cursor and, on the deprecated route, siteCode). On every POST a missing Idempotency-Key header is also a 400 (idempotency-key-required) and a malformed one (not 1-128 printable ASCII starting and ending with a visible character) a 400 (idempotency-key-invalid). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/empty-certification title: Certification must not be empty status: 400 detail: certification must not be empty instance: /associates/assoc-1/shift-starts NotFound: description: The referenced associate has no started shift (resource-not-found). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/resource-not-found title: Resource not found status: 404 detail: not found instance: /associates/ghost/certifications ConflictingSiteAndBuilding: description: >- The request carried both the canonical siteCode and its deprecated alias buildingId with DIFFERENT values (conflicting-site-and-building, ADR 0035). They name the same thing; send one, or send the same value in both. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/conflicting-site-and-building title: siteCode and its deprecated alias buildingId have different values status: 422 detail: siteCode and buildingId (a deprecated alias of siteCode) are both present with different values instance: /paths/pack/plan-proposals IdempotencyKeyReused: description: >- The Idempotency-Key was already used with a different request (method, path or body) (idempotency-key-reused, ADR-0027). Use a new key for a genuinely different request. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/idempotency-key-reused title: Idempotency-Key was already used with a different request status: 409 detail: The Idempotency-Key header on this request was already used with a different request (method, path or body). Use a new Idempotency-Key for a genuinely different request. instance: /shift-plans InternalError: description: >- Unclassified failure (e.g. a persistence or event-publish error) — internal-error. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" example: type: https://errors.workforce-management.warehouse-systems.dev/internal-error title: Internal server error status: 500 detail: connection refused instance: /shift-plans schemas: Problem: type: object description: >- RFC 7807 (https://www.rfc-editor.org/rfc/rfc7807) Problem Details for HTTP APIs. Used for every error response in this service, with Content-Type: application/problem+json. required: [type, title, status, detail] properties: type: type: string format: uri description: >- A URI identifying the error CATEGORY (not this specific occurrence). Does not need to resolve to a real page. example: https://errors.workforce-management.warehouse-systems.dev/associate-shift-ended title: type: string description: Fixed, category-level human-readable summary. example: Associate shift has already ended status: type: integer format: int32 description: The HTTP status code, duplicated here per RFC 7807. example: 409 detail: type: string description: The specific error message for this occurrence. example: associate shift has already ended instance: type: string description: The request path that produced this error. example: /associates/assoc-1/certifications HealthzResponse: type: object required: [status] properties: status: type: string example: ok ReadyzResponse: type: object required: [status] properties: status: type: string enum: [ready, not_ready] example: ready StartShiftRequest: type: object properties: certifications: type: array nullable: true description: >- Initial certifications the associate holds at shift start. May be empty or null (both mean "none yet" — null is treated exactly like omitting the field) — certifications can be added later via POST /associates/{id}/certifications. Each entry must be non-empty. items: type: string minLength: 1 example: ["pack", "hazmat"] siteCode: type: string nullable: true description: >- ADDITIVE and optional (ADR 0034). The canonical Site code (the facility-layout Site code, e.g. WH1 -- the same identifier warehouse-planning carries as site_id) this associate works at for the shift. Omitted, null or blank all leave the site unknown (null is treated exactly like omitting the field): such an associate counts only in UNSCOPED staffing-gap queries. The code is accepted as given -- this context never validates it against facility-layout. A restart (second call for the same associate) replaces the roster entry, site included. example: WH1 example: certifications: ["pack"] siteCode: WH1 StartShiftResponse: type: object required: [associateId] properties: associateId: type: string example: assoc-1 CertifyRequest: type: object required: [certification] properties: certification: type: string minLength: 1 description: The certification name to add (e.g. "hazmat"). example: hazmat ProposePathPlanRequest: type: object description: >- The ShiftPlan key is the canonical `siteCode`; `buildingId` is its DEPRECATED alias (same value; ADR 0035). Send at least one. Both present with different values is rejected with 422 conflicting-site-and-building. Send `charge` (the DEPRECATED charge-based proposal) or omit it and name `shiftId` (the proposal from warehouse-planning's published labour plan, ADR 0043). anyOf: - required: [siteCode] - required: [buildingId] properties: siteCode: type: string minLength: 1 description: >- The canonical Site code (the facility-layout Site code, e.g. WH1) the proposal is for. Required unless the deprecated buildingId is sent. example: WH1 buildingId: type: string minLength: 1 deprecated: true description: >- DEPRECATED -- use siteCode. Alias of siteCode with the same value. Required only when siteCode is not sent. example: WH1 shiftId: type: string description: >- OPTIONAL (ADR 0043). The shift whose published labour plan to read. Used only when `charge` is omitted: the proposal is then the heads warehouse-planning published for (siteCode, shiftId, pathId), untrimmed; nothing published is 404 labour-plan-not-found. Ignored when `charge` is sent. example: 2026-11-18-day charge: type: number format: double deprecated: true description: >- DEPRECATED (ADR 0043 decision 3): the volume of work (units) to be covered on this path; a request with it behaves exactly as before. Omit it and name `shiftId` to get the published requirement instead. Omitting both `charge` and `shiftId` (or sending a null charge without a shiftId) is rejected with a 400 missing-charge problem; an explicit 0 is a valid "nothing to do" charge. example: 100 plannedRate: type: number format: double description: >- Planned units-per-head-per-hour throughput rate for this path. OPTIONAL: omit (or send <= 0) to let the proposal fall back to a real measured rate fed back from labor-performance for this path's task type (feature: close-the-loop measured rate, ADR-0012; its mean seconds per task is converted to units per head per hour as 3600 / meanActualSeconds, ADR-0033). A supplied plannedRate always wins outright over any measured rate. example: 30 ProposePathPlanResponse: type: object required: [pathId, proposedHeads, resolvedRate, rateSource] properties: pathId: type: string example: pack proposedHeads: type: integer description: >- Charge-based: ceil(charge / resolvedRate), further trimmed when a high observed idle share exceeds IDLE_SHARE_TRIM_THRESHOLD (see trimReason). From the labour plan (rateSource labour-plan): the published planned_heads, never trimmed. Not committed. example: 4 resolvedRate: type: number format: double description: >- The rate actually used to compute proposedHeads, in units per head per hour -- either the caller-supplied plannedRate, or a measured rate fed back from labor-performance (its mean seconds per task converted to a per-head hourly rate: 3600 / meanActualSeconds). 0 when neither was available (proposedHeads is then also 0). example: 30 rateSource: type: string enum: [caller, measured, labour-plan] description: >- Where resolvedRate came from: "caller" (a supplied plannedRate, or no rate was available at all), "measured" (fed back from labor-performance) or "labour-plan" (ADR 0043: heads and rate as warehouse-planning published them; clients must tolerate unknown values). Lets a human see why proposedHeads came back 0 (no rate from either source) rather than guessing. example: caller trimReason: type: string description: >- Non-empty only when a high observed idle share (idleness-as-staffing-signal) trimmed proposedHeads -- explains the observed share, the threshold, and the before/after head counts, so the trim is auditable. Omitted (or empty) when no trim was applied, including when no idle-share signal is available at all (fail-open). example: >- observed idle share 50.0% for path "pack" exceeds the 30.0% trim threshold; heads trimmed from 10 to 5 PathPlanLineRequest: type: object required: [pathId, plannedHeads, plannedRate, plannedHours, installedStations] properties: pathId: type: string minLength: 1 example: pack plannedHeads: type: integer description: Committed headcount for this path. example: 3 plannedRate: type: number format: double example: 30 plannedHours: type: number format: double description: >- Total committed hours for this path. Must not exceed plannedHeads * the configured max hours per shift. example: 24 installedStations: type: integer description: >- Physical stations installed on this path, supplied by the caller (this context has no dependency on Work Planning, which owns this number). plannedHeads must not exceed this. example: 10 CommitShiftPlanRequest: type: object description: >- The ShiftPlan key is the canonical `siteCode`; `buildingId` is its DEPRECATED alias (same value, same stored column; ADR 0035). Send at least one. Sending both with the same value is fine; both with different values is rejected with 422 conflicting-site-and-building. required: [shiftId, lines] anyOf: - required: [siteCode] - required: [buildingId] properties: siteCode: type: string minLength: 1 description: >- The canonical Site code (the facility-layout Site code, e.g. WH1) the plan is for. Required unless the deprecated buildingId is sent. example: WH1 buildingId: type: string minLength: 1 deprecated: true description: >- DEPRECATED -- use siteCode. Alias of siteCode with the same value. Required only when siteCode is not sent. example: WH1 shiftId: type: string minLength: 1 example: shift-1 lines: type: array minItems: 1 description: >- One or more path plan lines. Must contain at least one line (shift-plan-no-path-plans if empty). items: $ref: "#/components/schemas/PathPlanLineRequest" PathPlanLineResponse: type: object required: [pathId, plannedHeads, plannedRate, plannedHours] properties: pathId: type: string example: pack plannedHeads: type: integer example: 3 plannedRate: type: number format: double example: 30 plannedHours: type: number format: double example: 24 requiredHeads: type: integer minimum: 0 description: >- ADDITIVE (ADR 0043 decision 4). The heads warehouse-planning published for this line's (siteCode, shiftId, pathId) in LabourPlanCommitted, shown next to the committed plannedHeads. Omitted when nothing was published. Never enforced: a line committing fewer heads than required is accepted. example: 4 ShiftPlanResponse: type: object required: [siteCode, buildingId, shiftId, lines] properties: siteCode: type: string description: >- The canonical Site code the plan is keyed by (ADR 0035). The same value as the deprecated buildingId. example: WH1 buildingId: type: string deprecated: true description: >- DEPRECATED -- use siteCode. The legacy name of the plan key, kept with the SAME value as siteCode (same stored column) so existing consumers do not break. Removed only by a later, announced breaking ADR. example: WH1 shiftId: type: string example: shift-1 lines: type: array items: $ref: "#/components/schemas/PathPlanLineResponse" AssignLaborRequest: type: object required: [pathId] properties: pathId: type: string minLength: 1 description: The path to assign the associate to. example: pack AssignmentResponse: type: object required: [associateId, active] properties: associateId: type: string example: assoc-1 activePathId: type: string description: The path of the current active assignment, if any. example: pack active: type: boolean description: Whether the associate currently has an active assignment. example: true StaffingGapPage: type: object required: [items] properties: items: type: array items: $ref: "#/components/schemas/StaffingGapResponse" nextCursor: type: string description: Opaque cursor of the next page; absent on the last page. Paths are ordered by pathId. StaffingGapResponse: type: object required: [pathId, plannedHeads, activeHeads, understaffed] properties: pathId: type: string example: pack plannedHeads: type: integer example: 3 activeHeads: type: integer example: 1 understaffed: type: boolean example: true observedIdleShare: type: number format: double minimum: 0 maximum: 1 description: >- The observed idle share -- a fraction in [0, 1], NOT a 0-100 percentage -- for this path's task type, fed back from labor-performance's idleness signal via LABOR_PERFORMANCE_MODE=kafka-cache. Omitted entirely -- never a fabricated 0 -- when no idle-share signal is available: the mode isn't kafka-cache, or no observation has been recorded yet for this task type. example: 0.42 observedIdlePct: type: number format: double deprecated: true description: >- DEPRECATED -- use observedIdleShare. The original, misleadingly named field: despite the "Pct" suffix it carries the SAME fraction in [0, 1] as observedIdleShare (not a 0-100 percentage), and is kept with its unchanged value so existing consumers do not break. Present exactly when observedIdleShare is. example: 0.42 siteCode: type: string description: >- ADDITIVE (ADR 0034, canonical since ADR 0035). Echoed only when the request was scoped by site (siteCode given): the canonical site the activeHeads were counted at. Omitted when unscoped -- a call that gives only the legacy buildingId is NOT scoped -- i.e. the gap is fleet-wide across every site; consumers must treat absence as "unscoped", never as a particular site. example: WH1 requiredHeads: type: integer minimum: 0 description: >- ADDITIVE (ADR 0043 decision 4). The heads warehouse-planning published for this line's plan key (the plan's site code), shift and path in LabourPlanCommitted, next to the committed plannedHeads. Omitted when nothing was published; understaffed still compares activeHeads with plannedHeads. example: 4