cloudaxe-opencode/packages/opencode/src/server/routes/instance/httpapi
Kit Langton 98fef45553 fix(httpapi): 404 status + body shape for missing-session errors
Two related divergences from Hono are fixed in one move:

1. Status: many session handlers (todo, diff, summarize, fork, abort,
   init, deleteMessage, command, shell, revert, unrevert) didn't wrap
   with mapNotFound, so a thrown NotFoundError surfaced as a 500 defect
   instead of a 404. The fork/diff endpoints also lacked OpencodeNotFound
   in their declared error union, so handlers couldn't surface 404 even
   if they wanted to.

2. Body shape: the existing mapNotFound rebrand to HttpApiError.NotFound
   produced an empty 404 response. Hono returns the NamedError envelope
   `{ name: "NotFoundError", data: { message } }`. SDK consumers reading
   `error.data.message` got undefined.

The fix introduces OpencodeNotFound — a Schema.ErrorClass annotated with
`httpApiStatus: 404` and a body schema matching the legacy NamedError
shape. mapNotFound now rebrands NotFoundError to OpencodeNotFound,
preserving the underlying error message. All session endpoints that take
a sessionID now wrap their service calls with mapNotFound.

A TODO in the handler notes the long-term direction: services should
fail with typed errors directly (Effect<T, SessionNotFound>) and let
HttpApi auto-route status + body via schema annotations, eliminating
mapNotFound entirely. This PR is the pragmatic middle: small surface,
no service-layer changes, fixes the user-visible parity bug.

Unskips the two .todo parity reproducers in httpapi-parity.test.ts.
2026-05-02 23:33:14 -04:00
..
groups fix(httpapi): 404 status + body shape for missing-session errors 2026-05-02 23:33:14 -04:00
handlers fix(httpapi): 404 status + body shape for missing-session errors 2026-05-02 23:33:14 -04:00
middleware fix(instance): run bootstrap from instance store (#25475) 2026-05-02 19:33:38 -04:00
AGENTS.md Document HttpApi route patterns (#25188) 2026-04-30 20:48:14 -04:00
api.ts Refactor v2 session events as schemas (#24512) 2026-05-02 22:09:48 -04:00
errors.ts fix(httpapi): 404 status + body shape for missing-session errors 2026-05-02 23:33:14 -04:00
event.ts Refactor v2 session events as schemas (#24512) 2026-05-02 22:09:48 -04:00
lifecycle.ts Move instance loading into Effect service (#25277) 2026-05-01 22:18:06 -04:00
public.ts fix(httpapi): preserve OpenAPI parameter parity (#25291) 2026-05-01 22:18:52 -04:00
server.ts Refactor v2 session events as schemas (#24512) 2026-05-02 22:09:48 -04:00