jackwener/OpenCLI · error · Error

No user message found in request

Error message

No user message found in request

What it means

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.

Source

Thrown at clis/antigravity/serve.js:346

                }
                catch (reconnectErr) {
                    console.error(`[serve] Reconnection failed: ${reconnectErr.message}`);
                    throw err; // Throw original error if reconnection itself fails
                }
            }
            throw err;
        }
        await sleep(pollInterval);
    }
    throw new Error(`Timeout waiting for Antigravity reply after ${timeout / 1000}s`);
}
// ─── Request Handlers ────────────────────────────────────────────────
async function handleMessages(body, page, opts = {}) {
    const { bridge, timeout, reconnect } = opts;
    // Extract the last user message
    const userMessages = body.messages.filter(m => m.role === 'user');
    if (userMessages.length === 0) {
        throw new Error('No user message found in request');
    }
    const lastUserMsg = userMessages[userMessages.length - 1];
    const userText = extractTextContent(lastUserMsg.content);
    if (!userText.trim()) {
        throw new Error('Empty user message');
    }
    // Optimization 1: New conversation if this is the first message in the session
    if (body.messages.length === 1) {
        console.error(`[serve] New session detected (1 message). Starting new conversation in UI.`);
        await startNewConversation(page);
    }
    // Optimization 3: Switch model if requested
    if (body.model) {
        await switchModel(page, body.model);
    }
    // Get conversation state before sending
    const beforeText = await getConversationText(page);
    // Send the message

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Include at least one message with role 'user' in the request body
  2. Fix client/proxy config so user content is sent with role 'user' (lowercase)
  3. Log and inspect body.messages to see what the client actually sent
  4. Validate the request payload before calling the endpoint

Example fix

// before
await fetch(url, { method: 'POST', body: JSON.stringify({ messages: [{ role: 'system', content: 'hi' }] }) });
// after
await fetch(url, { method: 'POST', body: JSON.stringify({ messages: [{ role: 'system', content: 'hi' }, { role: 'user', content: 'hi' }] }) });
Defensive patterns

Strategy: validation

Validate before calling

function validateRequest(body) {
  const msgs = Array.isArray(body?.messages) ? body.messages : [];
  if (!msgs.some(m => m?.role === 'user')) {
    throw new Error('Request must include at least one message with role "user"');
  }
}

Type guard

function hasUserMessage(body) {
  return Array.isArray(body?.messages)
    && body.messages.some(m => typeof m === 'object' && m !== null && m.role === 'user');
}

Try / catch

try {
  const reply = await sendToAntigravity(body);
} catch (err) {
  if (err.message === 'No user message found in request') {
    console.error('Payload sent:', JSON.stringify(body.messages));
  }
  throw err;
}

Prevention

When it happens

Trigger: 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 [].

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/ec889fd3f863ddfd. Report an issue: GitHub.