Mintplex-Labs/anything-llm · error
Failed to create thread
Error message
Failed to create thread
What it means
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.
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
Defensive patterns
Strategy: try-catch
Try / catch
try {
await ScheduledJobRun.continueInThread(runId);
} catch (err) {
if (/Failed to create thread/.test(err.message)) {
// workspace upsert succeeded but the thread insert failed - retry once DB health returns
return res.status(503).json({ error: 'Thread creation failed, retry shortly' });
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Transient DB outage mid-operation; instance upgraded without migrations; disk/connection limits hit exactly between the workspace upsert and thread insert steps.
Related errors
- Failed to create workspace
- Internal Server Error
- Internal Server Error
- Cannot create: maximum of
- Cannot enable: maximum of
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/21516fa17e33d1d9.
Report an issue: GitHub.
Appendix: source
Thrown at server/models/scheduledJobRun.js:332
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,
});
return {
workspace,
thread,
error: null,View on GitHub (pinned to 3aec848f28)