#5930 [GUI] Return HTTP 400 for malformed inference JSON
closed · @djmarker287-code · 0 Kommentare · Auf GitHub
Setup & installServer & APIAMD / HIPModels & quantsSecurityWindows
Beschreibung
## Problem and result
`local-ai-worker` checks whether Responses is available by sending one byte, `{` (`0x7b`), as an uncompressed JSON request body. It expects HTTP 400 or 422. With the LAN route from #5925 applied, Strata returned HTTP 500 with `Request failed`, so the worker stopped at readiness. The same request now returns HTTP 400 with `Invalid JSON in request body`.
## Related discussion
#5925 enables the Responses route on the desktop LAN listener. This fix is based directly on `main` and also applies to inference routes already available there.
## Approach
Give JSON parse errors a distinct type and catch them in the shared inference handler. Return the error in the format used by the requested API. API-key checks and unknown-route handling retain their existing status codes.
## Validation
**Passed**
Live test on Strata Desktop 0.2.13, Windows 11, Radeon AI PRO R9700 (32 GB), HIP engine 0.1.59, with `iq3_s` loaded. The installed host had the LAN change from #5925. Requests were sent from the Strata PC to its LAN address. The curl equivalent of the readiness probe is below. Set `LAN_BASE` to the shared `/v1` URL and add the authorization header if a key is configured.
```sh
curl -i --noproxy '*' -H 'Content-Type: application/json' \
--data-binary '{' "$LAN_BASE/responses"
```
| Request | Before | After |
| --- | --- | --- |
| LAN `POST /v1/responses` with `{` | `500 Request failed` | `400 Invalid JSON in request body` |
| Loopback `POST /v1/responses` with `{` | `500 Body must be JSON` | `400 Invalid JSON in request body` |
| Unknown route with `{` | `404` | `404` |
The live test also sent these two payloads using Node fetch. These curl commands reproduce them.
```sh
curl -i -H 'Content-Type: application/json' \
--data-binary '{"model":"iq3_s","input":"Reply with exactly OK.","reasoning":{"effort":"none"},"max_output_tokens":24,"store":false,"stream":false}' \
"$LAN_BASE/responses"
curl -iN -H 'Content-Type: application/json' \
--data-binary '{"model":"iq3_s","input":"Reply with exactly OK.","reasoning":{"effort":"none"},"max_output_tokens":24,"store":false,"stream":true}' \
"$LAN_BASE/responses"
```
The JSON request returned HTTP 200, `status: completed`, and `OK`. The streaming request returned HTTP 200 as `text/event-stream`, streamed `OK`, and emitted `response.completed`.
On commit `735d1e0` based on `13eedf5`, Windows 11 and Node 24.12.0, all 20 targeted tests passed from `apps/host`.
```sh
node --test tests/bad-host-header.test.mjs tests/native-gateway.test.mjs tests/cors-share.test.mjs tests/serving-key-compare.test.mjs tests/connect-urls.test.mjs
npm run typecheck
npm run build
```
**Failed**
The new regression test returned 500 on the unpatched base, where it expects 400.
**Not run**
The full host suite and `local-ai-worker ready` on the worker machine. The HTTP probe and its unknown-route control were tested directly.
## Limits
LAN Responses requires the routing change in #5925. The worker export captured a readiness failure before inference. The original Windows Codex error remains unverified.
Mehr auf der Site
Links zu Install, Modellen, Releases.