{"record":{"id":"ec889fd3f863ddfd","repo":"jackwener/OpenCLI","slug":"no-user-message-found-in-request","errorCode":null,"errorMessage":"No user message found in request","messagePattern":"No user message found in request","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/antigravity/serve.js","lineNumber":346,"sourceCode":"                }\n                catch (reconnectErr) {\n                    console.error(`[serve] Reconnection failed: ${reconnectErr.message}`);\n                    throw err; // Throw original error if reconnection itself fails\n                }\n            }\n            throw err;\n        }\n        await sleep(pollInterval);\n    }\n    throw new Error(`Timeout waiting for Antigravity reply after ${timeout / 1000}s`);\n}\n// ─── Request Handlers ────────────────────────────────────────────────\nasync function handleMessages(body, page, opts = {}) {\n    const { bridge, timeout, reconnect } = opts;\n    // Extract the last user message\n    const userMessages = body.messages.filter(m => m.role === 'user');\n    if (userMessages.length === 0) {\n        throw new Error('No user message found in request');\n    }\n    const lastUserMsg = userMessages[userMessages.length - 1];\n    const userText = extractTextContent(lastUserMsg.content);\n    if (!userText.trim()) {\n        throw new Error('Empty user message');\n    }\n    // Optimization 1: New conversation if this is the first message in the session\n    if (body.messages.length === 1) {\n        console.error(`[serve] New session detected (1 message). Starting new conversation in UI.`);\n        await startNewConversation(page);\n    }\n    // Optimization 3: Switch model if requested\n    if (body.model) {\n        await switchModel(page, body.model);\n    }\n    // Get conversation state before sending\n    const beforeText = await getConversationText(page);\n    // Send the message","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/antigravity/serve.js#L328-L364","documentation":"handleMessages extracts messages with role === 'user' from the OpenAI-style request body and throws when none exist. The server only knows how to drive the Antigravity UI from a user prompt, so a request without at least one user message is invalid input.","triggerScenarios":"POST body contains messages but every message has a non-'user' role (e.g. only 'system' or 'assistant'), or body.messages is missing/empty and filter yields [].","commonSituations":"Client sending chat-completion requests with only a system prompt; misconfigured proxy/SDK mapping user content into a different role field; empty messages array passed by an orchestrator bug; role casing mismatch ('User') after a client update.","solutions":["Include at least one message with role 'user' in the request body","Fix client/proxy config so user content is sent with role 'user' (lowercase)","Log and inspect body.messages to see what the client actually sent","Validate the request payload before calling the endpoint"],"exampleFix":"// before\nawait fetch(url, { method: 'POST', body: JSON.stringify({ messages: [{ role: 'system', content: 'hi' }] }) });\n// after\nawait fetch(url, { method: 'POST', body: JSON.stringify({ messages: [{ role: 'system', content: 'hi' }, { role: 'user', content: 'hi' }] }) });","handlingStrategy":"validation","validationCode":"function validateRequest(body) {\n  const msgs = Array.isArray(body?.messages) ? body.messages : [];\n  if (!msgs.some(m => m?.role === 'user')) {\n    throw new Error('Request must include at least one message with role \"user\"');\n  }\n}","typeGuard":"function hasUserMessage(body) {\n  return Array.isArray(body?.messages)\n    && body.messages.some(m => typeof m === 'object' && m !== null && m.role === 'user');\n}","tryCatchPattern":"try {\n  const reply = await sendToAntigravity(body);\n} catch (err) {\n  if (err.message === 'No user message found in request') {\n    console.error('Payload sent:', JSON.stringify(body.messages));\n  }\n  throw err;\n}","preventionTips":["Always include a user message in chat requests","Keep roles lowercase per the OpenAI schema","Log outgoing bodies when debugging proxies","Validate payloads client-side before POSTing"],"tags":["validation","request-body","api","antigravity"],"backgroundTag":"missing-request-parameter","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}