Mintplex-Labs/anything-llm · error

Failed to create workspace

Error message

Failed to create workspace

What it means

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.

Solutions

  1. Check server logs immediately around this error - Workspace.upsert's returned error string identifies the root cause
  2. Verify database connectivity and that all migrations are applied (prisma migrate deploy / container restart)
  3. Inspect the workspaces table for a conflicting or corrupted 'scheduled-jobs' row and repair or remove it
  4. Retry the continue-in-thread action once the underlying database issue is resolved
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const { workspace, thread, error } = await ScheduledJobRun.continueInThread(runId);
  if (error) return res.status(500).json({ error });
} catch (err) {
  // 'Failed to create workspace' is a wrapper - correlate with the underlying DB error in server logs
  console.error('continueInThread failed:', err.message);
  return res.status(503).json({ error: 'Could not continue run in thread; try again shortly' });
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/1cb1429f22d338c7. Report an issue: GitHub.

Appendix: source

Thrown at server/models/scheduledJobRun.js:327

      const { safeJsonParse } = require("../utils/http");

      const run = await this.get({ id: Number(runId) }, { job: true });
      if (!run) throw new Error("Run not found");

      const result = safeJsonParse(run.result, {});
      const responseText = result?.text || "No response was generated.";

      // Get or create the "Scheduled Jobs" workspace
      const { workspace, error: workspaceError } = await Workspace.upsert(
        { slug: "scheduled-jobs" },
        {
          name: "Scheduled Jobs",
          slug: "scheduled-jobs",
          chatMode: "automatic",
        }
      );
      if (workspaceError)
        throw new Error(workspaceError || "Failed to create workspace");

      const { thread, message: threadError } =
        await WorkspaceThread.new(workspace);
      if (threadError)
        throw new Error(threadError || "Failed to create thread");

      await WorkspaceChats.new({
        workspaceId: workspace.id,
        prompt: run.job.prompt,
        response: {
          text: responseText,
          sources: result.sources || [],
          outputs: result.outputs || [],
          type: "chat",
        },
        threadId: thread.id,
        include: true,
      });

View on GitHub (pinned to 3aec848f28)