{"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":"Error","httpStatus":null,"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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/scheduledJobRun.js#L309-L345","documentation":"Thrown by continueInThread when Workspace.upsert({ slug: 'scheduled-jobs' }, ...) returns a non-null workspaceError. The fallback text only appears if workspaceError is an empty/falsy-but-present string; normally the actual error message propagates. This means creating or finding the dedicated 'Scheduled Jobs' workspace failed.","triggerScenarios":"The database is unreachable, the workspaces table/unique constraint on slug is in a bad state, or Workspace.upsert's internal create/update logic threw. The 'scheduled-jobs' slug already exists under a different shape causing a conflict.","commonSituations":"DB connection failure mid-request; a prior partial migration left duplicate 'scheduled-jobs' slugs; Prisma unique-constraint violation; the upsert helper returned an error string from a nested validation.","solutions":["Read the propagated workspaceError string in the returned { error } for the real cause.","Check DB connectivity and that the workspaces table exists.","Inspect for duplicate slug 'scheduled-jobs' rows and deduplicate.","Run pending Prisma migrations."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const { workspace, error } = await ScheduledJobRun.continueInThread(runId);\nif (error && /create workspace/i.test(error)) {\n  logger.error('Scheduled-jobs workspace upsert failed', { runId, error });\n  return res.status(503).json({ error: 'Could not create the Scheduled Jobs workspace. Retry later.' });\n}","preventionTips":["Keep DB connectivity healthy and migrations applied.","Deduplicate any 'scheduled-jobs' slug rows.","Surface the propagated workspaceError string in logs."],"tags":["scheduled-jobs","workspace","database","upsert"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}