API overview
:::info Implemented by cmd/api
cmd/api serves every route below (internal/adapters/inbound/http), on
HTTP_ADDR (default :8080). The contracts are apis/openapi.yaml and
apis/asyncapi.yaml, pinned by
ADR 0001 and
ADR 0002. There is no route in
the code that the spec does not list: the router registers exactly the six API
routes plus /healthz and /readyz. See the Quickstart
for real responses.
:::
| Interface | Source of truth | Notes |
|---|---|---|
| REST | apis/openapi.yaml (OpenAPI 3.0.3, version 1.0.0) | The pages under REST are generated from the spec with npm run gen-api-docs; do not edit them by hand. Servers named in the spec: http://localhost:8080 (local) and http://localhost:8000/api/task-interleaving (kind cluster through Kong). |
| Events | apis/asyncapi.yaml (AsyncAPI 2.6.0, version 1.0.0) | Summarised on the event catalogue; every field on Domain events. |
| MCP | ADR 0007, internal/adapters/inbound/mcp | cmd/mcp serves Streamable HTTP on /mcp (port 8090; through Kong /api/mcp/task-interleaving). Four read-only tools, no write tool: get_site_policy, list_hints (stationId, state, siteId), get_hint, get_station (position and active hint). No auth, by fleet decision. |
| A2A | ADR 0009, internal/adapters/inbound/a2a | cmd/a2a serves JSON-RPC 2.0 on / and /a2a (port 8093; through Kong /api/a2a/task-interleaving), the Agent Card at /.well-known/agent-card.json. Two read-only skills, no write skill: station_hint_status (stationId) and site_interleaving_overview (siteId, limit 1..20). Domain rejections are answered in the message envelope as RFC 7807 problems with the REST slugs, never as JSON-RPC errors. No auth, by fleet decision. |
Endpoints
| Tag | Endpoint | Operation id | Success |
|---|---|---|---|
| Policy | PUT /sites/{siteId}/policy | declareInterleavingPolicy | 200, the policy at its new version, ETag: "<version>" |
| Policy | GET /sites/{siteId}/policy | getInterleavingPolicy | 200, the policy; 404 policy-not-found for an inert site |
| Hints | GET /hints | listHints | 200 {items, nextCursor?}, newest first, filters stationId, siteId, state |
| Hints | GET /hints/{hintId} | getHint | 200, the hint with its candidates and outcome |
| Stations | GET /stations/{stationId} | getStation | 200, position, last completed task, Active hint; 404 station-not-found |
| Recommendations | POST /recommendations | recommendTasks | 200, ranked candidates, possibly empty; read-only simulation |
| Reports | GET /reports/hint-adoption, GET /reports/freshness | getHintAdoption, getReportsFreshness | 200, served by cmd/ti-reports (port 8092; through Kong /api/task-interleaving/reports, prefix rewritten to /reports, konghq.com/regex-priority: "10" so it outranks the /api/task-interleaving api route — in the chart since this PR; live on k3s after the next release, chart pin and apply, see Integration) from the analytical database; see ADR 0008 |
| Health | GET /healthz, GET /readyz | healthz, readyz | 200 / 200, or 503 once shutdown has started (the spec also says "while starting"; the listener only opens after boot, see Runbook) |
Conventions in the contract
- Policy versioning. A policy carries
version(1 at declaration, +1 per accepted change) and a strongETagequal to the quoted version. The first declaration sends noIf-Match; a replacement must send the current one, and a stale or missing value is412 version-mismatch. A write that loses a race at the database is409 concurrent-modification. Declaring identical values again still advances the version. - Paging.
GET /hintstakeslimit(1 to 500, default 100) and the opaquecursor(the previous page'snextCursor). NonextCursormarks the last page. Each may be sent once: an empty or repeatedlimitis400 invalid-limit, a repeatedcursoris400 invalid-cursor, and a query parameter the operation does not declare is400 unknown-query-parameter. Idempotency-Key. Documented onPOST /recommendationsand implemented byinternal/adapters/inbound/http/idempotency.go. It is required on every deployment, since Postgres is the only runtime (400 idempotency-key-requiredwhen absent,400 idempotency-key-invalidwhen it is not 1 to 128 printable ASCII characters); the same key with a different method, path or body is409 idempotency-key-reused; an equal request replays the stored answer with the response headerIdempotency-Replayed: true(a first execution never carries it) when that answer was a success or a refusal that is final for the request (the400s), for 24 hours after it was stored (an older answer is not replayed: the key is a new request again). A refusal that depends on state that can change (422 policy-not-declared,origin-unknown,station-position-unknown) and every 5xx are not stored: the key is released and the same request under the same key executes again. A copy sent while the first request is still in flight replays the first request's stored answer instead of answering a refusal of its own (ADR 0013).- Errors are RFC 7807
application/problem+jsonwithtype = https://errors.task-interleaving.warehouse-systems.dev/<slug>. The slugs in the spec:malformed-request,invalid-site-id,invalid-station-id,invalid-hint-id,invalid-policy,invalid-task-type,invalid-cursor,invalid-limit,unknown-query-parameter,invalid-state,idempotency-key-required,idempotency-key-invalid,idempotency-key-reused,policy-not-declared,origin-unknown,station-position-unknown,policy-not-found,hint-not-found,station-not-found,version-mismatch,concurrent-modificationandinternal-error. The errors that map to these slugs are listed on Use cases and, with remedies, on Troubleshooting. - Auth: none. The fleet reverted REST and MCP auth on 2026-09-11, and
TestNoAuthMiddlewareReintroducedfails CI if auth middleware returns underinternal/adapters/inbound. - Advisory by contract. Nothing in this API assigns work to a worker;
fulfillment-executionkeepsclaimNextas its only claim path (ADR 0001).