Fix WebChat JSON request parsing - #486
Conversation
* Fix Responses assistant content type * Fix WebChat heterogeneous JSON responses --------- Co-authored-by: 刘松源 <liusongyuan@liusongyuandeMacBook-Pro-4.local>
XuYouo
left a comment
There was a problem hiding this comment.
Request changes: the WebChat login handshake is still broken.
-
[P1]
/webchat/api/session/bootstrapstill returns HTTP 500 on success. The new request parser lets the route reach the success branch, buthandleWebChatSessionBootstrapstill usescall.respond(...)for a heterogeneousBoolean + nested Mappayload. SinceContentNegotiationregistersjson(McpJson)beforegson(), the first converter throwsSerializing collections of different element types is not yet supported; Ktor does not fall back to Gson.App.tsxwaits for this request before loading/bootstrap, so WebChat login still fails. Please serialize this response through the same explicit Gson/respondTextpath and add a route-level regression test that asserts a 2xx response and valid JSON. -
[P2] Session bootstrap swallows invalid JSON bodies.
runCatching { call.receiveWebChatJsonObject() }.getOrDefault(emptyMap())catches theBadRequestExceptionproduced for malformed, array, or null bodies. With a valid Authorization header, the route continues and creates a session instead of returning 400, contrary to the PR contract. Preserve parser failures; if header-only bootstrap must remain supported, distinguish a genuinely absent body from an invalid JSON body.
Validation on head 0107bff3f: git diff --check passed; the added parser test passed on the exact head and after a clean merge with current main; a minimal route-level probe using the production converter order reproduced HTTP 500 for the success payload.
Summary
Root cause
Ktor ContentNegotiation could not deserialize request bodies directly into
Map<String, Any?>with the configured Gson converter. Every affected POST, PATCH, and PUT endpoint failed before route logic withFailed to convert request body to class kotlin.collections.Map.Impact
This fixes conversation creation and runs used by external WebChat clients and Telegram bridges, plus conversation updates, task clarification, workspace writes/moves, browser actions, and body-token session bootstrap.
Validation
0107bff3fand installed successfully on a physical Android device