0047. Adopt the fleet REST API guideline
Status
Accepted (supersedes the key-reuse status and the scope paragraph of ADR-0022).
Context
The fleet standardised its REST surface (see the warehouse-docs REST guideline):
URLs name things, every POST/PATCH is idempotent, key reuse is 409, every
collection is keyset-paged. This service had two verb routes, four POSTs outside
the idempotency middleware, key reuse answered 422, and one unpaged collection.
Decision
- Noun routes.
POST /paths/{pathId}/releasebecomesPOST /paths/{pathId}/work-releases;POST /work-units/{id}/completebecomesPOST /work-units/{id}/completions. Status codes and bodies are unchanged;operationIds (releaseNextWork,recordCompletion) are unchanged so MCP/A2A mappings do not move. Hard cutover, no aliases (TestRetiredRoutesAreGone). - Idempotency on every POST.
charge,plan,work-units,work-releasesandcompletionsall sit behindRequireIdempotencyKey(route-scoped). The key is global (looked up by key alone); the fingerprint is method + path + body hash. Same key + different fingerprint is409 idempotency-key-reused(was 422). A key that is not 1-128 printable ASCII is400 idempotency-key-invalid. A replay carriesIdempotency-Replayed: true. The key row still commits in the same transaction as the aggregate change and the outbox rows (ADR-0014/0022). 2xx and 4xx answers are stored; a 5xx or a panic rolls everything back and is never stored. The only PUT (/paths/{pathId}/pool) is a snapshot replace, idempotent by method, and takes no key. - Keyset paging.
GET /work-units?reference=answers{items,nextCursor}, withlimit(1-500, default 100) and an opaquecursor, ordered by(cpt, id); theinternal/adapters/inbound/http/pagehelper is the fleet reference. Badlimitis400 invalid-limit, a bad cursor400 invalid-cursor, any undeclared query parameter400 unknown-query-parameter. - Enforcement.
.spectral.yaml+.spectral/functions/restGuideline.js(spectral lint ... --fail-severity=warn, CI jobapi-lint).
Exemptions
None. (GET /paths/{pathId}/telemetry|labor-plan-view are single-path
views addressed by id and are not collections; the Spectral rule does not flag them.)
Consumers changed
This repo's web/ remote (fetchWorkUnitsByReference follows nextCursor).
Outside this repo: e2e-tests (warehouse-day floor client), warehouse-ops-agent
(GET /work-units?reference=), and any caller of the two renamed routes.
Amendment: GET /paths/{pathId}/rebalance becomes a keyed POST
The rebalance route carried a verb in its path and published PathThrottled /
LaborReassignmentFlagged as a side effect of a GET (unsafe for caches,
prefetchers and polling). It is replaced, with no alias, by
POST /paths/{pathId}/rebalance-decisions (guideline 1.3 e, a decision noun;
operationId rebalanceDecision unchanged):
Idempotency-Keyrequired (400idempotency-key-required/-invalid), no request body, 409idempotency-key-reusedon a different request.- Answers
201with the same decision JSON, noLocation(the decision is computed, not stored), as pricing'sPOST /price-quotesanswers a computed result with201. - The first execution runs
RebalanceDecisionand publishes the events. A replay of the same key returns the stored decision withIdempotency-Replayed: trueand publishes nothing. Callers (including pollers) must mint a new key per decision: reusing one freezes the decision and silences the events. GET /paths/{pathId}/telemetrystill publishes events from a GET; it is a noun route and out of scope here, recorded as a known concern.
Consequences
Breaking by design; deploys together with the rest of the fleet's REST cutover set.
Update (2026-11-20): which refusals are replayed
The sentence "2xx and 4xx answers are stored" in the Decision above is refined
by ADR 0050: a refusal is
stored and replayed only when its problem type declares FINAL (or OUTCOME,
which this service has none of today). A RETRYABLE refusal —
concurrent-modification, wip-limit-reached, work-pool-empty, the
not-founds of caller- or event-supplied ids, a not-yet-known CASE pack level,
any 5xx — releases the key: nothing is stored and the same key may be retried
(it executes again; a different body under it afterwards is a new request).
The wire contract — slugs, titles, statuses — is unchanged.