ADR 0012: Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Amends ADR 0006 (routes, Idempotency-Key scope and reuse status) and the list answer of ADR 0002 A24.
Context
The fleet standardised its REST contracts (warehouse REST API guideline, enforced by the rest-guideline Spectral rule in the api-lint
job): URLs name things, every POST and PATCH is idempotent with one global Idempotency-Key, key reuse is 409, and every collection is
keyset-paged as {items,nextCursor}. This service had :verb custom-method routes, an Idempotency-Key scoped by (route, key) whose
reuse was 422, a key limit of 200 characters and an unpaged {departures} list capped by limit.
Decision
-
Noun routes (R1, R2). Hard cutover, no alias:
Old New POST /lane-schedules/{laneId}:retirePOST /lane-schedules/{laneId}/retirementsPOST /departures/{departureId}:cancelPOST /departures/{departureId}/cancellationsPOST /departures/{departureId}:change-capacityPUT /departures/{departureId}/capacityPOST /loads/{loadId}:closePOST /loads/{loadId}/closuresPOST /loads/{loadId}:dispatchPOST /loads/{loadId}/dispatchesPOST /loads/{loadId}:receivePOST /loads/{loadId}/receiptsCapacity is an attribute replace, so it is a
PUT(idempotent by method, no middleware; a key sent to it is accepted and ignored). Status codes, bodies andoperationIds do not change. A test (TestRetiredRoutesAreGone) asserts each old route answers 404 or 405. -
Idempotency (R3-R6, R8). All eight POST routes stay behind the middleware (none was unkeyed). The key is global: migration
0002_idempotency_global_keymakeskeythe primary key ofidempotency_keys(older duplicates across routes are dropped,routeis kept for diagnostics). The fingerprint stayssha256(method, path, body), so the same key on another route or body is 409idempotency-key-reused(was 422). A key must be 1 to 128 printable ASCII characters (idempotency-key-invalidotherwise, was 200 characters of anything printable); a missing key is 400idempotency-key-required. The replay header isIdempotency-Replayed: true(only on a replay). The key row, the aggregate and the outbox rows still commit in ONE Postgres transaction (SAVEPOINT design of ADR 0006): this store already met the requirement, nothing else changed in it. Pointer 2026-11-20: the replay of every refusal that ADR 0006 describes is superseded in part by ADR 0015: a RETRYABLE refusal is not stored and releases the key. -
Pagination (R7).
GET /departurestakeslimit(1-500, default 100) and the opaquecursor, orders by(cutoffAt, departureId)with a keyset predicate(cutoff_at, id) > ($1, $2)in both the Postgres and the in-memory repository, and answers{items,nextCursor}(nextCursorabsent on the last page). The cursor is the fleetpagepackage format (internal/adapters/inbound/http/page, base64url JSON of the last sort key and id).invalid-limit,invalid-cursorandunknown-query-parameter(page.Unknown:after,offset,nextTokenand any undeclared name) are 400. The use caseListDeparturesPageserves REST;ListDepartures(limit 1..1000, default 500, one complete bounded read) keeps serving the MCP tool and the A2A skill, whose own schemas are unchanged. -
Exemptions. None: the only collection GET is paginated.
-
Consumers in this repo. The console remote (
web/src/api.ts) readsitemsand followsnextCursoruntil it is absent or the caller'slimitis reached. The e2e helper (cmd/api/e2e_integration_test.go) does the same. No outbound HTTP adapter exists.
Consequences
Breaking by design (new URLs, new list envelope, global key, 409): this PR merges and deploys with the rest of the REST cutover set. A
consumer still sending after, offset or nextToken fails loudly with 400. No Schemathesis contract job exists in this repo, so no
schemathesis.toml is needed.