ADR 0010: Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Supersedes the REST details of
ADR 0005 that it names below
(per-route key, 422 on reuse, Idempotent-Replayed, bare {items} lists).
Context
The fleet REST API guideline (warehouse-docs, rules R1 to R8, enforced by the
rest-guideline Spectral rule in .spectral.yaml) removes three divergences
between the services: command URLs written as :verb suffixes, an idempotency
contract that differed per service (the key scoped to a route, reuse answered
422, two spellings of the replay header) and unpaged lists. The cutover is
breaking by design and ships as one set across the fleet.
Decision
-
Nouns, not verbs. A lifecycle transition is a
POSTto a plural transition noun under the aggregate:Old New POST /waves/{waveId}:close-inductionPOST /waves/{waveId}/induction-closuresPOST /waves/{waveId}:dispatchPOST /waves/{waveId}/dispatchesPOST /waves/{waveId}:cancelPOST /waves/{waveId}/cancellationsPOST /routes/{routeId}:startPOST /routes/{routeId}/startsPOST /partners/{dspId}:deactivatePOST /partners/{dspId}/deactivationsoperationIds, status codes and bodies do not change; the old routes are gone (TestRetiredRoutesAreGone), with no alias. -
Every POST is idempotent. All nine POST routes sit behind
RequireIdempotencyKey. The key is 1 to 128 printable ASCII characters: missing is 400idempotency-key-required, malformed 400idempotency-key-invalid. The key is global (looked up by key alone); the fingerprint is method + path + SHA-256 of the body. Same key and fingerprint replays the stored answer withIdempotency-Replayed: true(Idempotent-Replayedis retired); same key and another fingerprint is 409idempotency-key-reused(was 422). -
One transaction.
postgres.IdempotencyStore.Dotakes an advisory lock on the key, begins the transaction and hands it to the handler through the context, so each use case'sUnitOfWork.Dojoins it: the key row, the aggregate change and the outbox rows commit together. A 2xx and a 4xx answer are stored (24 h); a 5xx, an error or a panic rolls everything back and is never stored, so the retry re-executes. Migration0002drops theroutecolumn fromidempotency_keys(primary key is the key alone) and addscontent_type, so a replay keeps theContent-Type. Consequence: a handler that returned a 4xx after writing something would keep that write; the use cases here validate before they save, so none does. -
Keyset paging.
GET /wavesandGET /waves/{waveId}/stopstakelimit(1 to 500, default 100) andcursorand answer{items, nextCursor}. The cursor is the base64url JSON of the last row's sort key and id (packageinternal/adapters/inbound/http/page): waves order by(inductCutoffAt, waveId)in both the Postgres and the memory repository; stops by(first induction time, stopKey)(ties on the induction time now break by stopKey). Badlimitis 400invalid-limit, an undecodable cursor 400invalid-cursor, any undeclared query parameter 400unknown-query-parameter. -
Exemptions. None: no operation is marked
x-pagination-exempt. -
MCP and A2A keep their tool schemas and still return complete lists: the
ExecuteofListWavesandGetWaveStopswalks the pages (500 rows each, at most 20 pages). -
Consumers in this repo. The web remote (
web/src/api.ts) is read-only, sends no key, and followsnextCursorfor both lists. No outbound HTTP client exists (this context calls no sibling).
Consequences
- Clients must send an
Idempotency-Keyon every POST, read lists fromitemsand loop onnextCursor, and treat 409idempotency-key-reusedas a bug. - Deploy together with the rest of the REST cutover set.
Update 2026-11-20
ADR 0019
supersedes the sentence "A 2xx and a 4xx answer are stored (24 h)" of the "One
transaction" decision: a refusal is stored only when its problem type is FINAL
or OUTCOME; a RETRYABLE refusal (for example concurrent-update,
unknown-station, not-found) is not stored and its key is released. The text
above is left as decided.