ADR 0008: Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Applies the warehouse REST API guideline (nouns not
verbs, idempotent POST/PATCH, 409 key reuse, Idempotency-Replayed,
keyset paging) to this context. Builds on ADR 0001 (the REST surface and the
deliberate absence of POST /exceptions) and ADR 0007 (the read use cases the
MCP and A2A adapters share with REST).
Context
The 2026-10-30 portfolio assessment found three command-URL styles across
the fleet, two spellings of the replay header, key reuse answered 422 in
most services and unpaginated lists. This context had verb sub-paths
(/triage, /assign, /resolve), a POST /exceptions that answered 405
before the idempotency middleware (so it was the one unkeyed POST), and
two bare-array lists (GET /exceptions, GET /exception-policies). The
guideline is enforced by the Spectral rest-guideline rule
(.spectral/functions/restGuideline.js, rules R1-R8) in the api-lint job.
Decision
Hard cutover, no aliases, no toggles, operationIds unchanged:
- Routes are nouns (R1, R2).
POST /exceptions/{caseId}/triagebecomes/triage-decisions,/assignbecomes/assignments,/resolvebecomes/resolutions. Statuses and bodies do not change.TestRetiredRoutesAreGone(and its Postgres twin) pins the old paths at 404/405. - Every
POSTis idempotent (R3-R6, R8).POST /exceptionsjoins the route-scoped idempotency group: the key is demanded first (400 idempotency-key-required), the permanent405is stored and replayed. The middleware addsIdempotency-Replayed: trueon every replay (and only on a replay), answers409 idempotency-key-reusedwhen the same key arrives with another method, path or body (the key is global, the fingerprint is method + path + SHA-256 of the body), and answers400 idempotency-key-invalidfor a key over 128 characters or not printable ASCII. A4xxis stored, a5xxis rolled back with the unit of work and never stored; concurrent same-key requests are serialised by the key's primary key. ThePUT /exception-policies/{sourceType}stays keyed: each accepted declaration appends a version, so a retry without the key would not be idempotent. - Lists are keyset pages (R7).
GET /exceptions(newest opened first, ordered by(opened_at, case_id)descending) andGET /exception-policies(by source type) answer{items, nextCursor}withlimit(1-500, default 100) andcursor. The cursor is the fleetpagepackage's base64url JSON of the last row's sort key and id (copied unchanged tointernal/adapters/inbound/http/page). Both repositories (Postgres and in-memory) implementListPage; the sharedrepocontractsuite walks the pages with rows sharing anopened_at. Invalidlimitis400 invalid-limit, an undecodable cursor400 invalid-cursor, an undeclared query parameter (after,offset,nextToken, ...)400 unknown-query-parameter. - MCP and A2A keep their tool schemas and complete data. The shared use
cases
ListOpenExceptions.ExecuteandListExceptionPolicies.Executewalk the keyset pages in-process (500 rows per page) and return every row; REST uses theirPagemethods.
Exemptions
None. Both collections are paginated; no operation carries
x-pagination-exempt.
Consumers changed
The exceptions web remote (web/src/api.ts, web/src/types.ts and their
tests) calls the new routes, reads items and follows nextCursor; every
POST already minted a fresh Idempotency-Key per submission. Outside this
repo, e2e-tests (returns_test.go) calls the renamed routes and is updated
in its own PR. No outbound adapter of this service calls a REST list.
Consequences
- Breaking by design: new URLs, a new list envelope, a key now required on
POST /exceptions. It deploys together with the REST cutover set. docs/docs/api-reference/restis regenerated fromapis/openapi.yaml.
Update 2026-11-20 (ADR 0015): the "a 4xx is stored" sentence above is
superseded by the fleet replay-class rule — a refusal is stored only when
its problem type is FINAL (or OUTCOME; none exists here). case-not-found
and concurrent-modification are RETRYABLE and release the key. The
Decision text above stands as the record of 2026-11-01.