{"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":null,"httpStatus":500,"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/3aec848f2885144aa8f1e53b9731a04310d5d558/server/models/scheduledJobRun.js#L314-L350","documentation":"continueInThread calls WorkspaceThread.new(workspace) to create the thread that will hold the run's response; if that helper returns a truthy `message` (its error channel), this throw fires with that text or 'Failed to create thread' as fallback. The workspace upsert succeeded, but the workspace_threads insert failed. The actual failure reason is the threadError text returned by WorkspaceThread.new.","triggerScenarios":"Prisma insert failure on workspace_threads (dropped connection, constraint violation, missing table after skipped migrations); the workspace object passed in is missing fields the thread creator expects.","commonSituations":"Transient DB outage mid-operation; instance upgraded without migrations; disk/connection limits hit exactly between the workspace upsert and thread insert steps.","solutions":["Read the threadError text in server logs - it carries the underlying Prisma/native error","Verify the workspace_threads table exists and migrations are current","Check database health, permissions, and connection limits","Retry the operation once the database is healthy - the workspace upsert is idempotent"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await ScheduledJobRun.continueInThread(runId);\n} catch (err) {\n  if (/Failed to create thread/.test(err.message)) {\n    // workspace upsert succeeded but the thread insert failed - retry once DB health returns\n    return res.status(503).json({ error: 'Thread creation failed, retry shortly' });\n  }\n  throw err;\n}","preventionTips":["Keep workspace_threads schema in sync via migrations on upgrade","Alert on Prisma insert failures so users do not hit this during outages","The workspace upsert is idempotent, so retrying continueInThread after DB recovery is safe"],"tags":["scheduled-jobs","workspace-threads","database","prisma"],"backgroundTag":"database-write-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}