Sibling POST handlers 500 on malformed JSON (parse-JSON-or-400 asymmetry) #21
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
_tts_endpointnow guards its JSON body (bad JSON / non-str → deterministic 400; untrustedfields degrade, never 500). Its sibling POST handlers do NOT:
_create_session_endpoint(
server.py:188) and_submit_turn_endpoint(server.py:~294) callawait 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_endpoint500s on malformed JSON. Pre-existing (unchanged code), so deliberately outof scope for the TTS commit (
d59f907) — filing as the follow-up.Repro:
POST /api/sessionswith bodynot json{→ 500 (want 400)POST /api/turns/{sid}with bodynot json{→ 500 (want 400)POST /api/ttswith bodynot 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'stry: 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 thread01KZ21RNYH1DPSCPKWVXB9YTVQ.