Sibling POST handlers 500 on malformed JSON (parse-JSON-or-400 asymmetry) #21

Open
opened 2026-08-02 14:15:47 -07:00 by vh · 0 comments
Owner

_tts_endpoint now guards its JSON body (bad JSON / non-str → deterministic 400; untrusted
fields degrade, never 500). Its sibling POST handlers do NOT: _create_session_endpoint
(server.py:188) and _submit_turn_endpoint (server.py:~294) call await request.json()
with no guard, so a malformed JSON body raises json.JSONDecodeError → an uncaught 500.

Surfaced by the heid code-review + bug-hunt panels on the TTS chunking work (2026-08-02;
Regin F4 / Kimi F5): the validation asymmetry is now that every POST handler EXCEPT
_tts_endpoint 500s on malformed JSON. Pre-existing (unchanged code), so deliberately out
of scope for the TTS commit (d59f907) — filing as the follow-up.

Repro:

  • POST /api/sessions with body not json{ → 500 (want 400)
  • POST /api/turns/{sid} with body not json{ → 500 (want 400)
  • POST /api/tts with body not json{ → 400 (the correct shape)

Fix: hoist a shared "parse JSON body or 400" helper and route all POST handlers through it
(mirrors _tts_endpoint's try: await request.json() except (json.JSONDecodeError, ValueError): → 400).
Low-risk, additive; each handler keeps its own field validation.

Provenance: heid panels — code-review thread 01KZ21MCC0FKQP59NFZPXCK17B, bug-hunt thread
01KZ21RNYH1DPSCPKWVXB9YTVQ.

`_tts_endpoint` now guards its JSON body (bad JSON / non-str → deterministic 400; untrusted fields degrade, never 500). Its sibling POST handlers do NOT: `_create_session_endpoint` (`server.py:188`) and `_submit_turn_endpoint` (`server.py:~294`) call `await request.json()` with no guard, so a malformed JSON body raises `json.JSONDecodeError` → an uncaught 500. Surfaced by the heid code-review + bug-hunt panels on the TTS chunking work (2026-08-02; Regin F4 / Kimi F5): the validation asymmetry is now that every POST handler EXCEPT `_tts_endpoint` 500s on malformed JSON. Pre-existing (unchanged code), so deliberately out of scope for the TTS commit (d59f907) — filing as the follow-up. Repro: - `POST /api/sessions` with body `not json{` → 500 (want 400) - `POST /api/turns/{sid}` with body `not json{` → 500 (want 400) - `POST /api/tts` with body `not json{` → 400 (the correct shape) Fix: hoist a shared "parse JSON body or 400" helper and route all POST handlers through it (mirrors `_tts_endpoint`'s `try: await request.json() except (json.JSONDecodeError, ValueError): → 400`). Low-risk, additive; each handler keeps its own field validation. Provenance: heid panels — code-review thread `01KZ21MCC0FKQP59NFZPXCK17B`, bug-hunt thread `01KZ21RNYH1DPSCPKWVXB9YTVQ`.
vh added the bugneeds-triage labels 2026-08-02 14:15:47 -07:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vh/ratatoskr#21