{"record":{"id":"0507c79a8fbf8e76","repo":"Mintplex-Labs/anything-llm","slug":"threaderror","errorCode":null,"errorMessage":"threadError","messagePattern":"threadError","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/workspaces.js","lineNumber":718,"sourceCode":"            )?.id ?? null\n          : null;\n        const chatsToFork = await WorkspaceChats.where(\n          {\n            workspaceId: workspace.id,\n            user_id: user?.id,\n            include: true, // only duplicate visible chats\n            thread_id: threadId,\n            api_session_id: null, // Do not include API session chats.\n            id: { lte: Number(chatId) },\n          },\n          null,\n          { id: \"asc\" }\n        );\n\n        const { thread: newThread, message: threadError } =\n          await WorkspaceThread.new(workspace, user?.id);\n        if (threadError)\n          return response.status(500).json({ error: threadError });\n\n        let lastMessageText = \"\";\n        const chatsData = chatsToFork.map((chat) => {\n          const chatResponse = safeJsonParse(chat.response, {});\n          if (chatResponse?.text)\n            lastMessageText = stripThinkingFromText(chatResponse.text);\n\n          return {\n            workspaceId: workspace.id,\n            prompt: chat.prompt,\n            response: JSON.stringify(chatResponse),\n            user_id: user?.id,\n            thread_id: newThread.id,\n          };\n        });\n        await WorkspaceChats.bulkCreate(chatsData);\n        await WorkspaceThread.update(newThread, {\n          name: !!lastMessageText","sourceCodeStart":700,"sourceCodeEnd":736,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/workspaces.js#L700-L736","documentation":"Propagation guard in the thread-fork endpoint: WorkspaceThread.new returned a non-null message, meaning thread creation itself failed (e.g. DB constraint or slug collision), and that creation error is relayed to the client.","triggerScenarios":"Thrown at server/endpoints/workspaces.js:718 when the library encounters an invalid state.","commonSituations":"Chat execution failed and the thread returned an error.","solutions":["Inspect the threadError value for the underlying cause.","Verify the thread exists and the message payload is valid, then retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}