{"record":{"id":"1cb1429f22d338c7","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-create-workspace","errorCode":null,"errorMessage":"Failed to create workspace","messagePattern":"Failed to create workspace","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/models/scheduledJobRun.js","lineNumber":327,"sourceCode":"      const { safeJsonParse } = require(\"../utils/http\");\n\n      const run = await this.get({ id: Number(runId) }, { job: true });\n      if (!run) throw new Error(\"Run not found\");\n\n      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      });","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/models/scheduledJobRun.js#L309-L345","documentation":"Inside continueInThread, a workspace with slug 'scheduled-jobs' is upserted via Workspace.upsert. When that call returns a truthy `error`, this throw fires with the underlying error text or the generic 'Failed to create workspace' fallback. The real cause is whatever made Workspace.upsert fail - typically a database problem, missing migration, or constraint issue on the workspaces table.","triggerScenarios":"Database unreachable or Prisma error during the upsert; the scheduled-jobs workspace row is in a corrupted/conflicting state; migrations not applied so expected columns or tables are missing; DB user lacks write permission.","commonSituations":"Database container restart or connection pool exhaustion at the moment a scheduled job result is continued; upgrading the app without running migrations; shared DB with a manually renamed 'scheduled-jobs' workspace.","solutions":["Check server logs immediately around this error - Workspace.upsert's returned error string identifies the root cause","Verify database connectivity and that all migrations are applied (prisma migrate deploy / container restart)","Inspect the workspaces table for a conflicting or corrupted 'scheduled-jobs' row and repair or remove it","Retry the continue-in-thread action once the underlying database issue is resolved"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const { workspace, thread, error } = await ScheduledJobRun.continueInThread(runId);\n  if (error) return res.status(500).json({ error });\n} catch (err) {\n  // 'Failed to create workspace' is a wrapper - correlate with the underlying DB error in server logs\n  console.error('continueInThread failed:', err.message);\n  return res.status(503).json({ error: 'Could not continue run in thread; try again shortly' });\n}","preventionTips":["Run database migrations on every upgrade before enabling scheduled-job continuation","Monitor DB connectivity and connection-pool saturation so upsert failures surface early","Treat this message as a symptom: always chase the underlying workspaceError text in logs"],"tags":["scheduled-jobs","workspace","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"}