{"record":{"id":"21516fa17e33d1d9","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-create-thread","errorCode":null,"errorMessage":"Failed to create thread","messagePattern":"Failed to create thread","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/scheduledJobRun.js","lineNumber":332,"sourceCode":"      const result = safeJsonParse(run.result, {});\n      const responseText = result?.text || \"No response was generated.\";\n\n      // Get or create the \"Scheduled Jobs\" workspace\n      const { workspace, error: workspaceError } = await Workspace.upsert(\n        { slug: \"scheduled-jobs\" },\n        {\n          name: \"Scheduled Jobs\",\n          slug: \"scheduled-jobs\",\n          chatMode: \"automatic\",\n        }\n      );\n      if (workspaceError)\n        throw new Error(workspaceError || \"Failed to create workspace\");\n\n      const { thread, message: threadError } =\n        await WorkspaceThread.new(workspace);\n      if (threadError)\n        throw new Error(threadError || \"Failed to create thread\");\n\n      await WorkspaceChats.new({\n        workspaceId: workspace.id,\n        prompt: run.job.prompt,\n        response: {\n          text: responseText,\n          sources: result.sources || [],\n          outputs: result.outputs || [],\n          type: \"chat\",\n        },\n        threadId: thread.id,\n        include: true,\n      });\n\n      return {\n        workspace,\n        thread,\n        error: null,","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/scheduledJobRun.js#L314-L350","documentation":"Thrown by continueInThread when WorkspaceThread.new(workspace) returns a non-null threadError (returned as `message`). The fallback fires only if that message is empty. This means a thread could not be created for the resolved 'Scheduled Jobs' workspace, blocking the run from being recorded as a chat.","triggerScenarios":"WorkspaceThread.new failed internally — DB write error, missing required workspace field, or a thread-limit/validation inside the helper. The workspace was created/found but thread creation is the failing step.","commonSituations":"Database connectivity issue isolated to the write; the workspace object passed in was missing expected fields; a schema change to workspace_threads introduced a required column not supplied by WorkspaceThread.new.","solutions":["Inspect the propagated threadError string in the returned { error }.","Verify the workspace_threads table schema matches WorkspaceThread.new's insert.","Run pending migrations.","Check DB logs for the failed INSERT."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const { thread, error } = await ScheduledJobRun.continueInThread(runId);\nif (error && /create thread/i.test(error)) {\n  logger.error('Thread creation for scheduled run failed', { runId, error });\n  return res.status(503).json({ error: 'Could not create a thread for the run.' });\n}","preventionTips":["Ensure workspace_threads schema matches WorkspaceThread.new's insert.","Apply pending migrations before relying on continueInThread.","Log the propagated threadError for diagnosis."],"tags":["scheduled-jobs","workspace-thread","database","thread"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}