0049. Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Amends ADR 0018
(the middleware now guards every POST, answers key reuse with 409, and
sets Idempotency-Replayed). Part of the fleet-wide REST cutover: the
guideline is the Warehouse REST API Guideline, kept in warehouse-docs; this
ADR records how this service applies it.
Update 2026-11-19 (ADR 0053). "Deterministic answers (2xx and 4xx) are stored and replayed" is narrowed: a 2xx, a FINAL refusal and an OUTCOME refusal are stored; a RETRYABLE refusal (concurrent-modification, a referenced fact not known yet, a state not reached yet, a dependency not ready) is not, and its key is released. A concurrent duplicate of a request that ends RETRYABLE executes the command itself.
Context
The 2026-10-30 application portfolio assessment measured, across the fleet, two
spellings of the replay header, key reuse answered 422 in most services and
409 in one, three command-URL styles (:verb, verb sub-paths, sub-resources),
unpaginated lists and writes that were not retry-safe. This service had all of
them: POST /stock/receive, POST /stock/stow, POST /reservations/{id}/confirm-pick,
POST /bins/{binId}/cycle-count and POST /transfers/{transferLineId}/stow
were verbs, POST /containers/{lpn}:stow and :break were custom methods,
three POSTs (stow, confirm-pick, cycle-count) were not behind the idempotency
middleware at all, key reuse was 422, and GET /reservations and
GET /bins/{binId}/containers answered a bare array and a containers object.
Decision
A hard cutover: no aliases, no dual routes, no toggles. The old routes are
gone and answer 404/405 (TestRetiredRoutesAreGone).
1. Noun routes (guideline sections 1.1-1.5)
URLs name things; a command is a noun sub-resource. Status codes and bodies of
an operation do not change with its rename, and every operationId is
unchanged, so the MCP and A2A mappings do not move.
| Was | Now | operationId |
|---|---|---|
POST /stock/receive | POST /stock-receipts | receiveStock |
POST /stock/stow | POST /stowages | stowStock |
POST /reservations/{id}/confirm-pick | POST /reservations/{id}/pick-confirmations | confirmPick |
POST /bins/{binId}/cycle-count | POST /bins/{binId}/cycle-counts | runCycleCount |
POST /transfers/{transferLineId}/stow | POST /transfers/{transferLineId}/stowages | stowTransferStock |
POST /containers/{lpn}:stow | POST /containers/{lpn}/stowages | stowContainer |
POST /containers/{lpn}:break | POST /containers/{lpn}/case-breaks | breakCase |
2. Every POST is idempotent (sections 2.1-2.7)
Idempotency-Key(1-128 printable ASCII characters, a fresh UUID per logical submit) is required on everyPOST. A missing key is400 idempotency-key-required, a malformed one400 idempotency-key-invalid.- The fingerprint is method + path + SHA-256(body). The same key with the
same fingerprint replays the stored answer (status, body,
Content-Type,Location) and addsIdempotency-Replayed: true; the first execution never carries it. The retired spellingIdempotent-Replayedappears nowhere. - The same key with a different fingerprint is
409idempotency-key-reused(it was422), told apart from a business409by its problem type. - Deterministic answers (2xx and 4xx) are stored and replayed; a 5xx or a panic rolls back and is never stored, so the retry re-executes. Concurrent requests with one key are serialised by the unique index and the loser replays the winner.
- The middleware is route-scoped on every
POSTroute, and the key row is written in the same Postgres transaction as the aggregate change and its outbox rows. Newly keyed:POST /stowages,POST /reservations/{id}/pick-confirmationsandPOST /bins/{binId}/cycle-counts. Their use cases (StowStock,ConfirmPick,RunCycleCount) already ran inside theUnitOfWork; under the middleware that unit of work joins the request transaction, so key row, stock/reservation change, bin-level facts and outbox rows still commit or roll back together. apis/openapi.yaml: everyPOSTreferencescomponents/parameters/IdempotencyKey, declares400and409, and documents theIdempotency-Replayedheader on every 2xx; no422is described as the reuse answer.
3. Collections are keyset-paginated (section 3)
GET /reservations?demandRef= and GET /bins/{binId}/containers take limit
(1-500, default 100) and an opaque cursor, and answer
{"items": [...], "nextCursor": "..."} (nextCursor absent on the last page).
The cursor is the fleet's page package (base64url JSON of the last row's sort
key and id), copied into internal/adapters/inbound/http/page:
| List | Order (sort key, id) | Filter repeated on every page |
|---|---|---|
GET /reservations | (created_at, id) | demandRef |
GET /bins/{binId}/containers | (lpn, lpn) (the LPN is unique) | binId (path) |
Both the Postgres and the in-memory repositories order by that key (never
OFFSET); a bad limit is 400 invalid-limit, a cursor that does not decode
400 invalid-cursor. The bin-containers body no longer repeats binId.
Exemptions: none. Neither list is a composite view or a bounded report.
4. Enforcement
.spectral.yamland.spectral/functions/restGuideline.js(rules R1-R8) run in theapi-lintCI job with--fail-severity=warn;apis/openapi.yamlpasses.- Tests with a real router and real Postgres (testcontainers): fresh key,
byte-identical replay with
Idempotency-Replayed: true, same key with another body or path409, missing key400, N concurrent same-key requests creating one row, a 4xx cached and replayed, a 5xx not stored, and for each list a page walk over more rows thanlimit(rows sharing a sort key included) with no duplicate and no skipped row.
Consumers
Changed in this repository: the inventory micro-frontend
(web/src/api.ts, web/src/useReservations.ts, InventoryScreen) reads
items and follows nextCursor for the demandRef lookup (it makes no
POST/PATCH, so it sends no key); apis/asyncapi.yaml, scripts/contract_hooks.py
(Schemathesis now expects 409 for a reused key), the executive page, the
README and the docs. The MCP tools and A2A skills call the use cases directly,
not HTTP, and are unchanged.
Outside this repository, each in its own PR of the cutover set: order-management
(POST /reservations, DELETE), warehouse-ops-agent (lists reservations and must
read items), e2e-tests (seeds with POST /stowages, /stock-receipts),
network-fulfillment (reads GET /inventory/{sku}/usable, whose path is
unchanged), fulfillment-execution (/containers/{lpn}/case-breaks,
/stowages) and warehouse-infra helm values.
Consequences
- Breaking by design: new URLs, a new list envelope, and the key is now
required on three more routes. All PRs of the REST cutover merge as one set and
are deployed together;
developis half-migrated until the last one lands. - A client that reads only the first page of a list silently truncates data once
the collection outgrows
limit; every consumer must loop onnextCursor. 409now has two meanings on aPOST; clients distinguish them by the problemtype(idempotency-key-reusedis a client bug, never retried blindly).- The deprecated
POST /stock-receiptsandPOST /reservations/{id}/pick-confirmationskeep their deprecation status; renaming them is not a reprieve.