{"record":{"id":"b723310fe59d0a8b","repo":"iflytek/astron-agent","slug":"chat-req-error","errorCode":"CHAT_REQ_ERROR","errorMessage":"CHAT_REQ_ERROR","messagePattern":"CHAT_REQ_ERROR","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/bot/impl/TalkAgentServiceImpl.java","lineNumber":79,"sourceCode":"                SIGNATURE_URL, \"GET\", config.getSparkVirtualManApiKey(), config.getSparkVirtualManApiSecret());\n    }\n\n    @Override\n    public ResponseEnum saveHistory(String uid, TalkAgentHistoryDto talkAgentHistoryDto) {\n        Long chatId = talkAgentHistoryDto.getChatId();\n        Integer clientType = talkAgentHistoryDto.getClientType();\n        String req = talkAgentHistoryDto.getReq();\n        String resp = talkAgentHistoryDto.getResp();\n        String sid = talkAgentHistoryDto.getSid();\n\n        if (chatId == null) {\n            return ResponseEnum.CHAT_REQ_ERROR;\n        }\n        // get latest chatId\n        List<ChatTreeIndex> chatTreeIndexList = chatListDataService.findChatTreeIndexByChatIdOrderById(chatId);\n        if (chatTreeIndexList.isEmpty()) {\n            log.warn(\"chatTreeList is empty, chatId:{}, sid:{}\", chatId, sid);\n            return ResponseEnum.CHAT_REQ_ERROR;\n        }\n        Long lastChatId = chatTreeIndexList.getFirst().getChildChatId();\n        // check chatId available\n        ChatList chatList = chatListDataService.findByUidAndChatId(uid, lastChatId);\n        if (chatList == null) {\n            log.warn(\"Chat window is unavailable or illegal access,uid: {}, chatId: {}\", uid, chatId);\n            return ResponseEnum.CHAT_REQ_NOT_BELONG_ERROR;\n        }\n        // record request\n        chatId = lastChatId;\n        ChatReqRecords chatReqRecords = new ChatReqRecords();\n        chatReqRecords.setChatId(chatId);\n        chatReqRecords.setUid(uid);\n        chatReqRecords.setMessage(req);\n        chatReqRecords.setClientType(clientType);\n        chatReqRecords.setCreateTime(LocalDateTime.now());\n        chatReqRecords.setUpdateTime(LocalDateTime.now());\n        chatReqRecords.setNewContext(1);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/bot/impl/TalkAgentServiceImpl.java#L61-L97","documentation":"TalkAgentServiceImpl.saveHistory validates that the given chatId resolves to an existing chat tree. It returns ResponseEnum.CHAT_REQ_ERROR when the chatId is blank/unknown or when no ChatTreeIndex rows exist for it. This is an API-level error code telling the client the chat request cannot be processed because the conversation record is missing.","triggerScenarios":"saveHistory called with a chatId that has no rows in chat_tree_index (findChatTreeIndexByChatIdOrderById returns an empty list), or an invalid chatId rejected by the earlier guard.","commonSituations":"Client sends a stale/deleted conversation ID after the chat was removed; race where the first message is saved before the chat tree index is created; ID truncation or wrong ID field sent by the frontend; cross-user access with a fabricated chatId.","solutions":["Have the client create a new conversation (fresh chatId) instead of reusing the missing one.","Check chat_list / chat_tree_index tables to confirm whether the chatId was deleted or never created.","Ensure the frontend sends the current chatId from the create-conversation response, not a cached one.","Verify ordering: chat tree index must be persisted before history save is invoked."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// client-side before saving history\nconst chat = await getConversation(chatId);\nif (!chat || chat.deleted) { startNewConversation(); return; }","typeGuard":"function hasChatTreeIndex(list) {\n  return Array.isArray(list) && list.length > 0;\n}","tryCatchPattern":"ResponseEnum result = talkAgentService.saveHistory(req);\nif (result == ResponseEnum.CHAT_REQ_ERROR) {\n    log.warn(\"chat missing, creating new conversation\");\n    chatId = conversationService.create(uid);\n}","preventionTips":["Always take chatId from the create-conversation response, never from stale client cache.","Create the chat tree index atomically with the first message.","Reconcile deleted conversations in the client on 404/CHAT_REQ_ERROR.","Log chatId + uid on failure for supportability."],"tags":["chat","record-not-found","api-error-code","validation"],"backgroundTag":"record-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}