37. Adopt the fleet REST API guideline
Status
Accepted (2026-11-01). Amends ADR 0016
(the idempotency middleware: reuse is now 409, not 422) and follows
ADR 0025 (RFC 9457 problems) and
ADR 0034 (Postgres is the
only runtime, so the middleware is always on). Part of the fleet-wide REST
cutover: it ships and is deployed together with the other services' cutover
PRs, because the key header contract and the list envelope are breaking for
every client.
Amended by ADR 0039 (2026-11-20). The sentence below that says
2xxand4xxanswers are stored and replayed, and that the loser of a race replays the winner's answer, no longer holds for every4xx: a refusal is stored only when its problem type isFINALorOUTCOME;concurrent-modificationandstandard-conflictareRETRYABLE, not stored, and their key is released.
Context
The 2026-10-30 portfolio assessment measured two spellings of the replay
header, key reuse answered 422 in most services and 409 in one, three
command-URL styles and unpaginated lists. The fleet standard (the "REST API
guideline") removes each divergence and is enforced by a Spectral ruleset
(.spectral.yaml + .spectral/functions/restGuideline.js, rules R1-R8) wired
into the api-lint job with --fail-severity=warn.
This service has a very small write surface: POST /standards
(DefineStandard) is its only write over REST (everything else is a read, and
TaskPerformance rows come from the Kafka consumer). Its routes were already
nouns, it was already keyed, and it has no collection GET.
Decision
Adopt the guideline as written. What it means for labor-performance:
- Routes (R1, R2). URLs name things: a
:custom-methodsuffix and a verb path segment are forbidden. No route of this service had to be renamed (/standards,/standards/{taskType},/associates/{associateId}/scorecard,/task-types/{taskType}/performance,/task-types/{taskType}/utilization,/associates/{associateId}/utilization,/reports/performance,/reports/performance/freshness).TestRoutesAreNounsNotVerbswalks the real router and fails on a:suffix or a verb segment, so a future route cannot slip in. - Idempotency (R3-R6, R8). Every
POSTandPATCHsits behind the route-scopedRequireIdempotencyKeymiddleware (today onlyPOST /standards);TestEveryPostAndPatchRouteRequiresAnIdempotencyKeywalks the router and fails if a newPOST/PATCHroute answers anything but400 idempotency-key-requiredwithout a key.PUTandDELETEtake no middleware. The contract is:Idempotency-Key: 1-128 printable ASCII characters, a client-generated UUID per logical submit. Missing is400 idempotency-key-required; malformed (over 128 characters, a control character, non-ASCII) is400 idempotency-key-invalid.- The key is global: the stored record is found by the key alone
(
idempotency_keys.keyis the primary key) and compared by the request fingerprint, method + path + SHA-256(body). - Same key, same fingerprint: the stored answer (status, body, headers) is
replayed byte for byte with
Idempotency-Replayed: true; the handler does not run again. The first execution never carries the header. The retired past-tense spelling of the header is gone from code, spec, tests and docs. - Same key, different method, path or body:
409 Conflict, problemidempotency-key-reused(was422). It never executes anything and never carriesIdempotency-Replayed. A business409(concurrent-modification,standard-conflict) is told apart from it by the problem type. - Persistence (unchanged from ADR 0016): the key row, the aggregate change
and the outbox rows commit in one transaction.
2xxand4xxanswers are stored and replayed; a5xxor a panic rolls the whole transaction back, key row included, and is never stored, so the retry executes again (new in this ADR). Concurrent requests with one key are serialized by the unique index; the loser replays the winner's answer. - OpenAPI (STANDARD 2.7): the
IdempotencyKeyparameter (required: true, the middleware is on in every runtime mode, ADR 0034),400and409on the operation, and theIdempotency-Replayedheader on the201. The422ofPOST /standardsnow describes only business validation.
- Pagination (R7). There is no collection
GET: every read addresses one thing (a standard, a scorecard, a task type's performance or utilization) or is a time-windowed report whoserowsandbyTaskTypearrays are members of one report object (/reports/performance, bounded by the mandatoryfrom/towindow). The ruleset flags nothing, so nox-pagination-exemptis declared andpage/cursorare not introduced. If a collectionGETis ever added it must paginate (limit+cursor, keyset,{items,nextCursor}). - Contract job.
scripts/contract-test.shis unchanged in shape: with no paged operation noschemathesis.tomlis needed.scripts/contract_hooks.pykeeps minting a fresh UUID per request, and its comment now names409.
Exemptions
None. No x-pagination-exempt, and no PUT with a keyed exception (this
service has no PUT).
Consumers
web/src/api.ts(thelabor_mferemote) already sends a freshcrypto.randomUUID()Idempotency-Keyon its only write (POST /standards) and reads no list; it needs no change.- No other service calls this service's REST API (none was found in the fleet sweep); the MCP and A2A adapters call use cases, not HTTP routes.
- Wire contract for any external client: send
Idempotency-KeyonPOST /standards, treat409 idempotency-key-reusedas a client bug (do not retry blindly), and readIdempotency-Replayed: trueas "this is the stored answer".
Consequences
- A client that relied on
422 idempotency-key-reusedmust now handle409; a client that read the old past-tense replay header (none in the fleet) must readIdempotency-Replayed. - A key longer than 128 characters, or with a non-printable or non-ASCII
character, is
400 idempotency-key-invalidinstead of being stored. - A transient
5xxno longer poisons a key: the retry with the same key re-executes. - The breaking change merges and deploys with the rest of the REST cutover
set;
developis half-migrated until the last PR of the set lands.