{"record":{"id":"f9c457d98d07bddb","repo":"iflytek/astron-agent","slug":"chat-id-cannot-be-empty","errorCode":null,"errorMessage":"Chat ID cannot be empty","messagePattern":"Chat ID cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/controller/chat/ChatMessageController.java","lineNumber":96,"sourceCode":"            @RequestParam(required = false) String fileUrl,\n            @RequestParam(required = false) String workflowOperation,\n            @RequestParam(required = false) String workflowVersion) {\n        String sseId = RandomUtil.randomString(8);\n        SseEmitter sseEmitter = SseEmitterUtil.createSseEmitter();\n\n        log.info(\"Establishing SSE connection, sseId: {}, chatId: {}\", sseId, chatId);\n\n        // Validate before any conversation lookup so invalid input has no downstream side effects.\n        ValidationResult validation = validateChatRequest(chatId, text, sseId, sseEmitter);\n        if (!validation.isValid()) {\n            return sseEmitter;\n        }\n\n        // Get the latest chat_id\n        List<ChatTreeIndex> chatTreeIndexList = chatListDataService.findChatTreeIndexByChatIdOrderById(chatId);\n        if (chatTreeIndexList.isEmpty()) {\n            log.warn(\"chatId is empty, sseId: {}\", sseId);\n            SseEmitterUtil.sendError(sseEmitter, \"Chat ID cannot be empty\");\n            SseEmitterUtil.sendEndAndComplete(sseEmitter);\n            return sseEmitter;\n        }\n        Long lastChatId = chatTreeIndexList.getFirst().getChildChatId();\n\n        // Preserve validation of the resolved child ID in case stored tree data is incomplete.\n        ValidationResult resolvedChatValidation = validateChatRequest(lastChatId, text, sseId, sseEmitter);\n        if (!resolvedChatValidation.isValid()) {\n            return sseEmitter;\n        }\n\n        // Validate chat window and assistant status\n        ChatContext chatContext = validateChatContext(lastChatId, null, sseId, sseEmitter);\n        if (chatContext == null) {\n            return sseEmitter;\n        }\n\n        return processChatRequest(chatContext, text, fileUrl, sseEmitter, sseId, workflowOperation, workflowVersion);","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/controller/chat/ChatMessageController.java#L78-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the chatId exists in the chat tree index table for the requesting user/space","Check for a race: ensure the first message's tree-index row is persisted before sending follow-up messages","Handle the SSE 'Chat ID cannot be empty' event on the frontend by starting a new conversation","Confirm the client passes the correct chatId (root/current) field, not sseId or botId","Guard against stale local state — refresh the chat list before resuming an old conversation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"List<ChatTreeIndex> idx = chatListDataService.findChatTreeIndexByChatIdOrderById(chatId);\nif (idx == null || idx.isEmpty()) { emitter error + return; }","typeGuard":null,"tryCatchPattern":"// server already emits SSE error; client side:\nes.onmessage = (e) => { if (e.data.includes(\"Chat ID cannot be empty\")) startNewConversation(); };","preventionTips":["Refresh chat state before resuming an old conversation","Ensure the first message persists tree-index rows before follow-ups","Verify the client sends the correct chatId field","Handle SSE error events gracefully by starting a new chat"],"tags":["sse","chat","validation"],"backgroundTag":"entity-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}