{"record":{"id":"5e7b10b6d48f9b9b","repo":"Billionmail/BillionMail","slug":"chat-not-found","errorCode":null,"errorMessage":"Chat not found","messagePattern":"Chat not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/askai/chat.go","lineNumber":262,"sourceCode":"\tcontent = strings.TrimSpace(content)\n\tif content == \"\" {\n\t\treturn errors.New(\"Content cannot be empty\")\n\t}\n\n\tsupplierInfo, err := GetSupplierConfig(supplierName)\n\tif err != nil {\n\t\treturn errors.New(\"Supplier not found\")\n\t}\n\n\tmodelInfo := GetModelInfo(supplierName, modelId)\n\tif modelInfo == nil {\n\t\treturn errors.New(\"Model not found\")\n\t}\n\n\t// Check if the chat is already active\n\tchatInfo, err := GetChat(chatId)\n\tif err != nil {\n\t\treturn errors.New(\"Chat not found\")\n\t}\n\t// set the chat information\n\tchatInfo.SupplierName = supplierName\n\tchatInfo.ModelId = modelId\n\terr = SaveChat(chatId, chatInfo)\n\tif err != nil {\n\t\treturn errors.New(\"Failed to save chat\")\n\t}\n\n\tChatStatus[chatId] = true // Set chat status to active\n\tdefer func() {\n\t\tdelete(ChatStatus, chatId) // Ensure chat status is removed after processing\n\t}()\n\n\taiObj := NewOpenAI(ctx, supplierInfo.ApiKey, supplierInfo.BaseUrl, modelId, chatId, supplierName, modelInfo.MaxTokens)\n\tif aiObj == nil {\n\t\treturn errors.New(\"failed to initialize AI client\")\n\t}","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/askai/chat.go#L244-L280","documentation":"Chat loads the existing chat via GetChat(chatId) and returns this error when the lookup fails, meaning no chat session exists with that ID. Chat only updates an existing chat's supplier/model; it does not create one.","triggerScenarios":"Calling Chat with a chatId that was never created (CreateChat not called), a chat that was removed via RemoveChat, an expired/purged chat ID, or a typo/incorrect ID from the client.","commonSituations":"Frontend keeps a stale chatId in localStorage after the chat was deleted server-side; restarting with an in-memory chat store that was cleared; calling Chat before the chat-creation endpoint completes.","solutions":["Create the chat first (the chat-creation API) and use the returned ID","Verify chatId exists via GetChat before calling Chat","Clear stale chatIds on the client and force re-creation when GetChat fails"],"exampleFix":"// before\nerr := askai.Chat(ctx, staleChatId, supplier, model, content, true)\n// after\nif _, err := askai.GetChat(chatId); err != nil {\n    chatId, err = askai.CreateChat(...) // recreate missing chat\n}\nerr = askai.Chat(ctx, chatId, supplier, model, content, true)","handlingStrategy":"validation","validationCode":"if _, err := askai.GetChat(chatId); err != nil {\n    return fmt.Errorf(\"chat %s does not exist; create it first\", chatId)\n}","typeGuard":null,"tryCatchPattern":"if err := askai.Chat(ctx, chatId, supplier, model, content, true); err != nil {\n    if err.Error() == \"Chat not found\" {\n        // invalidate client-side chatId and re-create the chat\n    }\n    return err\n}","preventionTips":["Create chats via the API and persist the returned ID server-side","Expire client-side chatId caches when the server deletes chats","Never accept chatId from the client without existence check"],"tags":["askai","chat","not-found","state"],"backgroundTag":"resource-not-found","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}