ADR 0016: REST error mapping, GET-only CORS, and strict path-target config
Status
Accepted. Does not supersede any earlier record; it refines behaviour that ADR 0009, ADR 0002 and ADR 0015 left implicit.
Context
The 2026-10-05 documentation refresh compared the code against its docs and found three places where behaviour was wrong or surprising, and a fourth where the code and an accepted ADR disagreed in the opposite direction.
GET /explain-travel-factorreturned HTTP 400 for every error fromusecases.ExplainTravelFactor.Execute. That includes facility-layout being unreachable or failing, which is an upstream degradation, not a mistake by the caller.- The CORS middleware allowed
POST,PUTandDELETE, although every route of this agent is a read-onlyGET(ADR 0006, governance note). config.loadPathTargetssilently fell back to the built-in default target whenDAILY_BRIEF_PATH_TARGETSwas set but not valid JSON. An operator typo therefore produced a healthy-looking brief about the wrong path.getOrderLifecyclecarried a502 Bad Gatewaybranch that could never run:OrderLifecycle.Executereturns onlyports.ErrNotFound, and every other order-management error degrades that stage tonull, as ADR 0002 specifies ("one context being unreachable degrades that one stage to absent, never a … failure for the whole response").
Decision
- Classify
ExplainTravelFactorerrors. The use case wraps the missing-location-code rejection in a new sentinel,usecases.ErrInvalidInput. The HTTP adapter maps an error that wrapsErrInvalidInputto 400 and every other error to 502. The MCP tool is unchanged (it returns the error as a tool error either way). - CORS allows
GETandOPTIONSonly.CORS_ALLOWED_ORIGINSand the allowed headers are unchanged. - A set-but-malformed
DAILY_BRIEF_PATH_TARGETSis a config error.config.Loadnow returns(Config, error);cmd/agentreturns the error and the process exits non-zero before serving. An unset variable (and an explicitly empty array) still selects the built-in default target, and the Helm chart's empty default is unaffected. - Keep ADR 0002's degradation for the order lifecycle and remove the
unreachable 502 branch rather than "surfacing" order-management failures
as 502. The handler keeps a defensive 500 for any future widening of
Execute's error contract. A test pins that an unreachable order-management still yields a 200 withorderManagement: nulland the other stages intact.
Consequences
Positive — clients and dashboards can tell "you sent a bad request" (400) from "facility-layout is down" (502) and alert on the latter. The CORS surface matches the read-only posture. A bad path-target override is caught at deploy time, in the rollout, instead of in a wrong brief.
Negative / contract notes — this is a REST contract change on an error
path only: a caller that treated any 4xx from /explain-travel-factor as
"my input is wrong" will now see a 5xx for upstream failures, which is the
point; success responses and all other routes are unchanged. Browsers can no
longer make cross-origin non-GET requests to this agent; none exist.
Deployments that carry a malformed DAILY_BRIEF_PATH_TARGETS will now crash
on start until it is fixed — intended, but visible in a rollout.
Open product question (not decided here) — whether an unreachable order-management should instead fail the whole order-lifecycle response (502) when it is the only stage that would otherwise be empty. ADR 0002 says no; this ADR leaves that rule unchanged.