ADR 0012: Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Amends ADR 0006 (the REST adapter) and assumptions A31 and A40 of ADR 0002.
Context
The warehouse fleet adopted one REST API guideline (nouns not verbs, every
POST/PATCH idempotent, one answer for key reuse, one replay header, keyset
pagination with one envelope). It is a hard cutover with no aliases, no dual
routes and no toggles, deployed together with the other services of the
cutover set. This service already kept Idempotency-Replayed and wrapped every
state-changing route; what remained was the :verb routes, the 422 for key
reuse, the per-route key scope, the unpaginated lists and the list envelopes.
Decision
-
Routes (R1, R2). The four custom-method routes become transition resources;
operationIds are unchanged, so the MCP tools and A2A skills do not move. Status codes and bodies are unchanged.Was Is POST /nodes/{nodeId}:activatePOST /nodes/{nodeId}/activationsPOST /nodes/{nodeId}:suspendPOST /nodes/{nodeId}/suspensionsPOST /nodes/{nodeId}:retirePOST /nodes/{nodeId}/retirementsPOST /lanes/{laneId}:closePOST /lanes/{laneId}/closuresTestRetiredRoutesAreGonepins that each old route answers 404 or 405. -
Idempotency (R3-R6, R8). The key is GLOBAL:
idempotency_keysis keyed bykeyalone (migration 0004 drops the rows of the old(route, key)design and re-keys the table; theroutecolumn stays for diagnosis). The request fingerprint issha256(method, path, body). Same key and fingerprint replays the first status and body withIdempotency-Replayed: true; the same key with another method, path or body is 409idempotency-key-reused(was 422). A key must be 1 to 128 printable ASCII characters (idempotency-key-invalidotherwise; it was 200 characters with any non-control character), missing is 400idempotency-key-required. The key row, the aggregate rows and the outbox rows still commit in ONE Postgres transaction (the handler runs in a savepoint of the middleware's transaction), a 4xx is stored, a 5xx or a panic is not. Every POST was already behind the middleware; no route was unkeyed. Pointer 2026-11-19: "a 4xx is stored" is superseded in part by ADR 0020: a RETRYABLE refusal is not stored and releases the key. -
PUT routes keep the middleware (guideline 2.1 exception).
PUT /nodes/{nodeId}/operational-profileAPPENDS a profile revision (revisions are append-only rows) andPUT /service-areas/{postalPrefix}bumps the assignment version and publishesServiceAreaAssigned; a keyless retry of either would append or publish twice, so a key is required on them. -
Pagination (R7).
GET /nodes,GET /lanesandGET /regionstakelimit(1-500, default 100) andcursorand answer{items, nextCursor}(nextCursorabsent on the last page). Keyset by the unique id ascending, byte-wise (COLLATE "C"), in the Postgres repositories and the in-memory doubles; the cursor is the fleetpagehelper copied intointernal/adapters/inbound/http/page(base64url JSON of sort key and id; the id is its own sort key, so the cursor carries it twice). 400invalid-limit, 400invalid-cursor, and 400unknown-query-parameterfor any parameter the collection does not declare (so a client still sendingafter,offset,fromornextTokenfails loudly). The repositories take aWindow{AfterID, Limit};Limit0 means every row, which is what the MCP tools and A2A skills pass, so they keep returning complete data with their own schemas. -
Exemptions. None.
GET /regionsis no longer a bare array. -
Consumers in this repo. The console remote
web/src/api.tsfollowsnextCursor(limit 500, bounded at 100 pages) and readsitems; it sends no POST/PATCH. There is no outbound HTTP adapter and no seed script. -
Enforcement.
.spectral.yaml+.spectral/functions/restGuideline.js(rules R1-R8) run in the existingapi-lintjob with--fail-severity=warn.
Consequences
- Breaking: new URLs, the list envelope, 409 for key reuse, a 128-character key limit. It deploys together with the REST cutover set.
idempotency_keysrows of the previous design are discarded at migration (they live 24 hours); a client retrying across the deploy gets a fresh execution of a request whose first answer was lost.- The replay lookup is by key alone, so one key cannot be reused across two routes any more.