iflytek/astron-agent · error

Chat ID cannot be empty

Error message

Chat ID cannot be empty

What it means

ChatMessageController.chat resolves the latest chat_id from ChatTreeIndex records via chatListDataService.findChatTreeIndexByChatIdOrderById. When the lookup returns an empty list, it logs 'chatId is empty', sends an SSE error message 'Chat ID cannot be empty' to the client stream, completes the emitter, and aborts. It means no chat tree history exists for the supplied chatId, so the conversation cannot continue.

Solutions

  1. Verify the chatId exists in the chat tree index table for the requesting user/space
  2. Check for a race: ensure the first message's tree-index row is persisted before sending follow-up messages
  3. Handle the SSE 'Chat ID cannot be empty' event on the frontend by starting a new conversation
  4. Confirm the client passes the correct chatId (root/current) field, not sseId or botId
  5. Guard against stale local state — refresh the chat list before resuming an old conversation
Defensive patterns

Strategy: validation

Validate before calling

List<ChatTreeIndex> idx = chatListDataService.findChatTreeIndexByChatIdOrderById(chatId);
if (idx == null || idx.isEmpty()) { emitter error + return; }

Try / catch

// server already emits SSE error; client side:
es.onmessage = (e) => { if (e.data.includes("Chat ID cannot be empty")) startNewConversation(); };

Prevention

When it happens

Trigger: SSE chat request with a chatId that has no rows in the chat tree index table: stale/deleted conversation, fabricated chatId, or a chatId from a different space/user than the one queried.

Common situations: Frontend resuming a conversation that was deleted server-side; race where chat history persistence hasn't completed before the next message is sent; cross-environment reuse of chat IDs (test data in prod); wrong chatId field passed instead of the root id.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/f9c457d98d07bddb. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/controller/chat/ChatMessageController.java:96

            @RequestParam(required = false) String fileUrl,
            @RequestParam(required = false) String workflowOperation,
            @RequestParam(required = false) String workflowVersion) {
        String sseId = RandomUtil.randomString(8);
        SseEmitter sseEmitter = SseEmitterUtil.createSseEmitter();

        log.info("Establishing SSE connection, sseId: {}, chatId: {}", sseId, chatId);

        // Validate before any conversation lookup so invalid input has no downstream side effects.
        ValidationResult validation = validateChatRequest(chatId, text, sseId, sseEmitter);
        if (!validation.isValid()) {
            return sseEmitter;
        }

        // Get the latest chat_id
        List<ChatTreeIndex> chatTreeIndexList = chatListDataService.findChatTreeIndexByChatIdOrderById(chatId);
        if (chatTreeIndexList.isEmpty()) {
            log.warn("chatId is empty, sseId: {}", sseId);
            SseEmitterUtil.sendError(sseEmitter, "Chat ID cannot be empty");
            SseEmitterUtil.sendEndAndComplete(sseEmitter);
            return sseEmitter;
        }
        Long lastChatId = chatTreeIndexList.getFirst().getChildChatId();

        // Preserve validation of the resolved child ID in case stored tree data is incomplete.
        ValidationResult resolvedChatValidation = validateChatRequest(lastChatId, text, sseId, sseEmitter);
        if (!resolvedChatValidation.isValid()) {
            return sseEmitter;
        }

        // Validate chat window and assistant status
        ChatContext chatContext = validateChatContext(lastChatId, null, sseId, sseEmitter);
        if (chatContext == null) {
            return sseEmitter;
        }

        return processChatRequest(chatContext, text, fileUrl, sseEmitter, sseId, workflowOperation, workflowVersion);

View on GitHub (pinned to 5e758547a8)